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.financial.analytics.model.credit.isda.cdsoption.ISDACreditDefaultSwapOptionParallelCS01Function.java

@Override
protected Set<ComputedValue> getComputedValue(final CreditDefaultSwapOptionDefinition definition,
        final ISDADateCurve yieldCurve, final double vol, final ZonedDateTime[] calibrationTenors,
        final double[] marketSpreads, final HazardRateCurve hazardRateCurve, final ZonedDateTime valuationTime,
        final ComputationTarget target, final ValueProperties properties) {
    final Double spreadCurveBump = Double.valueOf(Iterables.getOnlyElement(
            properties.getValues(CreditInstrumentPropertyNamesAndValues.PROPERTY_SPREAD_CURVE_BUMP)));
    final SpreadBumpType spreadBumpType = SpreadBumpType.valueOf(Iterables.getOnlyElement(
            properties.getValues(CreditInstrumentPropertyNamesAndValues.PROPERTY_SPREAD_BUMP_TYPE)));
    final double cs01 = CALCULATOR.getCS01ParallelShiftCreditDefaultSwapOption(valuationTime, definition, vol,
            yieldCurve, hazardRateCurve, calibrationTenors, marketSpreads, spreadCurveBump, spreadBumpType);
    final ValueSpecification spec = new ValueSpecification(ValueRequirementNames.CS01, target.toSpecification(),
            properties);/*from w  w w  .j  ava 2s.  co m*/
    return Collections.singleton(new ComputedValue(spec, cs01));
}

From source file:ai.grakn.graql.internal.reasoner.query.ReasonerQueries.java

/**
 * create a reasoner query from provided list of atoms
 * NB: atom constraints (types and predicates, if any) will be included in the query
 * @param as list of atoms that define the query
 * @param tx corresponding transaction/*from w  w w  .  j ava  2s. c om*/
 * @return reasoner query defined by the provided list of atoms together with their constraints (types and predicates, if any)
 */
public static ReasonerQueryImpl create(List<Atom> as, GraknTx tx) {
    boolean isAtomic = as.size() == 1;
    return isAtomic ? new ReasonerAtomicQuery(Iterables.getOnlyElement(as)).inferTypes()
            : new ReasonerQueryImpl(as, tx).inferTypes();
}

From source file:com.cloudera.exhibit.etl.tbl.PercentileTbl.java

public PercentileTbl(Map<String, String> values, Map<String, Object> options) {
    if (values.size() != 1) {
        throw new IllegalArgumentException("PERCENTILE must have exactly one input value");
    }// w  w  w.  j a v  a  2  s  . c o  m
    if (options.get(PERCENTILES_OPTION) == null) {
        throw new IllegalArgumentException(
                "PERCENTILE must have an integer list named 'percentiles' in its options");
    }
    Map.Entry<String, String> e = Iterables.getOnlyElement(values.entrySet());
    this.obsKey = e.getKey();
    this.outKey = e.getValue();
    this.percentiles = Lists.newArrayList();
    for (Object o : (List) options.get(PERCENTILES_OPTION)) {
        int p = Integer.valueOf(o.toString());
        if (p < 0 || p > 100) {
            throw new IllegalArgumentException(
                    "percentiles must be integer values between 0 and 100, found: " + p);
        }
    }
    this.binCount = options.containsKey("bins") ? Integer.valueOf(options.get("bins").toString()) : 10000;
}

From source file:com.opengamma.financial.analytics.model.credit.isda.cdsoption.ISDACreditDefaultSwapOptionParallelIR01Function.java

@Override
protected Set<ComputedValue> getComputedValue(final CreditDefaultSwapOptionDefinition definition,
        final ISDADateCurve yieldCurve, final double vol, final ZonedDateTime[] calibrationTenors,
        final double[] marketSpreads, final HazardRateCurve hazardRateCurve, final ZonedDateTime valuationTime,
        final ComputationTarget target, final ValueProperties properties) {
    final Double interestRateCurveBump = Double.valueOf(Iterables.getOnlyElement(
            properties.getValues(CreditInstrumentPropertyNamesAndValues.PROPERTY_INTEREST_RATE_CURVE_BUMP)));
    final InterestRateBumpType interestRateBumpType = InterestRateBumpType.valueOf(Iterables.getOnlyElement(
            properties.getValues(CreditInstrumentPropertyNamesAndValues.PROPERTY_INTEREST_RATE_BUMP_TYPE)));
    //    final double ir01 = CALCULATOR.getIR01ParallelShiftCreditDefaultSwap(valuationTime, definition, vol, yieldCurve, calibrationTenors, marketSpreads, interestRateCurveBump,
    //        interestRateBumpType);
    final ValueSpecification spec = new ValueSpecification(ValueRequirementNames.IR01, target.toSpecification(),
            properties);// ww  w. j ava2 s  . co  m
    return Collections.singleton(new ComputedValue(spec, 0));
}

