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.tools.internal.commands.emf.PasteFromSiriusClipboardCommand.java
private void prepareClipboard() { // Initiate current domain clipboard from viewpoint multi session // clipboard//from ww w . j a va 2 s .c o m SiriusClipboardManager.getInstance().setDomainClipboard(domain); clipboard = domain.getClipboard(); // and filter DElements if (clipboard != null) { clipboard = Lists.newArrayList( Iterables.filter(clipboard, Predicates.not(Predicates.instanceOf(DSemanticDecorator.class)))); } // add to current domain clipboard domain.setClipboard(clipboard); }
From source file:com.palantir.common.base.BatchingVisitableView.java
public <U> BatchingVisitableView<T> filter(final Class<? extends U> type) { return filter(Predicates.instanceOf(type)); }
From source file:org.eclipse.sirius.tests.support.internal.helper.CrossReferenceAdapterDetector.java
/** * Check that the given Notifier does not have a CrossReferencerAdatper * CrossReferencerAdatper./*from ww w . jav a 2 s. co m*/ * * @param notifier * the notifier to check. * @return true if a CrossReferencerAdapter has been found. */ public static boolean hasCrossReferenceAdapter(Notifier notifier) { return Iterables.any(notifier.eAdapters(), Predicates.instanceOf(org.eclipse.gmf.runtime.emf.core.util.CrossReferenceAdapter.class)); }
From source file:io.usethesource.criterion.profiler.MemoryFootprintProfiler.java
/** * Run this code after a benchmark iteration finished * * @param benchmarkParams benchmark parameters used for current launch * @param iterationParams iteration parameters used for current launch * @param result iteration result/* www.j a v a 2s . co m*/ * @return profiler results */ @Override public Collection<? extends Result<ProfilerResult>> afterIteration(BenchmarkParams benchmarkParams, IterationParams iterationParams, IterationResult result) { try { final String benchmarkClassName = benchmarkToClassName(benchmarkParams.getBenchmark()); final Method factoryMethod = factoryMethod(benchmarkClassName); final JmhValue wrappedObject = (JmhValue) factoryMethod.invoke(null, initializeArguments(benchmarkParams)); final Object objectToMeasure = wrappedObject.unwrap(); final Predicate<Object> predicateDataStructureOverhead = Predicates .not(Predicates.instanceOf(JmhValue.class)); final Predicate<Object> predicateRetainedSize = Predicates.alwaysTrue(); final List<ProfilerResult> profilerResults = new ArrayList<>(); /** * Traverse object graph for measuring memory footprint (in bytes). */ long memoryInBytes = objectexplorer.MemoryMeasurer.measureBytes(objectToMeasure, predicateDataStructureOverhead); // NOTE: non-standard constructor for passing ResultRole.PRIMARY final ProfilerResult memoryResult = new ProfilerResult(ResultRole.PRIMARY, "memory", memoryInBytes, UNIT_BYTES, POLICY); // hack: substitute results result.resetResults(); result.addResult(memoryResult); // /** // * Traverse object graph for measuring field statistics. // */ // final Footprint statistic = objectexplorer.ObjectGraphMeasurer // .measure(objectToMeasure, predicateDataStructureOverhead); // // final ProfilerResult objectsResult = // new ProfilerResult("objects", statistic.getObjects(), UNIT_COUNT, POLICY); // profilerResults.add(objectsResult); // // final ProfilerResult referencesResult = // new ProfilerResult("references", statistic.getReferences(), UNIT_COUNT, POLICY); // profilerResults.add(referencesResult); // // final ProfilerResult primitivesResult = // new ProfilerResult("primitives", statistic.getPrimitives().size(), UNIT_COUNT, POLICY); // profilerResults.add(primitivesResult); return profilerResults; } catch (Exception e) { e.printStackTrace(); return Arrays.asList(); } }
From source file:org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement.java
@SuppressWarnings("unchecked") protected final <S extends DeclaredStatement<?>> Collection<? extends S> allDeclared(final Class<S> type) { return Collection.class.cast(Collections2.filter(substatements, Predicates.instanceOf(type))); }
From source file:org.onos.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement.java
@SuppressWarnings("unchecked") protected final <S extends DeclaredStatement<?>> Collection<? extends S> allDeclared(Class<S> type) { return Collection.class.cast(Collections2.filter(substatements, Predicates.instanceOf(type))); }
From source file:brooklyn.entity.nosql.mongodb.sharding.CoLocatedMongoDBRouterImpl.java
@Override protected void doStart(Collection<? extends Location> locations) { // TODO Changed to create the router child after init as a workaround. // When we use `mongo-sharded.yaml`, and we call // `getConfig(CoLocatedMongoDBRouter.SHARDED_DEPLOYMENT)`, // the value is `$brooklyn:component("shardeddeployment")`. // To look up the component, it tries to do `entity().getApplication()` to // search the entities for one with the correct id. However if being done // during `init()`, then this (which is returned by `entity()`) has not had its parent // set, so `entity().getApplication()` returns null. ///*ww w . ja v a 2s .c om*/ // We should move this code back to `init()` once we have a solution for that. // We can also remove the call to Entities.manage() once this is in init() again. MongoDBRouter router = addChild( EntitySpec.create(MongoDBRouter.class).configure(MongoDBRouter.CONFIG_SERVERS, DependentConfiguration.attributeWhenReady( getConfig(CoLocatedMongoDBRouter.SHARDED_DEPLOYMENT), MongoDBConfigServerCluster.CONFIG_SERVER_ADDRESSES))); Entities.manage(router); setAttribute(ROUTER, (MongoDBRouter) Iterables.tryFind(getChildren(), Predicates.instanceOf(MongoDBRouter.class)).get()); addEnricher(Enrichers.builder().propagating(MongoDBRouter.PORT).from(router).build()); super.doStart(locations); setAttribute(Startable.SERVICE_UP, true); }
From source file:org.eclipse.emf.compare.uml2.internal.provider.profile.StereotypeAttributeChangeProfileSupportItemProvider.java
/** * Retrieves the {@link AttributeChange} which is refined by the {@link StereotypeAttributeChange}. * /* w w w . ja va 2 s .c o m*/ * @param diff * Input object. . * @return an {@link AttributeChange} if the input is a {@link StereotypeAttributeChange} which is refined * by an {@link AttributeChange} or <code>null</code> otherwise. */ private AttributeChange getAttributeChange(Object diff) { AttributeChange attributeChange = null; if (diff instanceof StereotypeAttributeChange) { StereotypeAttributeChange stereotypeAttributeChange = (StereotypeAttributeChange) diff; Optional<Diff> element = Iterables.tryFind(stereotypeAttributeChange.getRefinedBy(), Predicates.instanceOf(AttributeChange.class)); if (element.isPresent()) { attributeChange = (AttributeChange) element.get(); } } return attributeChange; }
From source file:brooklyn.entity.nosql.etcd.EtcdClusterImpl.java
@Override public void start(Collection<? extends Location> locations) { ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING); connectSensors();//w ww . jav a2 s . c o m 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()) { setAttribute(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.eclipse.sirius.diagram.sequence.ui.tool.internal.edit.validator.DefaultMessageCreationValidator.java
private boolean checkTargetLifelineNotExplicitlyCreatedAtUpperTime() { boolean valid = true; SequenceDiagram sequenceDiagram = sequenceElementSource.getDiagram(); SequenceDiagramQuery sequenceDiagramQuery = new SequenceDiagramQuery(sequenceDiagram); for (ISequenceEvent sequenceEvent : Iterables.filter( sequenceDiagramQuery.getAllSequenceEventsUpperThan(firstClickLocation.y), Predicates.not(Predicates.instanceOf(Lifeline.class)))) { if (isCreateMessageFor(sequenceEvent, sequenceElementTarget.getLifeline().get().getInstanceRole())) { valid = false;/* w w w .j a v a 2s . co m*/ break; } } return valid; }