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.buildship.ui.util.nodeselection.NodeSelection.java
/** * Checks whether all nodes are of the given type. * * @param expectedType the expected type of the nodes * @return {@code true} if all nodes match the type *//* www . java 2 s . c om*/ public boolean hasAllNodesOfType(Class<?> expectedType) { return allMatch(Predicates.instanceOf(expectedType)); }
From source file:org.eclipse.viatra.query.patternlanguage.emf.ui.contentassist.PatternImporter.java
@Override public void apply(final IDocument document, final ConfigurableCompletionProposal proposal) throws BadLocationException { if (document instanceof IXtextDocument) { IXtextDocument xtextDocument = (IXtextDocument) document; targetPattern = getTargetPattern(proposal); if (targetPattern == null || Strings.isNullOrEmpty(targetPattern.getName())) return; final String targetPackage = PatternLanguageHelper.getPackageName(targetPattern); importStatus = ((IXtextDocument) document).readOnly(new IUnitOfWork<ImportState, XtextResource>() { @Override/*from ww w . j av a 2s. c o m*/ public ImportState exec(XtextResource state) throws Exception { final PatternModel model = (PatternModel) Iterators.find(state.getAllContents(), Predicates.instanceOf(PatternModel.class)); if (Objects.equals(targetPackage, model.getPackageName())) { return ImportState.SAMEPACKAGE; } final VQLImportSection importSection = model.getImportPackages(); PatternImport relatedImport = importSection.getPatternImport().stream() .filter(decl -> targetPattern.equals(decl.getPattern()) || targetPattern.getName().equals(decl.getPattern().getName())) .findFirst().orElse(null); if (relatedImport == null) { return ImportState.NONE; } // Checking whether found pattern definition equals to different pattern if (targetPattern.equals(relatedImport.getPattern())) { return ImportState.FOUND; } else { return ImportState.CONFLICTING; } } }); String replacementString = getActualReplacementString(proposal) + "();"; ReplaceEdit edit = new ReplaceEdit(proposal.getReplacementOffset(), proposal.getReplacementLength(), replacementString); edit.apply(document); //+2 is used to put the cursor inside the parentheses int cursorOffset = getActualReplacementString(proposal).length() + 2; if (importStatus == ImportState.NONE) { xtextDocument.modify(new Void<XtextResource>() { @Override public void process(XtextResource state) throws Exception { VQLImportSection importSection = (VQLImportSection) Iterators.find(state.getAllContents(), Predicates.instanceOf(VQLImportSection.class), null); if (importSection.getImportDeclarations().size() + importSection.getPackageImport().size() + importSection.getPatternImport().size() == 0) { //Empty import sections need to be replaced to generate white space after the package declaration VQLImportSection newSection = PatternLanguageFactory.eINSTANCE.createVQLImportSection(); ((PatternModel) importSection.eContainer()).setImportPackages(newSection); importSection = newSection; } PatternImport newImport = PatternLanguageFactory.eINSTANCE.createPatternImport(); newImport.setPattern(targetPattern); importSection.getPatternImport().add(newImport); } }); //Two new lines + "import " + pattern fqn cursorOffset += 2 + 7 + PatternLanguageHelper.getFullyQualifiedName(targetPattern).length(); } proposal.setCursorPosition(cursorOffset); } }
From source file:com.github.licanhua.test.framework.base.CustomElementHelper.java
private static boolean isRootCauseOfException(Throwable e, Class clazz) { return FluentIterable.from(Throwables.getCausalChain(e)).filter(Predicates.instanceOf(clazz)).first() .isPresent();// ww w . ja v a 2s. co m }
From source file:org.apache.brooklyn.entity.nosql.riak.RiakClusterImpl.java
@Override protected void doStart() { super.doStart(); connectSensors();/*from w w w. j a v a2 s . c o m*/ try { Duration delay = getConfig(DELAY_BEFORE_ADVERTISING_CLUSTER); Tasks.setBlockingDetails("Sleeping for " + delay + " before advertising cluster available"); Time.sleep(delay); } finally { Tasks.resetBlockingDetails(); } //FIXME: add a quorum to tolerate failed nodes before setting on fire. @SuppressWarnings("unchecked") Optional<Entity> anyNode = Iterables.tryFind(getMembers(), Predicates.and(Predicates.instanceOf(RiakNode.class), EntityPredicates.attributeEqualTo(RiakNode.RIAK_NODE_HAS_JOINED_CLUSTER, true), EntityPredicates.attributeEqualTo(RiakNode.SERVICE_UP, true))); if (anyNode.isPresent()) { sensors().set(IS_CLUSTER_INIT, true); } else { log.warn("No Riak Nodes are found on the cluster: {}. Initialization Failed", getId()); ServiceStateLogic.setExpectedState(this, Lifecycle.ON_FIRE); } }
From source file:org.eclipse.sirius.diagram.sequence.business.internal.layout.EventEndToPositionFunction.java
private ISequenceEvent getSafeEvent(Collection<ISequenceEvent> ises) { ISequenceEvent ise = null;/*w ww . j a v a 2 s.c om*/ Predicate<Object> safe = Predicates.or(Predicates.instanceOf(AbstractNodeEvent.class), Predicates.instanceOf(AbstractFrame.class)); Collection<? extends ISequenceEvent> safeEvents = Lists.newArrayList(Iterables.filter(ises, safe)); if (!safeEvents.isEmpty()) { ise = safeEvents.iterator().next(); } else if (Iterables.size(Iterables.filter(ises, Operand.class)) == 2) { ise = getSafeOperandEnd(ises); } else { ise = ises.iterator().next(); } return ise; }
From source file:org.eclipse.sirius.diagram.sequence.ui.tool.internal.edit.validator.DefaultMessageCreationValidator.java
private boolean checkTargetLifelineNotExplicitlyDestroyedAtLowerTime() { boolean valid = true; SequenceDiagram sequenceDiagram = sequenceElementSource.getDiagram(); SequenceDiagramQuery sequenceDiagramQuery = new SequenceDiagramQuery(sequenceDiagram); for (ISequenceEvent sequenceEvent : Iterables.filter( sequenceDiagramQuery.getAllSequenceEventsLowerThan(firstClickLocation.y), Predicates.not(Predicates.instanceOf(Lifeline.class)))) { if (isDestroyMessageFor(sequenceEvent, sequenceElementTarget.getLifeline().get().getInstanceRole())) { valid = false;/*from w w w .ja v a 2 s. c o m*/ break; } } return valid; }
From source file:com.facebook.litho.testing.viewtree.ViewPredicates.java
@SuppressWarnings("unchecked") public static Predicate<View> isClass(final Class<? extends View> clazz) { return (Predicate<View>) (Predicate<?>) Predicates.instanceOf(clazz); }
From source file:eu.interedition.text.xml.ConverterBuilder.java
public Converter build() { final List<StreamFilter> filters = Lists.newLinkedList(); if (nodePathTracker != null) { filters.add(nodePathTracker);/*from w ww .j a v a 2 s . c o m*/ } Iterable<ConversionFilter> textStreamFilters = Iterables.filter(this.filters, ConversionFilter.class); Iterables.addAll(filters, Iterables.filter(textStreamFilters, ConversionFilter.BEFORE_TEXT_GENERATION)); if (offsetMapper != null) { filters.add(offsetMapper); } if (whitespaceCompressor != null) { filters.add(whitespaceCompressor); } Iterables.addAll(filters, Iterables.filter(textStreamFilters, Predicates.not(ConversionFilter.BEFORE_TEXT_GENERATION))); Iterables.addAll(filters, Iterables.filter(this.filters, Predicates.not(Predicates.instanceOf(ConversionFilter.class)))); return new Converter(whitespaceCompressor, offsetMapper, namespaceMapping, filters).add(listeners); }
From source file:org.apache.brooklyn.entity.nosql.etcd.EtcdClusterImpl.java
@Override public void start(Collection<? extends Location> locs) { addLocations(locs);/*from w w w . j a v a2 s . c om*/ List<Location> locations = MutableList.copyOf(Locations.getLocationsCheckingAncestors(locs, this)); ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING); connectSensors(); super.start(locations); Optional<Entity> anyNode = Iterables.tryFind(getMembers(), Predicates.and(Predicates.instanceOf(EtcdNode.class), EntityPredicates.attributeEqualTo(EtcdNode.ETCD_NODE_HAS_JOINED_CLUSTER, true), EntityPredicates.attributeEqualTo(Startable.SERVICE_UP, true))); if (config().get(Cluster.INITIAL_SIZE) == 0 || anyNode.isPresent()) { sensors().set(Startable.SERVICE_UP, true); ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING); } else { log.warn("No Etcd nodes are found on the cluster: {}. Initialization Failed", getId()); ServiceStateLogic.setExpectedState(this, Lifecycle.ON_FIRE); } }
From source file:org.sosy_lab.cpachecker.cfa.postprocessing.function.CFASimplifier.java
/** * Search all branching points in a CFA in post order * (any (transitive) predecessor of a node comes before that node in the result). * @param root The entry point of the CFA. * @return A queue of CFANodes that are branching points, in post order. *//*from w w w . j a va 2 s . co m*/ private static Deque<CFANode> findBranchingPoints(final CFANode root) { // The order is important: branching points at the beginning need to come first, // (similar to reverse post order). // Thus we iterate through the CFA and visit each sucessor only // after all its predecessors have been handled. final Deque<CFANode> branchingPoints = new ArrayDeque<>(); final Set<CFANode> visitedNodes = new HashSet<>(); final Deque<CFANode> waitlist = new ArrayDeque<>(); waitlist.push(root); while (!waitlist.isEmpty()) { CFANode current = waitlist.pollLast(); if (visitedNodes.contains(current)) { // loop in CFA continue; } if (visitedNodes.containsAll(predecessorsOf(current).toList())) { visitedNodes.add(current); if (current.getNumLeavingEdges() > 1) { if (current.getNumLeavingEdges() > 2) { throw new AssertionError("More than 2 leaving edges on node " + current + " in function " + current.getFunctionName()); } assert CFAUtils.allLeavingEdges(current).allMatch(Predicates.instanceOf(AssumeEdge.class)); branchingPoints.addLast(current); } addAll(waitlist, successorsOf(current)); } } return branchingPoints; }