List of usage examples for com.google.common.base Predicates instanceOf
@GwtIncompatible("Class.isInstance") public static Predicate<Object> instanceOf(Class<?> clazz)
From source file:org.eclipse.sirius.diagram.ui.business.internal.migration.DiagramRepresentationsFileMigrationParticipantV670.java
/** * Add a {@link IndirectlyCollapsedFilter} to the children of CollapsedNode * (to retrieve the same behavior as before). The migration of GMF bounds of * this indirectly collapsed nodes, if they are bordered nodes, are deal * later in method {{@link #migrateGMFBoundsOfBorderedNodes(List)}. * /* w ww.ja v a 2 s . com*/ * @param diagram * GMF Diagram to migrate. */ private void migrateChildrenOfCollapsedNode(Diagram diagram) { List<DDiagramElement> indirectlyCollaspedDDEs = Lists.newArrayList(); Iterator<Node> viewIterator = Iterators.filter(Iterators.filter(diagram.eAllContents(), Node.class), isDirectlyCollapsedNode); while (viewIterator.hasNext()) { final Node node = viewIterator.next(); if (node.getElement() instanceof AbstractDNode) { AbstractDNode abstractDNode = (AbstractDNode) node.getElement(); indirectlyCollaspedDDEs.addAll(abstractDNode.getOwnedBorderedNodes()); if (abstractDNode instanceof DNodeContainer) { DNodeContainer dDiagramElementContainer = (DNodeContainer) abstractDNode; indirectlyCollaspedDDEs.addAll(dDiagramElementContainer.getOwnedDiagramElements()); } else if (abstractDNode instanceof DNodeList) { DNodeList dNodeList = (DNodeList) abstractDNode; indirectlyCollaspedDDEs.addAll(dNodeList.getOwnedElements()); } } } for (DDiagramElement indirectlyCollaspedDDE : indirectlyCollaspedDDEs) { if (!Iterables.any(indirectlyCollaspedDDE.getGraphicalFilters(), Predicates.instanceOf(IndirectlyCollapseFilter.class))) { IndirectlyCollapseFilter indirectlyCollapseFilter = DiagramFactory.eINSTANCE .createIndirectlyCollapseFilter(); indirectlyCollaspedDDE.getGraphicalFilters().add(indirectlyCollapseFilter); } } }
From source file:com.facebook.litho.testing.viewtree.ViewTreeAssert.java
public <V extends View> ViewTreeAssert hasVisible(final Class<V> clazz, final Predicate<V> predicate) { final Predicate<View> conjunction = Predicates.and(Predicates.instanceOf(clazz), ViewPredicates.isVisible(), (Predicate<View>) predicate); final ImmutableList<View> path = actual.findChild(conjunction, ViewPredicates.isVisible()); Java6Assertions.assertThat(path)//ww w. ja v a2s . c o m .overridingErrorMessage( "Did not find view for which given predicate is true in view hierarchy:%n%s", actual.makeString(null)) .isNotNull(); return this; }
From source file:org.eclipse.sirius.diagram.ui.business.internal.query.RequestQuery.java
/** * Check if:/*from w ww . j a va2 s .c o m*/ * <UL> * <LI>all mappings of the creation tool of this request correspond to * BorderNode mapping,</LI> * <LI>or if all edit parts of the drop request is BorderNode edit part. * Warning the result is only available in case of drag'n'drop from diagram, * not from other view because in this case, the edit part is not * "real edit part" but a @link * {@link org.eclipse.sirius.diagram.ui.tools.internal.dnd.DragAndDropWrapper} * . The only solution in this case to know if it is a drop a element that * became bordered nodes is to call * {@link org.eclipse.sirius.diagram.ui.graphical.edit.internal.policies.validators.DragAndDropValidator#isConcerningOnlyBorderNodeFromView()} * .</LI> * </UL> * * @return true in case of request concerning bordered nodes, false * otherwise. */ public boolean isDropOrCreationOfBorderNode() { boolean isConcerningBorderNode = false; if (request instanceof CreateRequest) { CreateRequest createRequest = (CreateRequest) request; if (createRequest.getNewObject() instanceof NodeCreationDescriptionImpl) { isConcerningBorderNode = true; NodeCreationDescriptionImpl nodeCreationDescriptionImpl = (NodeCreationDescriptionImpl) createRequest .getNewObject(); for (NodeMapping nodeMapping : nodeCreationDescriptionImpl.getNodeMappings()) { if (!DescriptionPackage.eINSTANCE.getAbstractNodeMapping_BorderedNodeMappings() .equals(nodeMapping.eContainingFeature())) { isConcerningBorderNode = false; } } } } else if (RequestConstants.REQ_DROP.equals(request.getType())) { isConcerningBorderNode = !getEditParts().isEmpty() && Iterables.all(getEditParts(), Predicates.instanceOf(IBorderItemEditPart.class)); } return isConcerningBorderNode; }
From source file:org.eclipse.sirius.diagram.business.api.query.DDiagramElementQuery.java
/** * Tests whether the dDiagramElement is explicitly or indirectly folded. * //w ww . ja v a2 s. co m * @return <code>true</code> if the dDiagramElement is folded (explicitly or * indirectly). */ public boolean isFolded() { return Iterables.any(element.getGraphicalFilters(), Predicates .or(Predicates.instanceOf(FoldingPointFilter.class), Predicates.instanceOf(FoldingFilter.class))); }
From source file:com.facebook.litho.testing.viewtree.ViewTreeAssert.java
public <V extends View> ViewTreeAssert doesNotHaveVisible(final Class<V> clazz, final Predicate<V> predicate) { final Predicate<View> conjunction = Predicates.and(Predicates.instanceOf(clazz), ViewPredicates.isVisible(), (Predicate<View>) predicate); final ImmutableList<View> path = actual.findChild(conjunction, ViewPredicates.isVisible()); Java6Assertions.assertThat(path)// w ww . j av a2 s . c o m .overridingErrorMessage("Found a view for which given predicate is true in view hierarchy:%n%s", actual.makeString(null)) .isNull(); return this; }
From source file:com.facebook.swift.codec.metadata.ThriftStructMetadataBuilder.java
private void addMethod(Class<?> clazz, Method method, boolean allowReaders, boolean allowWriters) { checkArgument(method.isAnnotationPresent(ThriftField.class)); ThriftField annotation = method.getAnnotation(ThriftField.class); // verify parameters if (isValidateGetter(method)) { if (allowReaders) { MethodExtractor methodExtractor = new MethodExtractor(method, annotation); fields.add(methodExtractor); extractors.add(methodExtractor); } else {//from ww w .jav a2 s. co 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(method.getParameterAnnotations(), 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.required()) { metadataErrors.addError( "A method with annotated parameters can not be marked as required: %s.%s ", clazz.getName(), method.getName()); } } else { parameters = ImmutableList.of(new ParameterInjection(0, annotation, extractFieldName(method), method.getGenericParameterTypes()[0])); } 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:org.apache.impala.planner.HdfsPartitionPruner.java
/** * Evaluate an InPredicate filter on a partition column and return the ids of * the matching partitions.//from www.j a v a 2 s.c o 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 Set<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.apache.calcite.sql.SqlUtil.java
private static Iterator<SqlOperator> lookupSubjectRoutinesByName(SqlOperatorTable opTab, SqlIdentifier funcName, final SqlSyntax syntax, SqlFunctionCategory category) { final List<SqlOperator> sqlOperators = new ArrayList<>(); opTab.lookupOperatorOverloads(funcName, category, syntax, sqlOperators); switch (syntax) { case FUNCTION: return Iterators.filter(sqlOperators.iterator(), Predicates.instanceOf(SqlFunction.class)); default://w ww. j a v a2s . c o m return Iterators.filter(sqlOperators.iterator(), new PredicateImpl<SqlOperator>() { public boolean test(SqlOperator operator) { return operator.getSyntax() == syntax; } }); } }
From source file:org.obeonetwork.dsl.uml2.core.api.services.ActivityDiagramServices.java
/** * Get all the behaviors available in the semantic resources. * * @param eObj/*from w ww .ja v a2 s. com*/ * Semantic element * @return All the behaviors */ private List<EObject> getAllBehaviors(Element element) { final List<EObject> behaviors = Lists.newArrayList(); final List<org.eclipse.uml2.uml.Package> rootPkgs = getAllAvailableRootPackages(element); for (final org.eclipse.uml2.uml.Package pkg : rootPkgs) { Iterators.addAll(behaviors, Iterators.filter(pkg.eAllContents(), Predicates.instanceOf(Behavior.class))); } return behaviors; }
From source file:com.cloudera.impala.analysis.Expr.java
/** * Returns a clone of child with all NumericLiterals in it explicitly * cast to targetType./* www. j a v a 2 s .c o m*/ */ private Expr convertNumericLiteralsToFloat(Analyzer analyzer, Expr child, Type targetType) throws AnalysisException { if (!targetType.isFloatingPointType() && !targetType.isIntegerType()) return child; if (targetType.isIntegerType()) targetType = Type.DOUBLE; List<NumericLiteral> literals = Lists.newArrayList(); child.collectAll(Predicates.instanceOf(NumericLiteral.class), literals); ExprSubstitutionMap smap = new ExprSubstitutionMap(); for (NumericLiteral l : literals) { NumericLiteral castLiteral = (NumericLiteral) l.clone(); castLiteral.explicitlyCastToFloat(targetType); smap.put(l, castLiteral); } return child.substitute(smap, analyzer, false); }