Example usage for com.google.common.collect Iterables getOnlyElement

List of usage examples for com.google.common.collect Iterables getOnlyElement

Introduction

In this page you can find the example usage for com.google.common.collect Iterables getOnlyElement.

Prototype

public static <T> T getOnlyElement(Iterable<T> iterable) 

Source Link

Document

Returns the single element contained in iterable .

Usage

From source file:com.opengamma.engine.marketdata.manipulator.YieldCurveNodeExtractor.java

private String getSingleProperty(final ValueSpecification spec, final String propertyName) {
    final ValueProperties properties = spec.getProperties();
    final Set<String> curves = properties.getValues(propertyName);
    return Iterables.getOnlyElement(curves);
}

From source file:org.apache.drill.exec.physical.impl.window.StreamingWindowFrameBatchCreator.java

@Override
public RecordBatch getBatch(FragmentContext context, WindowPOP config, List<RecordBatch> children)
        throws ExecutionSetupException {
    return new StreamingWindowFrameRecordBatch(config, context, Iterables.getOnlyElement(children));
}

From source file:gr.forth.ics.swkm.model2.ModelDiff.java

private static void checkTriplesOfFirstContainedInSecond(Model m1, Model m2) {
    for (Triple t : m1.triples().fetch()) {
        for (Resource ng : t.graphs()) {
            Triples triples = m2.triples().g(ng.mappedTo(m2)).s(t.subject().mappedTo(m2))
                    .p(t.predicate().mappedTo(m2)).o(t.object().mappedTo(m2)).fetch();
            Iterables.getOnlyElement(triples);
        }//from w w  w .  j  a va 2  s. co m
    }
}

From source file:com.opengamma.financial.analytics.timeseries.VolatilityWeightedYieldCurveNodeReturnSeriesFunction.java

@Override
protected String getYCHTSStart(ValueProperties constraints) {
    Set<String> startDates = constraints.getValues(HistoricalTimeSeriesFunctionUtils.START_DATE_PROPERTY);
    if (startDates == null || startDates.size() != 1) {
        return null;
    }//from   w ww.  j ava2  s.c  o m
    String startDate = Iterables.getOnlyElement(startDates);

    Set<String> volWeightingStartDates = constraints
            .getValues(VolatilityWeightingFunctionUtils.VOLATILITY_WEIGHTING_START_DATE_PROPERTY);
    if (volWeightingStartDates == null || volWeightingStartDates.size() != 1) {
        // NOTE jonathan 2013-04-29 -- should start a day earlier so the result after weighting starts at the startDate,
        // but need to know previous date with data
        return startDate;
    } else {
        return Iterables.getOnlyElement(volWeightingStartDates);
    }
}

From source file:org.jclouds.http.functions.UnwrapOnlyNestedJsonValueInSet.java

@Override
public T apply(HttpResponse arg0) {
    Set<T> set = json.apply(arg0);
    if (set == null || set.size() == 0)
        return null;
    return Iterables.getOnlyElement(set);
}

From source file:org.apache.drill.exec.schema.ListSchema.java

@Override
public void addField(Field field) {
    if (field.getFieldType().getMode() == DataMode.REPEATED || fields.isEmpty() || !isSingleTyped()
            || !Iterables.getOnlyElement(fields).equals(field.getFieldType())) {
        fields.add(field);//from   w  w w. j a va2 s  .  c  o m
    }
}

From source file:edu.umn.msi.tropix.common.jobqueue.deployer.DeployerProperties.java

public String get() {
    Preconditions.checkState(properties.size() == 1,
            "Expected to have exactly one property when get() is called, actual number " + properties.size());
    return apply(Iterables.getOnlyElement(properties.keySet()));
}

From source file:org.apache.drill.exec.physical.impl.producer.ProducerConsumerBatchCreator.java

@Override
public ProducerConsumerBatch getBatch(FragmentContext context, ProducerConsumer config,
        List<RecordBatch> children) throws ExecutionSetupException {
    return new ProducerConsumerBatch(config, context, Iterables.getOnlyElement(children));
}

From source file:sklearn.linear_model.BaseLinearRegressor.java

@Override
public RegressionModel encodeModel(Schema schema) {
    return RegressionModelUtil.encodeRegressionModel(getCoef(), Iterables.getOnlyElement(getIntercept()),
            schema);
}

From source file:com.google.api.tools.framework.importers.swagger.aspects.utils.VendorExtensionUtils.java

/** Returns name of the vendor extension used. */
public static <T> String usedExtension(DiagCollector diagCollector, Map<String, Object> vendorExtensions,
        String extensionName, String... legacyNamesForExtension) {
    if (vendorExtensions != null) {
        warnOnLegacyExtensions(legacyNamesForExtension, vendorExtensions, extensionName, diagCollector);

        Iterable<String> allNamesForExtension = ImmutableList.<String>builder().add(legacyNamesForExtension)
                .add(extensionName).build();

        List<String> usedExtensionNames = getExtensionsNamesUsed(vendorExtensions, allNamesForExtension);

        if (usedExtensionNames.size() > 1) {
            diagCollector.addDiag(Diag.error(new SimpleLocation(extensionName),
                    "OpenAPI spec is invalid since multiple "
                            + "extension definitions '%s' for the same extension are used. Please provide "
                            + "only one extension definition with name '%s'.",
                    Joiner.on(",").join(usedExtensionNames), extensionName));
            return "";
        } else if (usedExtensionNames.size() == 1) {
            return Iterables.getOnlyElement(usedExtensionNames);
        }// www  .  j  a  va2 s. co m
    }
    return "";
}