List of usage examples for com.google.common.base Predicates instanceOf
@GwtIncompatible("Class.isInstance") public static Predicate<Object> instanceOf(Class<?> clazz)
From source file:com.googlecode.blaisemath.app.MenuConfig.java
/** * Gets the menubar configuration from file. * @param cls class with associated resource * @param key key for menubar component in config file * @return menus to comprise menubar, where values are lists with either strings or nested menus * @throws IOException if there's an error reading from the config file *//*from w w w . ja v a 2s . com*/ public static List<Map> readMenuBarConfig(Class cls, String key) throws IOException { Object res = readConfig(cls).get(key); checkState(res instanceof List, "Expected menubar to be a list of maps but was " + res); checkState(Iterables.all((List) res, Predicates.instanceOf(Map.class)), "Expected list elements of menubar to be maps"); return (List<Map>) res; }
From source file:controllers.modules.AspectLexBuilder.java
@Override public String getRoute() { DocumentCorpusModel corpus = (DocumentCorpusModel) Iterables.find(this.viewModels, Predicates.instanceOf(DocumentCorpusModel.class), null); AspectLexiconModel lexicon = (AspectLexiconModel) Iterables.find(this.viewModels, Predicates.instanceOf(AspectLexiconModel.class), null); return controllers.modules.routes.AspectLexBuilder .modulePage(corpus != null ? corpus.getIdentifier() : null, lexicon != null ? lexicon.getIdentifier() : null, false) .url();//from w w w . j a va 2 s .co m }
From source file:org.eclipse.incquery.runtime.emf.EMFScope.java
/** * Creates an EMF scope at the given roots, with customizable options. * <p> Most users should consider {@link #EMFScope(Set)} instead. * @param scopeRoots the roots of the EMF scope, must be {@link ResourceSet}s * @param options the base index building settings * @throws IncQueryException if not all scopeRoots are {@link ResourceSet}s *///from ww w . ja v a 2 s. c o m public EMFScope(Set<? extends Notifier> scopeRoots, BaseIndexOptions options) throws IncQueryException { super(); if (scopeRoots.isEmpty()) { throw new IllegalArgumentException("No scope roots given"); } else if (scopeRoots.size() == 1) { checkScopeRoots(scopeRoots, Predicates.or(ImmutableSet.of(Predicates.instanceOf(EObject.class), Predicates.instanceOf(Resource.class), Predicates.instanceOf(ResourceSet.class)))); } else { checkScopeRoots(scopeRoots, Predicates.instanceOf(ResourceSet.class)); } this.scopeRoots = ImmutableSet.copyOf(scopeRoots); this.options = options.copy(); }
From source file:org.eclipse.buildship.ui.wizard.project.WorkingSetConfigurationWidget.java
private Combo findWorkingSetsCombo(Composite parent) { return (Combo) findControl(parent, Predicates.instanceOf(Combo.class)); }
From source file:org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveStatementBase.java
protected final <S extends EffectiveStatement<?, ?>> S firstEffective(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:org.eclipse.viatra.query.runtime.emf.EMFScope.java
/** * Creates an EMF scope at the given roots, with customizable options. * <p> Most users should consider {@link #EMFScope(Set)} instead. * @param scopeRoots the roots of the EMF scope, must be {@link ResourceSet}s * @param options the base index building settings * @throws ViatraQueryException if not all scopeRoots are {@link ResourceSet}s *//*w w w . jav a 2 s .c o m*/ public EMFScope(Set<? extends Notifier> scopeRoots, BaseIndexOptions options) throws ViatraQueryException { super(); if (scopeRoots.isEmpty()) { throw new IllegalArgumentException("No scope roots given"); } else if (scopeRoots.size() == 1) { checkScopeRoots(scopeRoots, Predicates.or(ImmutableSet.of(Predicates.instanceOf(EObject.class), Predicates.instanceOf(Resource.class), Predicates.instanceOf(ResourceSet.class)))); } else { checkScopeRoots(scopeRoots, Predicates.instanceOf(ResourceSet.class)); } this.scopeRoots = ImmutableSet.copyOf(scopeRoots); this.options = options.copy(); }
From source file:org.onos.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveStatementBase.java
@SuppressWarnings("unchecked") protected final <S extends EffectiveStatement<?, ?>> Collection<? extends S> allEffective(Class<S> type) { Collection<? extends S> result = null; try {/*from ww w . ja v a 2 s. c o m*/ result = Collection.class.cast(Collections2.filter(substatements, Predicates.instanceOf(type))); } catch (NoSuchElementException e) { result = Collections.emptyList(); } return result; }
From source file:natlab.tame.tir.TIRCommaSeparatedList.java
/** * returns true if all the expressions in the list are just name expressions *//* w ww . j a va2 s.c o m*/ public boolean isAllNameExpressions() { return Iterables.all(this, Predicates.instanceOf(NameExpr.class)); }
From source file:org.apache.brooklyn.entity.monitoring.zabbix.ZabbixServerImpl.java
public void added(Entity member) { synchronized (mutex) { Optional<Location> location = Iterables.tryFind(member.getLocations(), Predicates.instanceOf(SshMachineLocation.class)); if (location.isPresent() && member.getAttribute(Startable.SERVICE_UP)) { SshMachineLocation machine = (SshMachineLocation) location.get(); if (!entityLocations.containsKey(machine)) { entityLocations.put(machine, member); // Configure the Zabbix agent List<String> commands = ImmutableList.<String>builder().add("sed -i.bk 's/\\$HOSTNAME/" + machine.getDisplayName() + "/' /etc/zabbix/zabbix_agentd.conf").add("zabbix_agentd") .build();/* w w w. j a v a 2 s .c o m*/ int result = machine.execCommands("configuring zabbix_agentd", commands); if (result == 0) { log.info("zabbix_agentd configured on {} at {}", member, machine); } else { log.warn("failed to configure zabbix_agentd on {}, status {}", machine, result); } } } else { log.warn("zabbix added({}) called but no location or service not started", member); } } }
From source file:org.eclipse.buildship.ui.wizard.project.WorkingSetConfigurationWidget.java
private Button findWorkingSetsSelectButton(Composite parent) { Predicate<Object> isButton = Predicates.instanceOf(Button.class); Predicate<Control> hasPushStyle = new Predicate<Control>() { @Override/*from w w w .j a v a2 s.com*/ public boolean apply(Control control) { return (control.getStyle() & SWT.PUSH) == SWT.PUSH; } }; return (Button) findControl(parent, Predicates.and(isButton, hasPushStyle)); }