List of usage examples for com.google.common.base Predicates instanceOf
@GwtIncompatible("Class.isInstance") public static Predicate<Object> instanceOf(Class<?> clazz)
From source file:vazkii.botania.common.block.tile.TileEnchanter.java
@Override public ISparkEntity getAttachedSpark() { List<Entity> sparks = worldObj.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(pos.getX(), pos.getY() + 1, pos.getZ(), pos.getX() + 1, pos.getY() + 2, pos.getZ() + 1), Predicates.instanceOf(ISparkEntity.class)); if (sparks.size() == 1) { Entity e = sparks.get(0); return (ISparkEntity) e; }/*from w ww . ja v a2s. c om*/ return null; }
From source file:org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.EMFCompareStructureMergeViewerContentProvider.java
private IDifferenceGroupProvider2 getGroupProvider2(TreeNode treeNode) { IDifferenceGroupProvider2 result = null; Optional<Adapter> searchResult = Iterables.tryFind(treeNode.eAdapters(), Predicates.instanceOf(IDifferenceGroupProvider2.class)); if (searchResult.isPresent()) { return (IDifferenceGroupProvider2) searchResult.get(); }/*from www .jav a 2 s . co m*/ return result; }
From source file:org.eclipse.sirius.diagram.ui.tools.internal.actions.repair.AbstractDiagramElementState.java
/** * Restore {@link GraphicalFilter}.//from ww w .j a v a 2s .c o m * * @param element * the {@link DDiagramElement} on which restore the specified * {@link GraphicalFilter} * @param filter * the specified {@link GraphicalFilter} to restore */ protected void addFilterType(DDiagramElement element, GraphicalFilter filter) { if (!Iterables.any(element.getGraphicalFilters(), Predicates.instanceOf(filter.getClass()))) { element.getGraphicalFilters().add(filter); } }
From source file:org.sosy_lab.cpachecker.cpa.bam.ARGSubtreeRemover.java
private boolean removeUnpreciseCacheEntriesOnPath(ARGState rootState, AbstractState reducedRootState, List<Precision> pNewPrecisions, Block rootBlock, Deque<ARGState> remainingPathElements, Map<ARGState, ARGState> pPathElementToReachedState, Set<ARGState> callNodes, Set<ARGState> returnNodes, Map<ARGState, UnmodifiableReachedSet> pathElementToOuterReachedSet, Set<Pair<ARGState, ARGState>> neededRemoveCachedSubtreeCalls) { UnmodifiableReachedSet outerReachedSet = pathElementToOuterReachedSet.get(rootState); Precision rootPrecision = outerReachedSet.getPrecision(pPathElementToReachedState.get(rootState)); for (Precision pNewPrecision : pNewPrecisions) { rootPrecision = Precisions.replaceByType(rootPrecision, pNewPrecision, Predicates.instanceOf(pNewPrecision.getClass())); }/* w w w .j av a 2 s. co m*/ Precision reducedNewPrecision = wrappedReducer.getVariableReducedPrecision(rootPrecision, rootBlock); UnmodifiableReachedSet innerReachedSet = abstractStateToReachedSet .get(pPathElementToReachedState.get(rootState)); Precision usedPrecision = innerReachedSet.getPrecision(innerReachedSet.getFirstState()); //add precise key for new precision if needed if (!bamCache.containsPreciseKey(reducedRootState, reducedNewPrecision, rootBlock)) { ReachedSet reachedSet = createInitialReachedSet(reducedRootState, reducedNewPrecision); bamCache.put(reducedRootState, reducedNewPrecision, rootBlock, reachedSet); } boolean isNewPrecisionEntry = usedPrecision.equals(reducedNewPrecision); //fine, this block will not lead to any problems anymore, but maybe inner blocks will? //-> check other (inner) blocks on path boolean foundInnerUnpreciseEntries = false; while (!remainingPathElements.isEmpty()) { ARGState currentElement = remainingPathElements.pop(); if (callNodes.contains(currentElement)) { ARGState currentReachedState = pPathElementToReachedState.get(currentElement); CFANode node = extractLocation(currentReachedState); Block currentBlock = partitioning.getBlockForCallNode(node); AbstractState reducedState = wrappedReducer.getVariableReducedState(currentReachedState, currentBlock, node); boolean removedUnpreciseInnerBlock = removeUnpreciseCacheEntriesOnPath(currentElement, reducedState, pNewPrecisions, currentBlock, remainingPathElements, pPathElementToReachedState, callNodes, returnNodes, pathElementToOuterReachedSet, neededRemoveCachedSubtreeCalls); if (removedUnpreciseInnerBlock) { //ok we indeed found an inner block that was unprecise if (isNewPrecisionEntry && !foundInnerUnpreciseEntries) { //if we are in a reached set that already uses the new precision and this is the first such entry we have to remove the subtree starting from currentElement in the rootReachedSet neededRemoveCachedSubtreeCalls .add(Pair.of(pPathElementToReachedState.get(rootState), currentReachedState)); foundInnerUnpreciseEntries = true; } } } if (returnNodes.contains(currentElement)) { //our block ended. Leave.. return foundInnerUnpreciseEntries || !isNewPrecisionEntry; } } return foundInnerUnpreciseEntries || !isNewPrecisionEntry; }
From source file:vazkii.botania.common.block.tile.mana.TilePool.java
@Override public ISparkEntity getAttachedSpark() { List sparks = worldObj.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(pos.up(), pos.up().add(1, 1, 1)), Predicates.instanceOf(ISparkEntity.class)); if (sparks.size() == 1) { Entity e = (Entity) sparks.get(0); return (ISparkEntity) e; }//w w w .ja va2 s .c o m return null; }
From source file:com.facebook.swift.codec.metadata.AbstractThriftMetadataBuilder.java
protected final void addMethod(Type type, Method method, boolean allowReaders, boolean allowWriters) { checkArgument(method.isAnnotationPresent(ThriftField.class)); ThriftField annotation = method.getAnnotation(ThriftField.class); Class<?> clazz = TypeToken.of(type).getRawType(); // verify parameters if (isValidateGetter(method)) { if (allowReaders) { MethodExtractor methodExtractor = new MethodExtractor(type, method, annotation, THRIFT_FIELD); fields.add(methodExtractor); extractors.add(methodExtractor); } else {/*from www . j ava 2s. c o m*/ metadataErrors.addError("Reader method %s.%s is not allowed on a builder class", clazz.getName(), method.getName()); } } else if (isValidateSetter(method)) { if (allowWriters) { List<ParameterInjection> parameters; if (method.getParameterTypes().length > 1 || Iterables.any( asList(method.getParameterAnnotations()[0]), Predicates.instanceOf(ThriftField.class))) { parameters = getParameterInjections(type, method.getParameterAnnotations(), resolveFieldTypes(type, method.getGenericParameterTypes()), extractParameterNames(method)); if (annotation.value() != Short.MIN_VALUE) { metadataErrors.addError( "A method with annotated parameters can not have a field id specified: %s.%s ", clazz.getName(), method.getName()); } if (!annotation.name().isEmpty()) { metadataErrors.addError( "A method with annotated parameters can not have a field name specified: %s.%s ", clazz.getName(), method.getName()); } if (annotation.requiredness() == Requiredness.REQUIRED) { metadataErrors.addError( "A method with annotated parameters can not be marked as required: %s.%s ", clazz.getName(), method.getName()); } } else { Type parameterType = resolveFieldTypes(type, method.getGenericParameterTypes())[0]; parameters = ImmutableList.of(new ParameterInjection(type, 0, annotation, ReflectionHelper.extractFieldName(method), parameterType)); } fields.addAll(parameters); methodInjections.add(new MethodInjection(method, parameters)); } else { metadataErrors.addError( "Inject method %s.%s is not allowed on struct class, since struct has a builder", clazz.getName(), method.getName()); } } else { metadataErrors.addError("Method %s.%s is not a supported getter or setter", clazz.getName(), method.getName()); } }
From source file:com.cloudera.impala.planner.HdfsScanNode.java
/** * Evaluate an InPredicate filter on a partition column and return the ids of * the matching partitions./*w w w . j a v a2s. co m*/ */ private HashSet<Long> evalInPredicate(Expr expr) { Preconditions.checkNotNull(expr); Preconditions.checkState(expr instanceof InPredicate); InPredicate inPredicate = (InPredicate) expr; HashSet<Long> matchingIds = Sets.newHashSet(); SlotRef slot = inPredicate.getBoundSlot(); Preconditions.checkNotNull(slot); int partitionPos = slot.getDesc().getColumn().getPosition(); TreeMap<LiteralExpr, HashSet<Long>> partitionValueMap = tbl_.getPartitionValueMap(partitionPos); if (inPredicate.isNotIn()) { // Case: SlotRef NOT IN (Literal, ..., Literal) // If there is a NullLiteral, return an empty set. List<Expr> nullLiterals = Lists.newArrayList(); inPredicate.collectAll(Predicates.instanceOf(NullLiteral.class), nullLiterals); if (!nullLiterals.isEmpty()) return matchingIds; matchingIds.addAll(tbl_.getPartitionIds()); // Exclude partitions with null partition column values HashSet<Long> nullIds = tbl_.getNullPartitionIds(partitionPos); matchingIds.removeAll(nullIds); } // Compute the matching partition ids for (int i = 1; i < inPredicate.getChildren().size(); ++i) { LiteralExpr literal = (LiteralExpr) inPredicate.getChild(i); HashSet<Long> idSet = partitionValueMap.get(literal); if (idSet != null) { if (inPredicate.isNotIn()) { matchingIds.removeAll(idSet); } else { matchingIds.addAll(idSet); } } } return matchingIds; }
From source file:org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.BasicDifferenceGroupImpl.java
/** * This can be used to check whether a givan diff is a resource attachment change. * /*from ww w . j a v a2 s . co m*/ * @return The created predicate. */ protected static Predicate<? super Diff> resourceAttachmentChange() { return Predicates.instanceOf(ResourceAttachmentChange.class); }
From source file:org.eclipse.sirius.diagram.sequence.business.internal.layout.vertical.SequenceVerticalLayout.java
private Map<ISequenceEvent, Range> computeBasicRanges(Map<EventEnd, Integer> endLocations) { final Map<ISequenceEvent, Range> sequenceEventsToRange = new LinkedHashMap<ISequenceEvent, Range>(); Predicate<ISequenceEvent> notMoved = Predicates.not(Predicates.in(sequenceEventsToRange.keySet())); // CombinedFragments for (EventEnd sortedEnd : semanticOrdering) { Predicate<ISequenceEvent> frames = Predicates.and(notMoved, Predicates.or( Predicates.instanceOf(CombinedFragment.class), Predicates.instanceOf(InteractionUse.class))); for (ISequenceEvent ise : Iterables.filter(endToISequencEvents.get(sortedEnd), frames)) { computeFinalRange(endLocations, sequenceEventsToRange, ise); }//from w ww.j a v a 2s . co m } // Operands for (EventEnd sortedEnd : semanticOrdering) { Predicate<ISequenceEvent> operands = Predicates.and(notMoved, Predicates.instanceOf(Operand.class)); for (ISequenceEvent ise : Iterables.filter(endToISequencEvents.get(sortedEnd), operands)) { computeFinalRange(endLocations, sequenceEventsToRange, ise); } } // Other sequence events for (EventEnd sortedEnd : semanticOrdering) { for (ISequenceEvent ise : Iterables.filter(endToISequencEvents.get(sortedEnd), notMoved)) { computeFinalRange(endLocations, sequenceEventsToRange, ise); } } return sequenceEventsToRange; }
From source file:fr.aliacom.obm.common.calendar.EventNotificationServiceImpl.java
private Collection<Attendee> filterAttendees(final Event event, Collection<Attendee> attendees) { return FluentIterable.from(attendees).filter(new Predicate<Attendee>() { @Override/* w w w . java 2 s . c o m*/ public boolean apply(Attendee attendee) { return !attendee.getEmail().equalsIgnoreCase(event.getOwnerEmail()); } }).filter(Predicates.not(Predicates.instanceOf(ResourceAttendee.class))).toSet(); }