List of usage examples for com.google.common.collect Iterables getOnlyElement
public static <T> T getOnlyElement(Iterable<T> iterable)
From source file:com.opengamma.engine.marketdata.manipulator.NodeExtractor.java
protected static String getOptionalProperty(final ValueSpecification spec, final String propertyName) { final ValueProperties properties = spec.getProperties(); final Set<String> curves = properties.getValues(propertyName); if (curves != null && !curves.isEmpty()) { return Iterables.getOnlyElement(curves); } else {/*from w w w. j av a 2s . c o m*/ return null; } }
From source file:org.apache.provisionr.cloudstack.core.Networks.java
/** * Returns the first network with the given name. * * @throws NoSuchElementException if no network is found * @throws IllegalArgumentException if more networks with the same name are found *//*from ww w . ja va 2s . co m*/ public static Network getByName(CloudStackClient client, final String networkName) { Set<Network> networks = Sets.filter(client.getNetworkClient().listNetworks(), new Predicate<Network>() { @Override public boolean apply(Network network) { return network != null && network.getName().equals(networkName); } }); return Iterables.getOnlyElement(networks); }
From source file:com.google.auto.factory.processor.AnnotationValues.java
static TypeElement asType(AnnotationValue value) { return value.accept(new SimpleAnnotationValueVisitor6<TypeElement, Void>() { @Override//from ww w.j a v a 2 s .c om protected TypeElement defaultAction(Object o, Void p) { throw new IllegalArgumentException(); } @Override public TypeElement visitType(TypeMirror t, Void p) { return t.accept(new SimpleTypeVisitor6<TypeElement, Void>() { @Override protected TypeElement defaultAction(TypeMirror e, Void p) { throw new AssertionError(); } @Override public TypeElement visitDeclared(DeclaredType t, Void p) { return Iterables.getOnlyElement(ElementFilter.typesIn(ImmutableList.of(t.asElement()))); } }, null); } }, null); }
From source file:grakn.core.graql.reasoner.atom.predicate.NeqIdPredicate.java
private static Variable extractPredicateVariable(Statement pattern) { return Iterables.getOnlyElement(pattern.getProperties(NeqProperty.class).collect(Collectors.toSet())) .statement().var(); }
From source file:org.apache.brooklyn.core.mgmt.rebind.transformer.CompoundTransformerLoader.java
public static CompoundTransformer load(String contents) { CompoundTransformer.Builder builder = CompoundTransformer.builder(); Iterable<Object> toplevel = Yamls.parseAll(contents); Collection<?> rules = (Collection<?>) Iterables.getOnlyElement(toplevel); for (Object obj : rules) { Map<?, ?> map = (Map<?, ?>) obj; Entry<?, ?> entry = Iterables.getOnlyElement(map.entrySet()); addRule(builder, (String) entry.getKey(), (Map<?, ?>) entry.getValue()); }/*from w ww . j ava 2 s.c o m*/ LOG.info("Loaded " + rules.size() + " transforms"); return builder.build(); }
From source file:org.apache.whirr.service.hadoop.HadoopCluster.java
private static Instance getJobTracker(Cluster cluster) { Set<Instance> jobtracker = cluster .getInstancesMatching(RolePredicates.role(HadoopJobTrackerClusterActionHandler.ROLE)); if (jobtracker.isEmpty()) { return null; }// w w w. j a v a 2 s . co m return Iterables.getOnlyElement(jobtracker); }
From source file:sklearn.ensemble.gradient_boosting.QuantileEstimator.java
public Number getDefaultValue() { return Iterables.getOnlyElement(getQuantile()); }
From source file:org.apache.beam.sdk.extensions.sql.utils.RowAsserts.java
/** Asserts result contains single row with a double field. */ public static SerializableFunction<Iterable<Row>, Void> matchesScalar(double expected, double delta) { return input -> { Row row = Iterables.getOnlyElement(input); assertNotNull(row);//from w ww. java2s . co m assertEquals(expected, row.getDouble(0), delta); return null; }; }
From source file:sklearn.ensemble.gradient_boosting.MeanEstimator.java
@Override public Number getDefaultValue() { return Iterables.getOnlyElement(getMean()); }
From source file:org.jclouds.functions.OnlyElementOrNull.java
@Override public T apply(Iterable<T> arg0) { if (arg0 == null || Iterables.size(arg0) == 0) return null; return Iterables.getOnlyElement(arg0); }