Java Code Examples for com.google.common.collect.FluentIterable#filter()
The following examples show how to use
com.google.common.collect.FluentIterable#filter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ItemLister.java From brooklyn-server with Apache License 2.0 | 6 votes |
private <T extends BrooklynObject> List<Class<? extends T>> getTypes(List<URL> urls, Class<T> type, Boolean catalogOnlyOverride) { // TODO this only really works if you give it lots of URLs - see comment on "--jar" argument // NB if the ReflectionScanner class is given "null" then it will scan, better than INITIAL_CLASSPATH FluentIterable<Class<? extends T>> fluent = FluentIterable.from(ClassFinder.findClasses(urls, type)); if (typeRegex != null) { fluent = fluent.filter(ClassFinder.withClassNameMatching(typeRegex)); } if (catalogOnlyOverride == null ? !allClasses : catalogOnlyOverride) { fluent = fluent.filter(ClassFinder.withAnnotation(Catalog.class)); } List<Class<? extends T>> filtered = fluent.toList(); Collection<Class<? extends T>> result; if (!includeImpls) { result = MutableSet.copyOf(filtered); for (Class<? extends T> clazz : filtered) { ImplementedBy implementedBy = clazz.getAnnotation(ImplementedBy.class); if (implementedBy != null) { result.remove(implementedBy.value()); } } } else { result = filtered; } itemCount += result.size(); return ImmutableList.copyOf(result); }
Example 2
Source File: QuotaManager.java From attic-aurora with Apache License 2.0 | 6 votes |
private ResourceBag getConsumption( FluentIterable<IAssignedTask> tasks, Map<IJobKey, IJobUpdateInstructions> updatesByKey, Map<IJobKey, IJobConfiguration> cronTemplatesByKey, Predicate<ITaskConfig> filter) { FluentIterable<IAssignedTask> filteredTasks = tasks.filter(compose(filter, IAssignedTask::getTask)); Predicate<IAssignedTask> excludeCron = compose( not(in(cronTemplatesByKey.keySet())), Tasks::getJob); ResourceBag nonCronConsumption = getNonCronConsumption( updatesByKey, filteredTasks.filter(excludeCron), filter); ResourceBag cronConsumption = getCronConsumption( Iterables.filter( cronTemplatesByKey.values(), compose(filter, IJobConfiguration::getTaskConfig)), filteredTasks.transform(IAssignedTask::getTask)); return nonCronConsumption.add(cronConsumption); }
Example 3
Source File: Flavors.java From buck with Apache License 2.0 | 6 votes |
/** * Propagate a build target's flavors in a certain domain to a list of other build targets. * * @param domain the flavor domain to be propagated. * @param buildTarget the build target containing the flavors to be propagated * @param deps list of BuildTargetPaths to propagate the flavors to. If a target already contains * one or more flavors in domain, it is left unchanged. * @return the list of BuildTargetPaths with any flavors propagated. */ public static FluentIterable<BuildTarget> propagateFlavorsInDomainIfNotPresent( FlavorDomain<?> domain, BuildTarget buildTarget, FluentIterable<BuildTarget> deps) { if (domain.containsAnyOf(buildTarget.getFlavors())) { FluentIterable<BuildTarget> targetsWithFlavorsAlready = deps.filter(containsFlavors(domain)::test); FluentIterable<BuildTarget> targetsWithoutFlavors = deps.filter(containsFlavors(domain).negate()::test); deps = targetsWithFlavorsAlready.append( propagateFlavorDomains(buildTarget, ImmutableSet.of(domain), targetsWithoutFlavors)); } return deps; }
Example 4
Source File: DependenciesAssertion.java From ArchUnit with Apache License 2.0 | 5 votes |
public DependenciesAssertion containOnly(final ExpectedDependencies expectedDependencies) { FluentIterable<? extends Dependency> rest = FluentIterable.from(actual); for (final List<Class<?>> expectedDependency : expectedDependencies) { rest = rest.filter(new Predicate<Dependency>() { @Override public boolean apply(Dependency input) { return !matches(input, expectedDependency.get(0), expectedDependency.get(1)); } }); } assertThat(rest.toSet()).as("unexpected elements").isEmpty(); return this; }
Example 5
Source File: XbaseProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * @since 2.17 */ protected Iterable<JvmFeature> getFavoriteStaticFeatures(EObject context, Predicate<JvmFeature> filter) { String pref = PreferenceConstants.getPreference(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, null); List<JvmFeature> result = newArrayList(); if (Strings.isEmpty(pref)) { return result; } String[] favorites = pref.split(";"); //$NON-NLS-1$ for (String fav : favorites) { boolean isWildcard = fav.lastIndexOf("*") > 0; //$NON-NLS-1$ int indexOfLastDot = fav.lastIndexOf("."); //$NON-NLS-1$ if (indexOfLastDot > 0) { String typeName = fav.substring(0, indexOfLastDot); JvmType type = typeReferences.findDeclaredType(typeName, context); final String membername = fav.substring(indexOfLastDot + 1, fav.length()); if (type != null) { if (type instanceof JvmDeclaredType) { JvmDeclaredType genericType = (JvmDeclaredType) type; // All features but no Constructor FluentIterable<JvmFeature> allFeaturesToImport = FluentIterable.from(genericType.getMembers()).filter(JvmFeature.class).filter(input -> { boolean isValid = !(input instanceof JvmConstructor) && input.isStatic(); if (isWildcard) { return isValid; } else { return isValid && input.getSimpleName().equals(membername); } }); FluentIterable<JvmFeature> featuresToImport = allFeaturesToImport.filter(filter); if (context != null) { // Make sure that already imported static features are not proposed RewritableImportSection importSection = importSectionFactory.parse((XtextResource) context.eResource()); featuresToImport = featuresToImport.filter(input -> !importSection.hasStaticImport(input.getSimpleName(), false)); } featuresToImport.copyInto(result); } } } } return result; }
Example 6
Source File: XcodeNativeTargetGenerator.java From buck with Apache License 2.0 | 5 votes |
private FluentIterable<TargetNode<?>> collectRecursiveLibraryDepTargets( TargetNode<?> targetNode) { FluentIterable<TargetNode<?>> allDeps = FluentIterable.from( AppleBuildRules.getRecursiveTargetNodeDependenciesOfTypes( xcodeDescriptions, targetGraph, Optional.of(dependenciesCache), RecursiveDependenciesMode.LINKING, targetNode, xcodeDescriptions.getXCodeDescriptions())); return allDeps.filter(this::isLibraryWithSourcesToCompile); }
Example 7
Source File: XcodeNativeTargetGenerator.java From buck with Apache License 2.0 | 4 votes |
private FluentIterable<TargetNode<?>> filterRecursiveLibraryDepTargetsWithSwiftSources( FluentIterable<TargetNode<?>> targetNodes) { return targetNodes.filter(this::isLibraryWithSwiftSources); }