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.business.internal.metamodel.spec.DNodeListSpec.java
/** * {@inheritDoc}/*from w ww . j av a2s . c om*/ * * @see org.eclipse.sirius.viewpoint.impl.DDiagramElementContainerImpl#getNodes() */ @Override public EList<DNode> getNodes() { final Collection<AbstractDNode> result = DDiagramElementContainerSpecOperations.getNodes(this); Collection<DNode> dNodeResult = new ArrayList<DNode>(); for (AbstractDNode dNode : Collections2.filter(result, Predicates.instanceOf(DNode.class))) { dNodeResult.add((DNode) dNode); } return new EcoreEList.UnmodifiableEList<DNode>(eInternalContainer(), DiagramPackage.eINSTANCE.getDDiagramElementContainer_Nodes(), dNodeResult.size(), dNodeResult.toArray()); }
From source file:eu.stratosphere.sopremo.expressions.EvaluationExpression.java
@SuppressWarnings("unchecked") public <T extends EvaluationExpression> List<T> findAll(final Class<T> evaluableClass) { return (List<T>) this.findAll(Predicates.instanceOf(evaluableClass)); }
From source file:org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveStatementBase.java
protected final <S extends SchemaNode> S firstSchemaNode(final Class<S> type) { final Optional<? extends EffectiveStatement<?, ?>> possible = Iterables.tryFind(substatements, Predicates.instanceOf(type)); return possible.isPresent() ? type.cast(possible.get()) : null; }
From source file:gg.uhc.uhc.modules.ModuleRegistry.java
public <T extends Module> Optional<T> get(Class<T> klass) { return (Optional<T>) Iterables.tryFind(modules.values(), Predicates.instanceOf(klass)); }
From source file:brooklyn.config.render.RendererHints.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private static <T extends Hint> Set<T> _getHintsFor(Object element, Class<T> optionalHintSuperClass) { Set<Hint<?>> found = ImmutableSet.copyOf(registry.get(element)); if (found.isEmpty() && element instanceof Class && !Object.class.equals(element)) { // try superclasses of the element; this seems overkill for the main use case, Entity; // (other classes registered are typically final) found = (Set<Hint<?>>) _getHintsFor(((Class) element).getSuperclass(), optionalHintSuperClass); if (found.isEmpty()) { for (Class<?> parentInterface : ((Class) element).getInterfaces()) { found = (Set<Hint<?>>) _getHintsFor(parentInterface, optionalHintSuperClass); if (!found.isEmpty()) break; }/*from w w w . j a v a 2s . com*/ } } if (optionalHintSuperClass != null) { return (Set<T>) Sets.filter(found, Predicates.instanceOf(optionalHintSuperClass)); } else { return (Set<T>) found; } }
From source file:org.onos.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveStatementBase.java
protected final <S extends SchemaNode> S firstSchemaNode(Class<S> type) { S result = null;//from ww w .j a va 2 s . c o m try { result = type.cast(Iterables.find(substatements, Predicates.instanceOf(type))); } catch (NoSuchElementException e) { result = null; } return result; }
From source file:brooklyn.entity.waratek.cloudvm.WaratekInfrastructureImpl.java
@Override public void init() { int initialSize = getConfig(JVM_CLUSTER_MIN_SIZE); EntitySpec<?> jvmSpec = EntitySpec.create(getConfig(JVM_SPEC)) .configure(JavaVirtualMachine.WARATEK_INFRASTRUCTURE, this).configure(UsesJmx.USE_JMX, Boolean.TRUE) .configure(UsesJmx.JMX_AGENT_MODE, JmxAgentModes.JMX_RMI_CUSTOM_AGENT) .configure(SoftwareProcess.CHILDREN_STARTABLE_MODE, ChildStartableMode.BACKGROUND_LATE); virtualMachines = addChild(/*from www .j a v a 2s .c om*/ EntitySpec.create(DynamicCluster.class).configure(Cluster.INITIAL_SIZE, initialSize) .configure(DynamicCluster.QUARANTINE_FAILED_ENTITIES, true) .configure(DynamicCluster.MEMBER_SPEC, jvmSpec).displayName("Java Virtual Machines")); fabric = addChild(EntitySpec.create(DynamicGroup.class) .configure(DynamicGroup.ENTITY_FILTER, Predicates.instanceOf(JavaVirtualContainer.class)) .displayName("All Java Virtual Containers")); applications = addChild(EntitySpec.create(DynamicMultiGroup.class) .configure(DynamicMultiGroup.ENTITY_FILTER, sameInfrastructure) .configure(DynamicMultiGroup.RESCAN_INTERVAL, 15L) .configure(DynamicMultiGroup.BUCKET_SPEC, EntitySpec.create(WaratekApplicationGroup.class)) .configure(DynamicMultiGroup.BUCKET_FUNCTION, new Function<Entity, String>() { @Override public String apply(@Nullable Entity input) { return input.getApplication().getDisplayName(); } }).displayName("Waratek Java Applications")); entities = addChild(EntitySpec.create(DynamicMultiGroup.class) .configure(DynamicMultiGroup.ENTITY_FILTER, sameInfrastructure) .configure(DynamicMultiGroup.RESCAN_INTERVAL, 15L) .configure(DynamicMultiGroup.BUCKET_SPEC, EntitySpec.create(WaratekApplicationGroup.class)) .configure(DynamicMultiGroup.BUCKET_FUNCTION, new Function<Entity, String>() { @Override public String apply(@Nullable Entity input) { return input.getEntityType().getName(); } }).displayName("Waratek Java Entities")); if (Entities.isManaged(this)) { Entities.manage(virtualMachines); Entities.manage(fabric); Entities.manage(applications); Entities.manage(entities); } virtualMachines.addEnricher(Enrichers.builder().aggregating(WaratekAttributes.TOTAL_HEAP_MEMORY) .computingSum().fromMembers().publishing(WaratekAttributes.TOTAL_HEAP_MEMORY).build()); virtualMachines.addEnricher(Enrichers.builder() .aggregating(WaratekAttributes.HEAP_MEMORY_DELTA_PER_SECOND_IN_WINDOW).computingSum().fromMembers() .publishing(WaratekAttributes.HEAP_MEMORY_DELTA_PER_SECOND_IN_WINDOW).build()); virtualMachines.addEnricher(Enrichers.builder().aggregating(WaratekAttributes.AVERAGE_CPU_USAGE) .computingAverage().fromMembers().publishing(WaratekAttributes.AVERAGE_CPU_USAGE).build()); virtualMachines.addEnricher(Enrichers.builder().aggregating(JVC_COUNT).computingSum().fromMembers() .publishing(JVC_COUNT).build()); virtualMachines.addEnricher(Enrichers.builder().aggregating(JavaVirtualMachine.STOPPED_JVCS).computingSum() .fromMembers().publishing(STOPPED_JVCS).build()); virtualMachines.addEnricher(Enrichers.builder().aggregating(JavaVirtualMachine.RUNNING_JVCS).computingSum() .fromMembers().publishing(RUNNING_JVCS).build()); virtualMachines.addEnricher(Enrichers.builder().aggregating(JavaVirtualMachine.PAUSED_JVCS).computingSum() .fromMembers().publishing(PAUSED_JVCS).build()); addEnricher(Enrichers.builder() .propagating(WaratekAttributes.TOTAL_HEAP_MEMORY, WaratekAttributes.AVERAGE_CPU_USAGE, WaratekAttributes.HEAP_MEMORY_DELTA_PER_SECOND_IN_WINDOW, JVC_COUNT, STOPPED_JVCS, RUNNING_JVCS, PAUSED_JVCS) .from(virtualMachines).build()); addEnricher(Enrichers.builder().propagating(ImmutableMap.of(DynamicCluster.GROUP_SIZE, JVM_COUNT)) .from(virtualMachines).build()); subscribeToMembers(virtualMachines, SERVICE_UP, new SensorEventListener<Boolean>() { @Override public void onEvent(SensorEvent<Boolean> event) { setAttribute(SERVICE_UP, calculateServiceUp()); } }); }
From source file:org.caleydo.view.tourguide.internal.compute.AScoreJob.java
protected final static <A, B extends A> Pair<Collection<A>, Collection<B>> partition(Collection<A> in, final Class<B> with) { Collection<B> bs = Lists.newArrayList( Iterables.transform(Iterables.filter(in, Predicates.instanceOf(with)), new Function<A, B>() { @Override//from w w w.j a v a 2 s . c om public B apply(A a) { return with.cast(a); } })); Collection<A> as = Collections2.filter(in, Predicates.not(Predicates.instanceOf(with))); return Pair.make(as, bs); }
From source file:eu.stratosphere.sopremo.expressions.BatchAggregationExpression.java
public EvaluationExpression add(final ExpressionFunction aggregation, final EvaluationExpression preprocessing) { return aggregation.inline(preprocessing).replace(Predicates.instanceOf(AggregationExpression.class), new Function<EvaluationExpression, EvaluationExpression>() { @Override//w w w. j a v a2 s .co m public EvaluationExpression apply(final EvaluationExpression expression) { final AggregationExpression ae = (AggregationExpression) expression; return BatchAggregationExpression.this.add(ae.getAggregation(), ExpressionUtil.replaceArrayProjections(ae.getInputExpression())); } }); }
From source file:org.eclipse.sirius.diagram.editor.properties.sections.tool.createview.CreateViewMappingPropertySection.java
/** * Fetches the list of available values for the feature. * //from w w w . ja v a 2 s .c o m * @return The list of available values for the feature. */ protected List<?> getChoiceOfValues() { List<?> values = Collections.emptyList(); List<IItemPropertyDescriptor> propertyDescriptors = getDescriptors(); for (Iterator<IItemPropertyDescriptor> iterator = propertyDescriptors.iterator(); iterator.hasNext();) { IItemPropertyDescriptor propertyDescriptor = iterator.next(); if (((EStructuralFeature) propertyDescriptor.getFeature(eObject)) == getFeature()) values = new ArrayList<Object>(propertyDescriptor.getChoiceOfValues(eObject)); } // Start of user code choice of values if (!values.isEmpty()) { Predicate<Object> predicate = Predicates.or(Predicates.instanceOf(EdgeMapping.class), Predicates.instanceOf(EdgeMappingImport.class)); if (eObject instanceof CreateEdgeView) { values = Lists.newArrayList(Iterables.filter(values, predicate)); } else if (eObject instanceof CreateView) { values = Lists.newArrayList(Iterables.filter(values, Predicates.not(predicate))); } } // End of user code choice of values return values; }