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.apache.whirr.compute.StartupProcess.java
void cleanupFailedNodes() throws InterruptedException { if (lostNodes.size() > 0) { Set<String> lostIds = Sets.newLinkedHashSet(); for (Entry<NodeMetadata, Throwable> lostNode : lostNodes.entrySet()) { LOG.debug("Will destroy failed node {}", lostNode.getKey(), lostNode.getValue()); lostIds.add(lostNode.getKey().getId()); }//from w w w.j av a2 s .c o m LOG.info("Destroying failed nodes {}", lostIds); Set<? extends NodeMetadata> destroyedNodes = computeService .destroyNodesMatching(Predicates.in(lostNodes.keySet())); lostIds.clear(); for (NodeMetadata destroyed : destroyedNodes) { lostIds.add(destroyed.getId()); } LOG.info("Destroyed failed nodes {}", lostIds); } }
From source file:org.eclipse.sirius.ui.tools.internal.views.common.modelingproject.manager.ModelingProjectManagerImpl.java
private void loadAndOpenRepresentationsFiles(final List<URI> representationsFilesURIs, boolean user) { // Add the specific sessions listener (if not already added). SessionManager.INSTANCE.addSessionsListener(sessionManagerListener); // List only the representations files that are not already loaded or // that are not currently in loading. Iterator<URI> representationsFilesURIsToLoadIterator = Iterators.filter(representationsFilesURIs.iterator(), Predicates.not(Predicates.or(Predicates.in(sessionFileLoading), isAlreadyLoadedPredicate))); if (!representationsFilesURIsToLoadIterator.hasNext()) { return;// www . j a va2 s . c om } // We add the representationsFilesURIs to the list of representations // files that are currently loading because the event // SessionListener.OPENING comes too late (after loading of the // representations file that can be very long). List<URI> tempRepresentationsFilesURIs = Lists.newArrayList(representationsFilesURIsToLoadIterator); sessionFileLoading.addAll(tempRepresentationsFilesURIs); // Launch the silently job to open the representations files for (URI representationsFilesURI : tempRepresentationsFilesURIs) { OpenRepresentationsFileJob.scheduleNewWhenPossible(representationsFilesURI, user); } }
From source file:org.apache.helix.controller.rebalancer.strategy.CrushRebalanceStrategy.java
/** * Use the predicate to reject already selected zones or nodes. */// w w w . ja v a 2 s . co m private Predicate<Node> nodeAlreadySelected(Set<Node> selectedNodes) { return Predicates.not(Predicates.in(selectedNodes)); }
From source file:org.eclipse.sirius.diagram.sequence.ui.tool.internal.edit.policy.SequenceInteractionFeedBackBuilder.java
private void feedBackMovedElements(Collection<Figure> feedbacks) { for (ISequenceEvent movedElement : Iterables.filter(validator.getMovedElements(), Predicates.not(Predicates.in(validator.getEventsInError())))) { addFeedBack(movedElement, ISE_FEEDBACK_COLOR, false, feedbacks, validator.getRangeFunction().apply(movedElement)); }//from w w w. j a v a 2 s . c o m }
From source file:org.sosy_lab.cpachecker.cpa.arg.ARGStatistics.java
@Override public void printStatistics(PrintStream pOut, Result pResult, ReachedSet pReached) { if (!exportARG && !exportErrorPath) { // shortcut, avoid unnecessary creation of path etc. assert refinementGraphWriter == null; return;//from w w w . j av a2s .c o m } final Set<Pair<ARGState, ARGState>> allTargetPathEdges = new HashSet<>(); int cexIndex = 0; for (Map.Entry<ARGState, CounterexampleInfo> cex : getAllCounterexamples(pReached).entrySet()) { cexExporter.exportCounterexample(cex.getKey(), cex.getValue(), cexIndex++, allTargetPathEdges, !cexExporter.shouldDumpErrorPathImmediately()); } if (exportARG) { final ARGState rootState = (ARGState) pReached.getFirstState(); exportARG(rootState, Predicates.in(allTargetPathEdges)); } }
From source file:eu.lp0.cursus.scoring.scores.impl.GenericRaceLapsData.java
protected Iterable<Pilot> extractRaceLaps(Race race, Predicate<Pilot> filter) { // If they aren't marked as attending the race as a pilot, they don't get scored Predicate<Pilot> attending = Predicates.in(filteredPilots(race)); if (filter != null) { filter = Predicates.and(attending, filter); } else {/* ww w . j a v a 2 s . c o m*/ filter = attending; } // Convert a list of race events into a list of valid pilot laps return Iterables.filter(Iterables.transform(Iterables.unmodifiableIterable(race.getTallies()), new Function<RaceTally, Pilot>() { boolean scoring = scoreBeforeStart; @Override public Pilot apply(@Nonnull RaceTally tally) { switch (tally.getType()) { case START: scoring = true; break; case LAP: if (scoring) { return tally.getPilot(); } break; case INVALID_LAP: break; case FINISH: scoring = scoreAfterFinish; break; } return null; } }), filter); }
From source file:org.immutables.generator.SourceOrdering.java
/** * While we have {@link SourceOrdering}, there's still a problem: We have inheritance hierarchy * and// www. j a v a 2s . c o m * we want to have all defined or inherited accessors returned as members of target type, like * {@link Elements#getAllMembers(TypeElement)}, but we need to have them properly and stably * sorted. * This implementation doesn't try to correctly resolve order for accessors inherited from * different supertypes(interfaces), just something that stable and reasonable wrt source ordering * without handling complex cases. * @param elements the elements utility * @param types the types utility * @param type the type to traverse * @return provider of all accessors in source order and mapping */ public static AccessorProvider getAllAccessorsProvider(final Elements elements, final Types types, final TypeElement type) { class CollectedOrdering extends Ordering<Element> { class Intratype { Ordering<String> ordering; int rank; } final Map<String, Intratype> accessorOrderings = Maps.newLinkedHashMap(); final List<TypeElement> linearizedTypes = Lists.newArrayList(); final Predicate<String> accessorNotYetInOrderings = Predicates .not(Predicates.in(accessorOrderings.keySet())); final ArrayListMultimap<String, TypeElement> accessorMapping = ArrayListMultimap.create(); CollectedOrdering() { traverse(type); traverseObjectForInterface(); } private void traverseObjectForInterface() { if (type.getKind() == ElementKind.INTERFACE) { traverse(elements.getTypeElement(Object.class.getName())); } } void traverse(@Nullable TypeElement element) { if (element == null) { return; } collectEnclosing(element); traverse(asTypeElement(element.getSuperclass())); for (TypeMirror implementedInterface : element.getInterfaces()) { traverse(asTypeElement(implementedInterface)); } } @Nullable TypeElement asTypeElement(TypeMirror type) { if (type.getKind() == TypeKind.DECLARED) { return (TypeElement) ((DeclaredType) type).asElement(); } return null; } void collectEnclosing(TypeElement type) { FluentIterable<String> accessorsInType = FluentIterable .from(SourceOrdering.getEnclosedElements(type)).filter(IsParameterlessNonstatic.PREDICATE) .transform(ToSimpleName.FUNCTION); for (String accessor : accessorsInType) { accessorMapping.put(accessor, type); } List<String> accessors = accessorsInType.filter(accessorNotYetInOrderings).toList(); Intratype intratype = new Intratype(); intratype.rank = linearizedTypes.size(); intratype.ordering = Ordering.explicit(accessors); for (String name : accessors) { accessorOrderings.put(name, intratype); } linearizedTypes.add(type); } @Override public int compare(Element left, Element right) { String leftKey = ToSimpleName.FUNCTION.apply(left); String rightKey = ToSimpleName.FUNCTION.apply(right); Intratype leftIntratype = accessorOrderings.get(leftKey); Intratype rightIntratype = accessorOrderings.get(rightKey); if (leftIntratype == null || rightIntratype == null) { // FIXME figure out why it happens (null) return Boolean.compare(leftIntratype == null, rightIntratype == null); } return leftIntratype == rightIntratype ? leftIntratype.ordering.compare(leftKey, rightKey) : Integer.compare(leftIntratype.rank, rightIntratype.rank); } } final CollectedOrdering ordering = new CollectedOrdering(); return new AccessorProvider() { ImmutableListMultimap<String, TypeElement> accessorMapping = ImmutableListMultimap .copyOf(ordering.accessorMapping); ImmutableList<ExecutableElement> sortedList = FluentIterable .from(ElementFilter.methodsIn(elements.getAllMembers(type))) .filter(IsParameterlessNonstatic.PREDICATE).toSortedList(ordering); @Override public ImmutableListMultimap<String, TypeElement> accessorMapping() { return accessorMapping; } @Override public ImmutableList<ExecutableElement> get() { return sortedList; } }; }
From source file:com.b2international.snowowl.datastore.server.CDORepositoryManager.java
@Override public void disconnect(final Iterable<String> userIds, final ISessionOperationCallback... callbacks) { Preconditions.checkNotNull(userIds, "User ID iterable argument cannot be null."); applyDisconnect(Predicates.in(Sets.newHashSet(userIds)), callbacks); }
From source file:io.prestosql.plugin.hive.HivePartitionManager.java
public HivePartitionResult getPartitions(SemiTransactionalHiveMetastore metastore, ConnectorTableHandle tableHandle, Constraint<ColumnHandle> constraint) { HiveTableHandle hiveTableHandle = (HiveTableHandle) tableHandle; TupleDomain<ColumnHandle> effectivePredicate = constraint.getSummary(); SchemaTableName tableName = hiveTableHandle.getSchemaTableName(); Table table = getTable(metastore, tableName); Optional<HiveBucketHandle> hiveBucketHandle = getHiveBucketHandle(table); List<HiveColumnHandle> partitionColumns = getPartitionKeyColumnHandles(table); if (effectivePredicate.isNone()) { return new HivePartitionResult(partitionColumns, ImmutableList.of(), none(), none(), none(), hiveBucketHandle, Optional.empty()); }//w ww .j a va 2 s . com Optional<HiveBucketFilter> bucketFilter = getHiveBucketFilter(table, effectivePredicate); TupleDomain<HiveColumnHandle> compactEffectivePredicate = toCompactTupleDomain(effectivePredicate, domainCompactionThreshold); if (partitionColumns.isEmpty()) { return new HivePartitionResult(partitionColumns, ImmutableList.of(new HivePartition(tableName)), compactEffectivePredicate, effectivePredicate, none(), hiveBucketHandle, bucketFilter); } List<Type> partitionTypes = partitionColumns.stream() .map(column -> typeManager.getType(column.getTypeSignature())).collect(toList()); List<String> partitionNames = getFilteredPartitionNames(metastore, tableName, partitionColumns, effectivePredicate); Iterable<HivePartition> partitionsIterable = () -> partitionNames.stream() // Apply extra filters which could not be done by getFilteredPartitionNames .map(partitionName -> parseValuesAndFilterPartition(tableName, partitionName, partitionColumns, partitionTypes, constraint)) .filter(Optional::isPresent).map(Optional::get).iterator(); // All partition key domains will be fully evaluated, so we don't need to include those TupleDomain<ColumnHandle> remainingTupleDomain = TupleDomain.withColumnDomains( Maps.filterKeys(effectivePredicate.getDomains().get(), not(Predicates.in(partitionColumns)))); TupleDomain<ColumnHandle> enforcedTupleDomain = TupleDomain.withColumnDomains( Maps.filterKeys(effectivePredicate.getDomains().get(), Predicates.in(partitionColumns))); return new HivePartitionResult(partitionColumns, partitionsIterable, compactEffectivePredicate, remainingTupleDomain, enforcedTupleDomain, hiveBucketHandle, bucketFilter); }
From source file:com.google.devtools.build.skyframe.SkyFunctionEnvironment.java
private Map<SkyKey, ? extends NodeEntry> batchPrefetch(SkyKey requestor, GroupedList<SkyKey> depKeys, Set<SkyKey> oldDeps, boolean assertDone, SkyKey keyForDebugging) throws InterruptedException { Iterable<SkyKey> depKeysAsIterable = Iterables.concat(depKeys); Iterable<SkyKey> keysToPrefetch = depKeysAsIterable; if (PREFETCH_OLD_DEPS) { ImmutableSet.Builder<SkyKey> keysToPrefetchBuilder = ImmutableSet.builder(); keysToPrefetchBuilder.addAll(depKeysAsIterable).addAll(oldDeps); keysToPrefetch = keysToPrefetchBuilder.build(); }/* w ww.j a v a 2 s . c o m*/ Map<SkyKey, ? extends NodeEntry> batchMap = evaluatorContext.getBatchValues(requestor, Reason.PREFETCH, keysToPrefetch); if (PREFETCH_OLD_DEPS) { batchMap = ImmutableMap.<SkyKey, NodeEntry>copyOf( Maps.filterKeys(batchMap, Predicates.in(ImmutableSet.copyOf(depKeysAsIterable)))); } if (batchMap.size() != depKeys.numElements()) { throw new IllegalStateException("Missing keys for " + keyForDebugging + ": " + Sets.difference(depKeys.toSet(), batchMap.keySet())); } if (assertDone) { for (Map.Entry<SkyKey, ? extends NodeEntry> entry : batchMap.entrySet()) { Preconditions.checkState(entry.getValue().isDone(), "%s had not done %s", keyForDebugging, entry); } } return batchMap; }