List of usage examples for com.google.common.base Predicates in
public static <T> Predicate<T> in(Collection<? extends T> target)
From source file:com.facebook.buck.apple.WorkspaceAndProjectGenerator.java
private static void buildWorkspaceSchemeTests(Optional<BuildTarget> mainTarget, TargetGraph projectGraph, boolean includeProjectTests, boolean includeDependenciesTests, ImmutableSetMultimap<String, Optional<TargetNode<?>>> schemeNameToSrcTargetNode, ImmutableSetMultimap<String, TargetNode<AppleTestDescription.Arg>> extraTestNodes, ImmutableSetMultimap.Builder<String, TargetNode<AppleTestDescription.Arg>> selectedTestsBuilder, ImmutableSetMultimap.Builder<String, TargetNode<?>> buildForTestNodesBuilder) { for (String schemeName : schemeNameToSrcTargetNode.keySet()) { ImmutableSet<TargetNode<?>> targetNodes = ImmutableSet .copyOf(Optional.presentInstances(schemeNameToSrcTargetNode.get(schemeName))); ImmutableSet<TargetNode<AppleTestDescription.Arg>> testNodes = getOrderedTestNodes(mainTarget, projectGraph, includeProjectTests, includeDependenciesTests, targetNodes, extraTestNodes.get(schemeName)); selectedTestsBuilder.putAll(schemeName, testNodes); buildForTestNodesBuilder.putAll(schemeName, TopologicalSort.sort(projectGraph, Predicates.in(getTransitiveDepsAndInputs(projectGraph, testNodes, targetNodes)))); }// w ww . j a va2 s.co m }
From source file:com.eucalyptus.autoscaling.backend.AutoScalingBackendService.java
public DescribeTagsResponseType describeTags(final DescribeTagsType request) throws EucalyptusCloudException { final DescribeTagsResponseType reply = request.getReply(); //TODO: MaxRecords / NextToken support for DescribeTags final Collection<Predicate<Tag>> tagFilters = Lists.newArrayList(); for (final Filter filter : request.filters()) { final Function<Tag, String> extractor = tagFilterExtractors.get(filter.getName()); if (extractor == null) { throw new ValidationErrorException("Filter type " + filter.getName() + " is not correct. Allowed Filter types are: auto-scaling-group key value propagate-at-launch"); }// www . j a va 2 s .co m final Function<String, String> tagValueConverter = Objects .firstNonNull(tagValuePreProcessors.get(filter.getName()), Functions.<String>identity()); tagFilters.add(Predicates .compose(Predicates.in(Collections2.transform(filter.values(), tagValueConverter)), extractor)); } final Context context = Contexts.lookup(); final Ordering<Tag> ordering = Ordering.natural().onResultOf(Tags.resourceId()) .compound(Ordering.natural().onResultOf(Tags.key())) .compound(Ordering.natural().onResultOf(Tags.value())); try { final TagDescriptionList tagDescriptions = new TagDescriptionList(); for (final Tag tag : ordering .sortedCopy(Tags.list(context.getUserFullName().asAccountFullName(), Predicates.and(tagFilters), Restrictions.conjunction(), Collections.<String, String>emptyMap()))) { if (Permissions.isAuthorized(PolicySpec.VENDOR_AUTOSCALING, tag.getResourceType(), tag.getKey(), context.getAccount(), PolicySpec.describeAction(PolicySpec.VENDOR_AUTOSCALING, tag.getResourceType()), context.getAuthContext())) { tagDescriptions.getMember().add(TypeMappers.transform(tag, TagDescription.class)); } } if (!tagDescriptions.getMember().isEmpty()) { reply.getDescribeTagsResult().setTags(tagDescriptions); } } catch (AutoScalingMetadataNotFoundException e) { handleException(e); } return reply; }
From source file:com.google.devtools.build.lib.skyframe.ActionExecutionFunction.java
private static Iterable<Artifact> filterKnownInputs(Iterable<Artifact> newInputs, Set<Artifact> knownInputs) { return Iterables.filter(newInputs, Predicates.not(Predicates.in(knownInputs))); }
From source file:com.google.devtools.build.lib.query2.SkyQueryEnvironment.java
@Override public void buildTransitiveClosure(QueryExpression caller, Set<Target> targets, int maxDepth) throws QueryException, InterruptedException { // Everything has already been loaded, so here we just check for errors so that we can // pre-emptively throw/report if needed. Iterable<SkyKey> transitiveTraversalKeys = makeTransitiveTraversalKeys(targets); ImmutableList.Builder<String> errorMessagesBuilder = ImmutableList.builder(); // First, look for errors in the successfully evaluated TransitiveTraversalValues. They may // have encountered errors that they were able to recover from. Set<Entry<SkyKey, SkyValue>> successfulEntries = graph.getSuccessfulValues(transitiveTraversalKeys) .entrySet();//from ww w .ja v a 2 s .c om Builder<SkyKey> successfulKeysBuilder = ImmutableSet.builder(); for (Entry<SkyKey, SkyValue> successfulEntry : successfulEntries) { successfulKeysBuilder.add(successfulEntry.getKey()); TransitiveTraversalValue value = (TransitiveTraversalValue) successfulEntry.getValue(); String firstErrorMessage = value.getFirstErrorMessage(); if (firstErrorMessage != null) { errorMessagesBuilder.add(firstErrorMessage); } } ImmutableSet<SkyKey> successfulKeys = successfulKeysBuilder.build(); // Next, look for errors from the unsuccessfully evaluated TransitiveTraversal skyfunctions. Iterable<SkyKey> unsuccessfulKeys = Iterables.filter(transitiveTraversalKeys, Predicates.not(Predicates.in(successfulKeys))); Set<Entry<SkyKey, Exception>> errorEntries = graph.getMissingAndExceptions(unsuccessfulKeys).entrySet(); for (Map.Entry<SkyKey, Exception> entry : errorEntries) { if (entry.getValue() == null) { // Targets may be in the graph because they are not in the universe or depend on cycles. eventHandler.handle(Event.warn(entry.getKey().argument() + " does not exist in graph")); } else { errorMessagesBuilder.add(entry.getValue().getMessage()); } } // Lastly, report all found errors. ImmutableList<String> errorMessages = errorMessagesBuilder.build(); for (String errorMessage : errorMessages) { reportBuildFileError(caller, errorMessage); } }
From source file:com.eucalyptus.autoscaling.activities.ActivityManager.java
private Predicate<AutoScalingInstanceCoreView> withAvailabilityZone( final Collection<String> availabilityZones) { return Predicates.compose(Predicates.in(availabilityZones), availabilityZone()); }
From source file:com.google.devtools.build.lib.rules.android.AndroidBinary.java
private static ImmutableSet<AndroidBinaryType> getEffectiveIncrementalDexing(RuleContext ruleContext, List<String> dexopts, boolean isBinaryProguarded) { TriState override = ruleContext.attributes().get("incremental_dexing", BuildType.TRISTATE); // Ignore --incremental_dexing_binary_types if the incremental_dexing attribute is set, but // raise an error if proguard is enabled (b/c incompatible with incremental dexing ATM). if (isBinaryProguarded && override == TriState.YES) { ruleContext.attributeError("incremental_dexing", "target cannot be incrementally dexed because it uses Proguard"); return ImmutableSet.of(); }/*from www .j a v a 2 s .c o m*/ if (isBinaryProguarded || override == TriState.NO) { return ImmutableSet.of(); } ImmutableSet<AndroidBinaryType> result = override == TriState.YES ? ImmutableSet.copyOf(AndroidBinaryType.values()) : AndroidCommon.getAndroidConfig(ruleContext).getIncrementalDexingBinaries(); if (!result.isEmpty()) { Iterable<String> blacklistedDexopts = Iterables.filter(dexopts, new FlagMatcher( AndroidCommon.getAndroidConfig(ruleContext).getTargetDexoptsThatPreventIncrementalDexing())); if (!Iterables.isEmpty(blacklistedDexopts)) { // target's dexopts include flags blacklisted with --non_incremental_per_target_dexopts. If // incremental_dexing attribute is explicitly set for this target then we'll warn and // incrementally dex anyway. Otherwise, just don't incrementally dex. if (override == TriState.YES) { Iterable<String> ignored = Iterables.filter(blacklistedDexopts, Predicates.not(Predicates.in( AndroidCommon.getAndroidConfig(ruleContext).getDexoptsSupportedInIncrementalDexing()))); ruleContext.attributeWarning("incremental_dexing", String.format( "Using incremental dexing even though dexopts %s indicate this target " + "may be unsuitable for incremental dexing for the moment.%s", blacklistedDexopts, Iterables.isEmpty(ignored) ? "" : " These will be ignored: " + ignored)); } else { result = ImmutableSet.of(); } } } return result; }
From source file:com.palantir.atlasdb.transaction.impl.SnapshotTransaction.java
/** * This will throw if we have a value changed conflict. This means that either we changed the * value and anyone did a write after our start timestamp, or we just touched the value (put the * same value as before) and a changed value was written after our start time. *///from w ww . ja v a2 s. co m private void throwIfValueChangedConflict(String table, Map<Cell, byte[]> writes, Set<CellConflict> spanningWrites, Set<CellConflict> dominatingWrites, LockRefreshToken commitLocksToken) { Map<Cell, CellConflict> cellToConflict = Maps.newHashMap(); Map<Cell, Long> cellToTs = Maps.newHashMap(); for (CellConflict c : Sets.union(spanningWrites, dominatingWrites)) { cellToConflict.put(c.cell, c); cellToTs.put(c.cell, c.theirStart + 1); } Map<Cell, byte[]> oldValues = getIgnoringLocalWrites(table, cellToTs.keySet()); Map<Cell, Value> conflictingValues = keyValueService.get(table, cellToTs); Set<Cell> conflictingCells = Sets.newHashSet(); for (Entry<Cell, Long> cellEntry : cellToTs.entrySet()) { Cell cell = cellEntry.getKey(); if (!writes.containsKey(cell)) { Validate.isTrue(false, "Missing write for cell: " + cellToConflict.get(cell) + " for table " + table); } if (!conflictingValues.containsKey(cell)) { // This error case could happen if our locks expired. throwIfExternalAndCommitLocksNotValid(commitLocksToken); Validate.isTrue(false, "Missing conflicting value for cell: " + cellToConflict.get(cell) + " for table " + table); } if (conflictingValues.get(cell).getTimestamp() != (cellEntry.getValue() - 1)) { // This error case could happen if our locks expired. throwIfExternalAndCommitLocksNotValid(commitLocksToken); Validate.isTrue(false, "Wrong timestamp for cell in table " + table + " Expected: " + cellToConflict.get(cell) + " Actual: " + conflictingValues.get(cell)); } @Nullable byte[] oldVal = oldValues.get(cell); byte[] writeVal = writes.get(cell); byte[] conflictingVal = conflictingValues.get(cell).getContents(); if (!Transactions.cellValuesEqual(oldVal, writeVal) || !Arrays.equals(writeVal, conflictingVal)) { conflictingCells.add(cell); } else if (log.isInfoEnabled()) { log.info("Another transaction committed to the same cell before us but " + "their value was the same. " + "Cell: " + cell + " Table: " + table); } } if (conflictingCells.isEmpty()) { return; } Predicate<CellConflict> conflicting = Predicates.compose(Predicates.in(conflictingCells), CellConflict.getCellFunction()); throw TransactionConflictException.create(table, getStartTimestamp(), Sets.filter(spanningWrites, conflicting), Sets.filter(dominatingWrites, conflicting), System.currentTimeMillis() - timeCreated); }