List of usage examples for com.google.common.base Predicates in
public static <T> Predicate<T> in(Collection<? extends T> target)
From source file:org.eclipse.sirius.diagram.sequence.business.internal.operation.SynchronizeISequenceEventsSemanticOrderingOperation.java
private Set<EventEnd> selectEndsToIgnore(ISequenceEvent ise, List<EventEnd> endsBySemanticOrder, final List<EventEnd> iseEnds, final List<EventEnd> compoundEnds) { final Iterable<ISequenceEvent> movedElements = Iterables.filter(allElementsToReorder, Predicates.not(Predicates.in(reordered))); final Set<EObject> semanticLinked = Sets.newHashSet(Iterables.filter( Iterables.transform(movedElements, ISequenceElement.SEMANTIC_TARGET), Predicates.notNull())); final Predicate<EObject> isLinkedSubEventEnd = new Predicate<EObject>() { @Override/*w ww. ja v a 2 s .com*/ public boolean apply(EObject input) { return semanticLinked.contains(input); } }; final Set<EObject> semanticDescendants = Sets .newHashSet(Iterables.filter(Iterables.transform(new ISequenceEventQuery(ise).getAllDescendants(), ISequenceElement.SEMANTIC_TARGET), Predicates.notNull())); final Predicate<EObject> isSemanticSubEventEnd = new Predicate<EObject>() { @Override public boolean apply(EObject input) { return semanticDescendants.contains(input); } }; Predicate<EventEnd> toIgnore = new Predicate<EventEnd>() { @Override public boolean apply(EventEnd input) { return !iseEnds.contains(input) && (Iterables.any(EventEndHelper.getSemanticEvents(input), Predicates.or(isSemanticSubEventEnd, isLinkedSubEventEnd)) || compoundEnds.contains(input)); } }; HashSet<EventEnd> newHashSet = Sets.newHashSet(Iterables.filter(endsBySemanticOrder, toIgnore)); return newHashSet; }
From source file:org.eclipse.sirius.diagram.sequence.business.internal.layout.horizontal.SequenceHorizontalLayout.java
private int getOrComputeMaxChildrenDepth(AbstractFrame frame, Collection<AbstractFrame> framesToIgnore) { int children = 0; if (!frameChildrenDepths.containsKey(frame)) { Collection<Lifeline> frameCoverage = coverage.get(frame); Range frameRange = ranges.get(frame); for (AbstractFrame potentialChild : Iterables.filter(frames, Predicates.not(Predicates.in(framesToIgnore)))) { Collection<Lifeline> potentialCoverage = coverage.get(potentialChild); Range potentialRange = ranges.get(potentialChild); if (frame != potentialChild && frameCoverage.containsAll(potentialCoverage) && frameRange.includes(potentialRange)) { ArrayList<AbstractFrame> newArrayList = Lists.newArrayList(framesToIgnore); newArrayList.add(potentialChild); children = Math.max(children, 1 + getOrComputeMaxChildrenDepth(potentialChild, newArrayList)); }//from w ww . j av a 2s . com } frameChildrenDepths.put(frame, children); } else { children = frameChildrenDepths.get(frame); } return children; }
From source file:com.google.errorprone.scanner.BuiltInCheckerSuppliers.java
/** * Returns a {@link ScannerSupplier} with the {@link BugChecker}s that are in the ENABLED lists. *//* ww w . ja v a 2 s.c o m*/ public static ScannerSupplier defaultChecks() { return allChecks().filter(Predicates.or(Predicates.in(ENABLED_ERRORS), Predicates.in(ENABLED_WARNINGS))); }
From source file:com.google.devtools.build.lib.skyframe.TargetPatternPhaseFunction.java
/** * Interpret test target labels from the command-line arguments and return the corresponding set * of targets, handling the filter flags, and expanding test suites. * * @param targetPatterns the list of command-line target patterns specified by the user * @param testFilter the test filter//from www . j ava 2 s. co m */ private static ResolvedTargets<Target> determineTests(Environment env, List<String> targetPatterns, String offset, TestFilter testFilter) throws InterruptedException { List<SkyKey> patternSkyKeys = new ArrayList<>(); for (TargetPatternSkyKeyOrException keyOrException : TargetPatternValue.keys(targetPatterns, FilteringPolicies.FILTER_TESTS, offset)) { try { patternSkyKeys.add(keyOrException.getSkyKey()); } catch (TargetParsingException e) { // Skip. } } Map<SkyKey, ValueOrException<TargetParsingException>> resolvedPatterns = env .getValuesOrThrow(patternSkyKeys, TargetParsingException.class); if (env.valuesMissing()) { return null; } List<SkyKey> expandedSuiteKeys = new ArrayList<>(); for (SkyKey key : patternSkyKeys) { TargetPatternValue value; try { value = (TargetPatternValue) resolvedPatterns.get(key).get(); } catch (TargetParsingException e) { // Skip. continue; } expandedSuiteKeys.add(TestSuiteExpansionValue.key(value.getTargets().getTargets())); } Map<SkyKey, SkyValue> expandedSuites = env.getValues(expandedSuiteKeys); if (env.valuesMissing()) { return null; } ResolvedTargets.Builder<Target> testTargetsBuilder = ResolvedTargets.builder(); for (SkyKey key : patternSkyKeys) { TargetPatternKey pattern = (TargetPatternKey) key.argument(); TargetPatternValue value; try { value = (TargetPatternValue) resolvedPatterns.get(key).get(); } catch (TargetParsingException e) { // This was already reported in getTargetsToBuild (maybe merge the two code paths?). continue; } TestSuiteExpansionValue expandedSuitesValue = (TestSuiteExpansionValue) expandedSuites .get(TestSuiteExpansionValue.key(value.getTargets().getTargets())); if (pattern.isNegative()) { ResolvedTargets<Target> negativeTargets = expandedSuitesValue.getTargets(); testTargetsBuilder.filter(Predicates.not(Predicates.in(negativeTargets.getTargets()))); testTargetsBuilder.mergeError(negativeTargets.hasError()); } else { ResolvedTargets<Target> positiveTargets = expandedSuitesValue.getTargets(); testTargetsBuilder.addAll(positiveTargets.getTargets()); testTargetsBuilder.mergeError(positiveTargets.hasError()); } } testTargetsBuilder.filter(testFilter); return testTargetsBuilder.build(); }
From source file:org.kitesdk.data.spi.Constraints.java
@SuppressWarnings("unchecked") public Constraints with(String name, Object... values) { SchemaUtil.checkTypeConsistency(schema, strategy, name, values); if (values.length > 0) { checkContained(name, values);//from w w w .jav a 2s . co m // this is the most specific constraint and is idempotent under "and" return new Constraints(schema, strategy, constraints, name, Predicates.in(values)); } else { if (!constraints.containsKey(name)) { // no other constraint => add the exists return new Constraints(schema, strategy, constraints, name, Predicates.exists()); } else { // satisfied by an existing constraint return this; } } }
From source file:de.iteratec.iteraplan.presentation.dialog.common.model.businessmapping.BusinessMappingsComponentModel.java
/** * Updates the business mapping model with new business mappings calculated by the cartesian * product of the given {@link BusinessProcess}, {@link BusinessUnit} and {@link Product} lists. *//*w w w. ja v a 2s.c o m*/ List<BusinessMapping> updateClusterPartsWithNewBusinessMapping(BusinessMappingItems bmi) { final BusinessMappingStrategy strategy = BusinessMappingStrategyFactory.getStrategyFor(source.getClass()); strategy.validate(bmi); final List<BusinessMapping> businessMappings = strategy.createBusinessMappings(bmi); final List<BusinessMapping> existingMappings = this.findExistingBusinessMappings(businessMappings, strategy); final Iterable<BusinessMapping> newMappings = Iterables.filter(businessMappings, Predicates.not(Predicates.in(existingMappings))); for (BusinessMapping businessMapping : newMappings) { strategy.addOwningEntity(businessMapping, source); final SingleBusinessMappingComponentModelPart covPart = new SingleBusinessMappingComponentModelPart( businessMapping, getComponentMode()); covPart.initializeFrom(this.bmiSorted); final C clusterElementFromMapping = clusterElementRetriever .getClusterElementFromMapping(businessMapping); final ClusterComponentModelPart<T, C> clusterPart = getOrCreateClusterPart(clusterElementFromMapping); clusterPart.addMappingPart(covPart); } if (Iterables.isEmpty(newMappings) && existingMappings.isEmpty()) { // the user tried to add topLevelElements only -> throw an exception throw new IteraplanBusinessException(IteraplanErrorMessages.CANNOT_ADD_INVALID_BUSINESS_MAPPINGS); } return existingMappings; }
From source file:com.google.errorprone.scanner.BuiltInCheckerSuppliers.java
/** * Returns a {@link ScannerSupplier} with the {@link BugChecker}s that are in the ENABLED_ERRORS * list.//from w w w .ja v a 2s. c o m */ public static ScannerSupplier errorChecks() { return allChecks().filter(Predicates.in(ENABLED_ERRORS)); }
From source file:com.google.devtools.build.lib.rules.genquery.GenQuery.java
@Nullable private byte[] executeQuery(RuleContext ruleContext, QueryOptions queryOptions, Set<Target> scope, String query) throws InterruptedException { SkyFunction.Environment env = ruleContext.getAnalysisEnvironment().getSkyframeEnv(); Pair<ImmutableMap<PackageIdentifier, Package>, ImmutableMap<Label, Target>> closureInfo; try {//w ww .j a va2s . co m closureInfo = constructPackageMap(env, scope); if (closureInfo == null) { return null; } } catch (BrokenQueryScopeException e) { ruleContext.ruleError(e.getMessage()); return null; } ImmutableMap<PackageIdentifier, Package> packageMap = closureInfo.first; ImmutableMap<Label, Target> validTargetsMap = closureInfo.second; PackageProvider packageProvider = new PreloadedMapPackageProvider(packageMap, validTargetsMap); TargetPatternEvaluator evaluator = new SkyframeEnvTargetPatternEvaluator(env); Predicate<Label> labelFilter = Predicates.in(validTargetsMap.keySet()); return doQuery(queryOptions, packageProvider, labelFilter, evaluator, query, ruleContext); }
From source file:com.android.build.gradle.tasks.PackageAndroidArtifact.java
/** * Packages the application incrementally. In case of instant run packaging, this is not a * perfectly incremental task as some files are always rewritten even if no change has * occurred./* w ww . j a v a 2 s.c om*/ * * @param changedDex incremental dex packaging data * @param changedJavaResources incremental java resources * @param changedAssets incremental assets * @param changedAndroidResources incremental Android resource * @param changedNLibs incremental native libraries changed * @throws IOException failed to package the APK */ private void doTask(@NonNull ImmutableMap<RelativeFile, FileStatus> changedDex, @NonNull ImmutableMap<RelativeFile, FileStatus> changedJavaResources, @NonNull ImmutableMap<RelativeFile, FileStatus> changedAssets, @NonNull ImmutableMap<RelativeFile, FileStatus> changedAndroidResources, @NonNull ImmutableMap<RelativeFile, FileStatus> changedNLibs) throws IOException { ImmutableMap.Builder<RelativeFile, FileStatus> javaResourcesForApk = ImmutableMap.builder(); javaResourcesForApk.putAll(changedJavaResources); Collection<File> instantRunDexBaseFiles; switch (dexPackagingPolicy) { case INSTANT_RUN_SHARDS_IN_SINGLE_APK: /* * If we're doing instant run, then we don't want to treat all dex archives * as dex archives for packaging. We will package some of the dex files as * resources. * * All dex files in directories whose name contains INSTANT_RUN_PACKAGES_PREFIX * are kept in the apk as dex files. All other dex files are placed as * resources as defined by makeInstantRunResourcesFromDex. */ instantRunDexBaseFiles = getDexFolders().stream() .filter(input -> input.getName().contains(INSTANT_RUN_PACKAGES_PREFIX)) .collect(Collectors.toSet()); Iterable<File> nonInstantRunDexBaseFiles = getDexFolders().stream() .filter(f -> !instantRunDexBaseFiles.contains(f)).collect(Collectors.toSet()); ImmutableMap<RelativeFile, FileStatus> newInstantRunResources = makeInstantRunResourcesFromDex( nonInstantRunDexBaseFiles); @SuppressWarnings("unchecked") ImmutableMap<RelativeFile, FileStatus> updatedChangedResources = IncrementalRelativeFileSets .union(Sets.newHashSet(changedJavaResources, newInstantRunResources)); changedJavaResources = updatedChangedResources; changedDex = ImmutableMap.copyOf(Maps.filterKeys(changedDex, Predicates.compose(Predicates.in(instantRunDexBaseFiles), RelativeFile.EXTRACT_BASE))); break; case INSTANT_RUN_MULTI_APK: instantRunDexBaseFiles = getDexFolders().stream() .filter(input -> input.getName().contains(InstantRunSlicer.MAIN_SLICE_NAME)) .collect(Collectors.toSet()); changedDex = ImmutableMap.copyOf(Maps.filterKeys(changedDex, Predicates.compose(Predicates.in(instantRunDexBaseFiles), RelativeFile.EXTRACT_BASE))); case STANDARD: break; default: throw new RuntimeException("Unhandled DexPackagingPolicy : " + getDexPackagingPolicy()); } PrivateKey key; X509Certificate certificate; boolean v1SigningEnabled; boolean v2SigningEnabled; try { if (signingConfig != null && signingConfig.isSigningReady()) { CertificateInfo certificateInfo = KeystoreHelper.getCertificateInfo(signingConfig.getStoreType(), checkNotNull(signingConfig.getStoreFile()), checkNotNull(signingConfig.getStorePassword()), checkNotNull(signingConfig.getKeyPassword()), checkNotNull(signingConfig.getKeyAlias())); key = certificateInfo.getKey(); certificate = certificateInfo.getCertificate(); v1SigningEnabled = signingConfig.isV1SigningEnabled(); v2SigningEnabled = signingConfig.isV2SigningEnabled(); } else { key = null; certificate = null; v1SigningEnabled = false; v2SigningEnabled = false; } ApkCreatorFactory.CreationData creationData = new ApkCreatorFactory.CreationData(getOutputFile(), key, certificate, v1SigningEnabled, v2SigningEnabled, null, // BuiltBy getBuilder().getCreatedBy(), getMinSdkVersion(), PackagingUtils.getNativeLibrariesLibrariesPackagingMode(manifest), getNoCompressPredicate()::apply); try (IncrementalPackager packager = createPackager(creationData)) { packager.updateDex(changedDex); packager.updateJavaResources(changedJavaResources); packager.updateAssets(changedAssets); packager.updateAndroidResources(changedAndroidResources); packager.updateNativeLibraries(changedNLibs); } } catch (PackagerException | KeytoolException e) { throw new RuntimeException(e); } /* * Save all used zips in the cache. */ Stream.concat(changedDex.keySet().stream(), Stream.concat(changedJavaResources.keySet().stream(), Stream.concat(changedAndroidResources.keySet().stream(), changedNLibs.keySet().stream()))) .map(RelativeFile::getBase).filter(File::isFile).distinct().forEach((File f) -> { try { cacheByPath.add(f); } catch (IOException e) { throw new IOExceptionWrapper(e); } }); // Mark this APK production, this will eventually be saved when instant-run is enabled. // this might get overridden if the apk is signed/aligned. try { instantRunContext.addChangedFile(instantRunFileType, getOutputFile()); } catch (IOException e) { throw new BuildException(e.getMessage(), e); } }
From source file:org.jclouds.googlecomputeengine.compute.extensions.GoogleComputeEngineSecurityGroupExtension.java
private SecurityGroup groupForTagsInNetwork(Network nw, final Set<String> tags) { ListOptions opts = new Builder().filter("network eq .*/" + nw.getName()); Set<Firewall> fws = api.getFirewallApiForProject(userProject.get()).list(opts).concat() .filter(new Predicate<Firewall>() { @Override/* ww w. j a va 2 s .c om*/ public boolean apply(final Firewall input) { // If any of the targetTags on the firewall apply or the firewall has no target tags... return Iterables.any(input.getTargetTags(), Predicates.in(tags)) || Predicates.equalTo(0).apply(input.getTargetTags().size()); } }).toSet(); if (fws.isEmpty()) { return null; } return groupConverter.apply(nw); }