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.api.query.NodeQuery.java
/** * Retrieves the node dimension before collapse from {@link CollapseFilter}. * In case of the collapse filter width and height attributes are equal to * zero, the default dimension is returned. * /* w w w . jav a2s .co m*/ * @return the original dimension. */ public Dimension getOriginalDimensionBeforeCollapse() { EObject element = node.getElement(); Dimension dim = new Dimension(0, 0); if (element instanceof DDiagramElement) { CollapseFilter filter = (CollapseFilter) Iterables .getFirst(Iterables.filter(((DDiagramElement) element).getGraphicalFilters(), Predicates.instanceOf(CollapseFilter.class)), null); if (filter == null || filter.getWidth() == 0 || filter.getHeight() == 0) { dim.setSize(getDefaultDim((DDiagramElement) element)); } else { dim.setSize(new Dimension(filter.getWidth(), filter.getHeight())); } } return dim; }
From source file:org.eclipse.sirius.diagram.business.api.query.DDiagramElementQuery.java
/** * Check if this {@link DDiagramElement} is directly hidden. * /*from w w w. j a v a 2 s . co m*/ * @return true if the given element is hidden. */ public boolean isHidden() { return Iterables.any(element.getGraphicalFilters(), Predicates.instanceOf(HideFilter.class)); }
From source file:org.dyndns.jkiddo.dmp.chunks.ContainerChunk.java
@SuppressWarnings("unchecked") protected <T extends Chunk> T getSingleChunk(final Class<T> clazz) { final Iterable<Chunk> iterables = Iterables.filter(this.collection, Predicates.instanceOf(clazz)); if (Iterables.size(iterables) == 1) { return (T) iterables.iterator().next(); }// w w w. j a v a 2s . c o m if (Iterables.size(iterables) == 0) { return null; } throw new NoSuchElementException("Multiple chunks of type " + clazz + " was found"); }
From source file:org.onos.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveStatementBase.java
protected final <S extends EffectiveStatement<?, ?>> S firstEffective(Class<S> type) { S result = null;/*from www . ja v a2s . c o m*/ try { result = type.cast(Iterables.find(substatements, Predicates.instanceOf(type))); } catch (NoSuchElementException e) { result = null; } return result; }
From source file:org.eclipse.buildship.ui.wizard.project.WorkingSetConfigurationWidget.java
private Label findWorkingSetsLabel(Composite parent) { return (Label) findControl(parent, Predicates.instanceOf(Label.class)); }
From source file:org.apache.brooklyn.entity.nosql.couchbase.CouchbaseSyncGatewaySshDriver.java
@Override public void launch() { Entity cbNode = entity.getConfig(CouchbaseSyncGateway.COUCHBASE_SERVER); Entities.waitForServiceUp(cbNode, Duration.ONE_HOUR); DependentConfiguration.waitInTaskForAttributeReady(cbNode, CouchbaseCluster.IS_CLUSTER_INITIALIZED, Predicates.equalTo(true));//from w w w. j a v a2 s .c o m // Even once the bucket has published its API URL, it can still take a couple of seconds for it to become available Time.sleep(10 * 1000); if (cbNode instanceof CouchbaseCluster) { // in_cluster now applies even to a node in a cluster of size 1 Optional<Entity> cbClusterNode = Iterables.tryFind(cbNode.getAttribute(CouchbaseCluster.GROUP_MEMBERS), Predicates.and(Predicates.instanceOf(CouchbaseNode.class), EntityPredicates.attributeEqualTo(CouchbaseNode.IS_IN_CLUSTER, Boolean.TRUE))); if (!cbClusterNode.isPresent()) { throw new IllegalArgumentException( format("The cluster %s does not contain any suitable Couchbase nodes to connect to..", cbNode.getId())); } cbNode = cbClusterNode.get(); } String hostname = cbNode.getAttribute(CouchbaseNode.HOSTNAME); String webPort = cbNode.getAttribute(CouchbaseNode.COUCHBASE_WEB_ADMIN_PORT).toString(); String username = cbNode.getConfig(CouchbaseNode.COUCHBASE_ADMIN_USERNAME); String password = cbNode.getConfig(CouchbaseNode.COUCHBASE_ADMIN_PASSWORD); String bucketName = entity.getConfig(CouchbaseSyncGateway.COUCHBASE_SERVER_BUCKET); String pool = entity.getConfig(CouchbaseSyncGateway.COUCHBASE_SERVER_POOL); String pretty = entity.getConfig(CouchbaseSyncGateway.PRETTY) ? "-pretty" : ""; String verbose = entity.getConfig(CouchbaseSyncGateway.VERBOSE) ? "-verbose" : ""; String adminRestApiPort = entity.getConfig(CouchbaseSyncGateway.ADMIN_REST_API_PORT).iterator().next() .toString(); String syncRestApiPort = entity.getConfig(CouchbaseSyncGateway.SYNC_REST_API_PORT).iterator().next() .toString(); String serverWebAdminUrl = format("http://%s:%s@%s:%s", username, password, hostname, webPort); String options = format( "-url %s -bucket %s -adminInterface 0.0.0.0:%s -interface 0.0.0.0:%s -pool %s %s %s", serverWebAdminUrl, bucketName, adminRestApiPort, syncRestApiPort, pool, pretty, verbose); newScript(ImmutableMap.of("usePidFile", true), LAUNCHING).body .append(format("/opt/couchbase-sync-gateway/bin/sync_gateway %s ", options) + "> out.log 2> err.log < /dev/null &") .failOnNonZeroResultCode().execute(); }
From source file:dom.multimap.DominatorsSetMultimap_Default_Instrumented.java
public SetMultimap.Immutable<IConstructor, IConstructor> calculateDominators(Set.Immutable<ITuple> graph) { // long totalNrOfUniqueKeys = 0; // long totalNrOfTuple = 0; // long unique = 0; // long tuples = 0; // long one2one = 0; IConstructor n0 = getTop(graph);/*w w w . j a v a2 s . com*/ Set.Immutable<IConstructor> nodes = carrier(graph); SetMultimap.Immutable<IConstructor, IConstructor> preds = toMultimap(project(graph, 1, 0)); { Predicate<Object> predicate = Predicates.not(Predicates.instanceOf(IValue.class)); JmhCfgDominatorBenchmarks.memoryInBytes_multimap += objectexplorer.MemoryMeasurer.measureBytes(preds, predicate); // Footprint memoryFootprint_multimap = objectexplorer.ObjectGraphMeasurer.measure(preds, // predicate); Object mapWithNestedSets = toMap(project(graph, 1, 0)); JmhCfgDominatorBenchmarks.memoryInBytes_mapWithNestedSets += objectexplorer.MemoryMeasurer .measureBytes(mapWithNestedSets, predicate); // Footprint memoryFootprint_mapWithNestedSets = // objectexplorer.ObjectGraphMeasurer.measure(mapWithNestedSets, predicate); } Iterator<Entry<IConstructor, Object>> it = preds.nativeEntryIterator(); while (it.hasNext()) { Entry<IConstructor, Object> tuple = it.next(); Object singletonOrSet = tuple.getValue(); if (singletonOrSet instanceof Set.Immutable) { JmhCfgDominatorBenchmarks.unique++; JmhCfgDominatorBenchmarks.tuples += ((Set.Immutable) singletonOrSet).size(); } else { JmhCfgDominatorBenchmarks.unique++; JmhCfgDominatorBenchmarks.tuples++; JmhCfgDominatorBenchmarks.tuples_one2one++; } } SetMultimap.Transient<IConstructor, IConstructor> w = TrieSetMultimap_HHAMT.transientOf(); w.__insert(n0, n0); // JmhCfgDominatorBenchmarks.unique++; // JmhCfgDominatorBenchmarks.tuples++; // JmhCfgDominatorBenchmarks.one2one++; for (IConstructor n : nodes.__remove(n0)) { w.__put(n, nodes); // TODO: implement method to put a whole set at once! // JmhCfgDominatorBenchmarks.unique++; // JmhCfgDominatorBenchmarks.tuples+=nodes.size(); } SetMultimap.Immutable<IConstructor, IConstructor> dom = w.freeze(); SetMultimap.Immutable<IConstructor, IConstructor> prev = TrieSetMultimap_HHAMT.of(); /* * solve (dom) for (n <- nodes) dom[n] = {n} + intersect({dom[p] | p <- preds[n]?{}}); */ while (!prev.equals(dom)) { prev = dom; // System.out.println(prev.size()); SetMultimap.Transient<IConstructor, IConstructor> newDom = TrieSetMultimap_HHAMT.transientOf(); for (IConstructor n : nodes) { Set.Immutable ps = preds.get(n); if (ps == null) { ps = EMPTY; } // System.out.println(" ps: " + ps.size()); Set.Immutable<Set.Immutable<IConstructor>> sos = setofdomsets(dom, ps); // System.out.println(" sos: " + sos.size()); Set.Immutable<IConstructor> intersected = intersect(sos); // System.out.println(" intersected: " + intersected.size()); if (!intersected.isEmpty()) { Set.Immutable<IConstructor> newValue = union(intersected, Immutable.of(n)); newDom.__put(n, newValue); // TODO: implement method to put a whole set at once! // JmhCfgDominatorBenchmarks.unique++; // JmhCfgDominatorBenchmarks.tuples+=newValue.size(); } else { newDom.__insert(n, n); // TODO: implement method to put a // whole set at once! // JmhCfgDominatorBenchmarks.unique++; // JmhCfgDominatorBenchmarks.tuples++; // JmhCfgDominatorBenchmarks.one2one++; } } dom = newDom.freeze(); // return dom; // TODO: remove } // System.out.println("unique:" + unique); // System.out.println("tuples:" + tuples); // System.out.println("one2one:" + one2one); // // System.out.println("ratio:" + tuples / unique); return dom; }
From source file:org.eclipse.incquery.patternlanguage.emf.ui.quickfix.EMFPatternLanguageQuickfixProvider.java
@Fix(EMFIssueCodes.MISSING_PACKAGE_IMPORT) public void addMissingPackageImport(final Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Add missing import", "Add missing import", null, new IModification() { @Override/*from w ww. j ava 2 s .c o m*/ public void apply(IModificationContext context) throws BadLocationException { final IXtextDocument document = context.getXtextDocument(); Integer offset = document.readOnly(new IUnitOfWork<Integer, XtextResource>() { @Override public Integer exec(XtextResource state) { final XImportSection importSection = (XImportSection) Iterators.find(state.getAllContents(), Predicates.instanceOf(XImportSection.class), null); final ICompositeNode node = NodeModelUtils.getNode(importSection); return Integer.valueOf(node.getTotalEndOffset()); } }); if (offset != null) { StringBuilder sb = new StringBuilder(); sb.append("\n"); sb.append("import \""); sb.append(issue.getData()[0]); sb.append("\""); document.replace(offset, 0, sb.toString()); } } }); }
From source file:org.apache.brooklyn.core.location.dynamic.clocker.StubInfrastructureImpl.java
@Override public void init() { super.init(); ConfigToAttributes.apply(this); EntitySpec<?> dockerHostSpec = EntitySpec.create(StubHost.class) .configure(StubHost.DOCKER_INFRASTRUCTURE, this).configure(SoftwareProcess.CHILDREN_STARTABLE_MODE, SoftwareProcess.ChildStartableMode.BACKGROUND_LATE); DynamicCluster hosts = addChild(EntitySpec.create(DynamicCluster.class) .configure(Cluster.INITIAL_SIZE, config().get(DOCKER_HOST_CLUSTER_MIN_SIZE)) .configure(DynamicCluster.QUARANTINE_FAILED_ENTITIES, true) .configure(DynamicCluster.MEMBER_SPEC, dockerHostSpec) .configure(DynamicCluster.RUNNING_QUORUM_CHECK, QuorumChecks.atLeastOneUnlessEmpty()) .configure(DynamicCluster.UP_QUORUM_CHECK, QuorumChecks.atLeastOneUnlessEmpty()) .displayName("Docker Hosts")); DynamicGroup fabric = addChild(EntitySpec.create(DynamicGroup.class) .configure(DynamicGroup.ENTITY_FILTER, Predicates.and(Predicates.instanceOf(StubContainer.class), EntityPredicates.attributeEqualTo(StubContainer.DOCKER_INFRASTRUCTURE, this))) .configure(DynamicGroup.MEMBER_DELEGATE_CHILDREN, true).displayName("All Docker Containers")); DynamicMultiGroup buckets = addChild(EntitySpec.create(DynamicMultiGroup.class) .configure(DynamicMultiGroup.ENTITY_FILTER, StubUtils.sameInfrastructure(this)) .configure(DynamicMultiGroup.RESCAN_INTERVAL, 15L) .configure(DynamicMultiGroup.BUCKET_FUNCTION, new Function<Entity, String>() { @Override/*from w w w. j a v a 2 s. co m*/ public String apply(@Nullable Entity input) { return input.getApplication().getDisplayName() + ":" + input.getApplicationId(); } }) .configure(DynamicMultiGroup.BUCKET_SPEC, EntitySpec.create(BasicGroup.class).configure(BasicGroup.MEMBER_DELEGATE_CHILDREN, true)) .displayName("Docker Applications")); sensors().set(DOCKER_HOST_CLUSTER, hosts); sensors().set(DOCKER_CONTAINER_FABRIC, fabric); sensors().set(DOCKER_APPLICATIONS, buckets); }
From source file:org.eclipse.buildship.ui.wizard.project.WorkingSetConfigurationWidget.java
private Button findWorkingSetsEnabledButton(Composite parent) { return (Button) findControl(parent, Predicates.instanceOf(Button.class)); }