From source file:com.opengamma.financial.analytics.model.credit.isda.cdsoption.ISDACreditDefaultSwapOptionParallelGammaCS01Function.java

@Override
protected Set<ComputedValue> getComputedValue(final CreditDefaultSwapOptionDefinition definition,
        final ISDADateCurve yieldCurve, final double vol, final ZonedDateTime[] calibrationTenors,
        final double[] marketSpreads, final HazardRateCurve hazardRateCurve, final ZonedDateTime valuationTime,
        final ComputationTarget target, final ValueProperties properties) {
    final Double spreadCurveBump = Double.valueOf(Iterables.getOnlyElement(
            properties.getValues(CreditInstrumentPropertyNamesAndValues.PROPERTY_SPREAD_CURVE_BUMP)));
    final SpreadBumpType spreadBumpType = SpreadBumpType.valueOf(Iterables.getOnlyElement(
            properties.getValues(CreditInstrumentPropertyNamesAndValues.PROPERTY_SPREAD_BUMP_TYPE)));
    final double gammaCS01 = CALCULATOR.getGammaParallelShiftCreditDefaultSwapOption(valuationTime, definition,
            vol, yieldCurve, hazardRateCurve, calibrationTenors, marketSpreads, spreadCurveBump,
            spreadBumpType);//from   w w  w .  j  a  va  2  s  . c  o  m
    final ValueSpecification spec = new ValueSpecification(ValueRequirementNames.GAMMA_CS01,
            target.toSpecification(), properties);
    return Collections.singleton(new ComputedValue(spec, gammaCS01));
}

From source file:org.polymap.rhei.um.auth.UmAuthorizationModule.java

@Override
public Set<Principal> rolesOf(Subject subject) {
    Set<UserPrincipal> principals = subject.getPrincipals(UserPrincipal.class);
    UserPrincipal principal = Iterables.getOnlyElement(principals);

    Set<Principal> result = new HashSet();
    if (principal.getName().equals("admin")) {
        ///*from   w  w  w. j a v  a2  s . co  m*/
    } else {
        User user = ((UmUserPrincipal) principal).getUser();
        for (final String groupName : loginModule.repo.groupsOf(user)) {
            result.add(new Principal() {
                @Override
                public String getName() {
                    return groupName;
                }
            });
        }
    }
    return result;
}

From source file:org.jclouds.gogrid.predicates.LoadBalancerLatestJobCompleted.java

@Override
public boolean apply(LoadBalancer loadBalancer) {
    checkNotNull(loadBalancer, "Load balancer must be a valid instance");
    checkNotNull(loadBalancer.getName(), "Load balancer must be a valid name");
    Job latestJob = Iterables
            .getOnlyElement(jobClient.getJobList(latestJobForObjectByName(loadBalancer.getName())));
    return JobState.SUCCEEDED.equals(latestJob.getCurrentState());
}

From source file:com.google.errorprone.bugpatterns.ComparableType.java

private static Type getComparableTypeArgument(ClassTree tree, VisitorState state) {
    final Type comparable = state.getTypes().asSuper(ASTHelpers.getType(tree),
            state.getSymtab().comparableType.asElement());

    if (comparable != null && !comparable.getTypeArguments().isEmpty()) {
        return Iterables.getOnlyElement(comparable.getTypeArguments());
    }// w w  w  .  j  ava2s .c  om

    return null;
}

From source file:org.apache.beam.runners.direct.DirectGroupByKeyOverrideFactory.java

@Override
public PTransformReplacement<PCollection<KV<K, V>>, PCollection<KV<K, Iterable<V>>>> getReplacementTransform(
        AppliedPTransform<PCollection<KV<K, V>>, PCollection<KV<K, Iterable<V>>>, PTransform<PCollection<KV<K, V>>, PCollection<KV<K, Iterable<V>>>>> transform) {

    PCollection<KV<K, Iterable<V>>> output = (PCollection<KV<K, Iterable<V>>>) Iterables
            .getOnlyElement(transform.getOutputs().values());

    return PTransformReplacement.of(PTransformReplacements.getSingletonMainInput(transform),
            new DirectGroupByKey<>(transform.getTransform(), output.getWindowingStrategy()));
}

From source file:io.prestosql.sql.planner.plan.FilterNode.java

@Override
public PlanNode replaceChildren(List<PlanNode> newChildren) {
    return new FilterNode(getId(), Iterables.getOnlyElement(newChildren), predicate);
}