List of usage examples for com.google.common.collect Iterables getOnlyElement
public static <T> T getOnlyElement(Iterable<T> iterable)
From source file:de.cosmocode.palava.ipc.xml.rpc.adapters.ValueType.java
/** * Returns the type associated with a given value. * /*from w w w . j a va 2s .c o m*/ * @since 1.0 * @param value the value * @return the {@link ValueType} representing the type of the specified value * @throws NullPointerException if value is null */ public static ValueType of(Value value) { Preconditions.checkNotNull(value, "Value"); final Serializable first = Iterables.getOnlyElement(value.getContent()); final JAXBElement<?> element; final Object content; if (first instanceof JAXBElement<?>) { element = JAXBElement.class.cast(first); content = element.getValue(); } else { element = null; content = first; } // ordering from the most used to the least if (first instanceof String) { return STRING; } else if (DATETIME_ISO8601_NAME.equals(element.getName())) { return DATETIME_ISO801; } else { return of(value, content); } }
From source file:com.google.devtools.build.lib.analysis.config.transitions.SplitTransition.java
/** * Returns true iff {@code option} and {@splitOptions} are equal. * * <p>This can be used to determine if a split is a noop. *//* w w w . j a va 2 s .c o m*/ static boolean equals(BuildOptions options, List<BuildOptions> splitOptions) { return splitOptions.size() == 1 && Iterables.getOnlyElement(splitOptions).equals(options); }
From source file:org.apache.provisionr.cloudstack.core.SecurityGroups.java
/** * Get a SecurityGroup by name.//w ww .ja va2 s.com * * @throws NoSuchElementException if securityGroup does not exist. */ public static SecurityGroup getByName(CloudStackClient cloudStackClient, String securityGroup) { return Iterables .getOnlyElement(cloudStackClient.getSecurityGroupClient().listSecurityGroups(named(securityGroup))); }
From source file:dagger.producers.monitoring.TimingRecorders.java
/** * Returns a timing recorder factory that delegates to the given factories, and ensures that any * method called on this object, even transitively, does not throw a {@link RuntimeException} or * return null./*from w w w .j ava2s . com*/ * * <p>If the delegate recorders throw an {@link Error}, then that will escape this recorder * implementation. Errors are treated as unrecoverable conditions, and may cause the entire * component's execution to fail. */ public static ProductionComponentTimingRecorder.Factory delegatingProductionComponentTimingRecorderFactory( Collection<ProductionComponentTimingRecorder.Factory> factories) { switch (factories.size()) { case 0: return noOpProductionComponentTimingRecorderFactory(); case 1: return new NonThrowingProductionComponentTimingRecorder.Factory(Iterables.getOnlyElement(factories)); default: return new DelegatingProductionComponentTimingRecorder.Factory(factories); } }
From source file:com.groupon.jenkins.dynamic.build.execution.DynamicBuildExection.java
private static DynamicBuildRunner getBuildRunner(DynamicBuild build, BuildExecutionContext dynamicBuildRun, BuildType buildType, DotCiPluginRunner dotCiPluginRunner) { return build.getBuildConfiguration().isParallized() ? new DynamicMultiConfigBuildRunner(build, buildType, dotCiPluginRunner) : new DynamicSingleConfigBuildRunner(build, dynamicBuildRun, buildType, dotCiPluginRunner, Iterables.getOnlyElement(build.getAxisList())); }
From source file:com.opengamma.financial.analytics.timeseries.VolatilityWeightedFXForwardCurveNodeReturnSeriesFunction.java
@Override protected String getFCHTSStart(ValueProperties constraints) { Set<String> startDates = constraints.getValues(HistoricalTimeSeriesFunctionUtils.START_DATE_PROPERTY); if (startDates == null || startDates.size() != 1) { return null; }// w w w . j a v a 2 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.apache.beam.sdk.fn.data.RemoteGrpcPortRead.java
public static RemoteGrpcPortRead fromPTransform(PTransform pTransform) throws InvalidProtocolBufferException { checkArgument(URN.equals(pTransform.getSpec().getUrn()), "Expected URN for %s, got %s", RemoteGrpcPortRead.class.getSimpleName(), pTransform.getSpec().getUrn()); checkArgument(pTransform.getOutputsCount() == 1, "Expected exactly one output, got %s", pTransform.getOutputsCount()); RemoteGrpcPort port = RemoteGrpcPort.parseFrom(pTransform.getSpec().getPayload()); String outputPcollection = Iterables.getOnlyElement(pTransform.getOutputsMap().values()); return readFromPort(port, outputPcollection); }
From source file:net.sourceforge.pmd.lang.apex.rule.apexunit.ApexUnitTestClassShouldHaveAsserts.java
private Object checkForAssertStatements(ApexNode<?> node, Object data) { final List<ASTBlockStatement> blockStatements = node.findDescendantsOfType(ASTBlockStatement.class); final List<ASTStatement> statements = Iterables.getOnlyElement(blockStatements) .findDescendantsOfType(ASTStatement.class); boolean isAssertFound = false; for (final ASTStatement statement : statements) { final List<ASTMethodCallExpression> methodCalls = statement .findDescendantsOfType(ASTMethodCallExpression.class); for (final ASTMethodCallExpression methodCallExpression : methodCalls) { final String methodName = methodCallExpression.getNode().getMethod().getName(); if (methodCallExpression.getNode().getDefiningType().getApexName().equalsIgnoreCase(SYSTEM) && (methodName.equalsIgnoreCase(ASSERT) || methodName.equalsIgnoreCase(ASSERT_EQUALS) || methodName.equalsIgnoreCase(ASSERT_NOT_EQUALS))) { isAssertFound = true;/*from w ww . j a v a2 s.com*/ } } } if (!isAssertFound) { addViolation(data, node); } return data; }
From source file:com.opengamma.financial.analytics.model.forex.AbstractForexSpotRateMarketDataFunction.java
@Override public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues) { final ComputedValue inputValue = Iterables.getOnlyElement(inputs.getAllValues()); final ValueSpecification outputSpec = new ValueSpecification(ValueRequirementNames.SPOT_RATE, target.toSpecification(), createValueProperties().get()); return ImmutableSet.of(new ComputedValue(outputSpec, inputValue.getValue())); }
From source file:org.jclouds.ibmdev.functions.GetFirstInstanceInList.java
@Override public Instance apply(HttpResponse from) { return Iterables.getOnlyElement(listParser.apply(from)); }