List of usage examples for com.google.common.collect Iterables getOnlyElement
public static <T> T getOnlyElement(Iterable<T> iterable)
From source file:com.opengamma.financial.analytics.model.discounting.DiscountingParRateFunction.java
@Override public CompiledFunctionDefinition compile(final FunctionCompilationContext context, final Instant atInstant) { return new DiscountingCompiledFunction(getTargetToDefinitionConverter(context), getDefinitionToDerivativeConverter(context), false) { @Override/* w w w. java 2 s .co m*/ protected Set<ComputedValue> getValues(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues, final InstrumentDerivative derivative, final FXMatrix fxMatrix) { final MulticurveProviderInterface data = getMergedProviders(inputs, fxMatrix); final ValueRequirement desiredValue = Iterables.getOnlyElement(desiredValues); final ValueProperties properties = desiredValue.getConstraints().copy().get(); final double parRate = derivative.accept(CALCULATOR, data); final ValueSpecification spec = new ValueSpecification(PAR_RATE, target.toSpecification(), properties); return Collections.singleton(new ComputedValue(spec, parRate)); } }; }
From source file:org.apache.druid.indexing.common.task.MoveTask.java
@Override public TaskStatus run(TaskToolbox toolbox) throws Exception { // Confirm we have a lock (will throw if there isn't exactly one element) final TaskLock myLock = Iterables.getOnlyElement(getTaskLocks(toolbox.getTaskActionClient())); if (!myLock.getDataSource().equals(getDataSource())) { throw new ISE("WTF?! Lock dataSource[%s] != task dataSource[%s]", myLock.getDataSource(), getDataSource());/*from w w w .j a v a 2 s . c o m*/ } if (!myLock.getInterval().equals(getInterval())) { throw new ISE("WTF?! Lock interval[%s] != task interval[%s]", myLock.getInterval(), getInterval()); } // List unused segments final List<DataSegment> unusedSegments = toolbox.getTaskActionClient() .submit(new SegmentListUnusedAction(myLock.getDataSource(), myLock.getInterval())); // Verify none of these segments have versions > lock version for (final DataSegment unusedSegment : unusedSegments) { if (unusedSegment.getVersion().compareTo(myLock.getVersion()) > 0) { throw new ISE("WTF?! Unused segment[%s] has version[%s] > task version[%s]", unusedSegment.getIdentifier(), unusedSegment.getVersion(), myLock.getVersion()); } log.info("OK to move segment: %s", unusedSegment.getIdentifier()); } // Move segments for (DataSegment segment : unusedSegments) { final DataSegment movedSegment = toolbox.getDataSegmentMover().move(segment, targetLoadSpec); toolbox.getTaskActionClient().submit(new SegmentMetadataUpdateAction(ImmutableSet.of(movedSegment))); } return TaskStatus.success(getId()); }
From source file:eu.interedition.text.xml.module.CLIXAnnotationXMLTransformerModule.java
@Override public void start(XMLTransformer transformer, XMLEntity entity) { super.start(transformer, entity); final ObjectNode entityAttributes = entity.getAttributes(); final JsonNode startId = entityAttributes.remove(TextConstants.CLIX_START_ATTR_NAME.toString()); final JsonNode endId = entityAttributes.remove(TextConstants.CLIX_END_ATTR_NAME.toString()); if (startId == null && endId == null) { return;/*ww w.ja v a 2 s . com*/ } final long textOffset = transformer.getTextOffset(); if (startId != null) { annotations.put(startId.toString(), new Annotation(entity.getName(), new TextTarget(transformer.getTarget(), textOffset, textOffset), entityAttributes)); } if (endId != null) { final Annotation a = annotations.remove(endId.toString()); if (a != null) { Iterables.getOnlyElement(a.getTargets()).setEnd(textOffset); add(transformer, a); } } }
From source file:com.opengamma.financial.analytics.model.forex.forward.FXForwardSingleValuedFunction.java
@Override public Set<ValueSpecification> getResults(final FunctionCompilationContext context, final ComputationTarget target, final Map<ValueSpecification, ValueRequirement> inputs) { String currencyPairConfigName = null; String payCurveName = null;/*from w ww .j a va2s . co m*/ String payCurveCalculationConfig = null; String receiveCurveName = null; String receiveCurveCalculationConfig = null; for (final Map.Entry<ValueSpecification, ValueRequirement> entry : inputs.entrySet()) { final ValueSpecification specification = entry.getKey(); final ValueRequirement requirement = entry.getValue(); if (specification.getValueName().equals(ValueRequirementNames.CURRENCY_PAIRS)) { currencyPairConfigName = specification.getProperty(CurrencyPairsFunction.CURRENCY_PAIRS_NAME); } else if (requirement.getValueName().equals(ValueRequirementNames.YIELD_CURVE)) { final ValueProperties constraints = requirement.getConstraints(); if (constraints.getProperties().contains(ValuePropertyNames.PAY_CURVE)) { payCurveName = Iterables.getOnlyElement(constraints.getValues(ValuePropertyNames.CURVE)); payCurveCalculationConfig = Iterables .getOnlyElement(constraints.getValues(ValuePropertyNames.CURVE_CALCULATION_CONFIG)); } else if (constraints.getProperties().contains(ValuePropertyNames.RECEIVE_CURVE)) { receiveCurveName = Iterables.getOnlyElement(constraints.getValues(ValuePropertyNames.CURVE)); receiveCurveCalculationConfig = Iterables .getOnlyElement(constraints.getValues(ValuePropertyNames.CURVE_CALCULATION_CONFIG)); } } } assert currencyPairConfigName != null; final ConfigSource configSource = OpenGammaCompilationContext.getConfigSource(context); final ConfigDBCurrencyPairsSource currencyPairsSource = new ConfigDBCurrencyPairsSource(configSource); final CurrencyPairs baseQuotePairs = currencyPairsSource.getCurrencyPairs(currencyPairConfigName); final FinancialSecurity security = (FinancialSecurity) target.getSecurity(); final Currency putCurrency = security.accept(ForexVisitors.getPayCurrencyVisitor()); final Currency callCurrency = security.accept(ForexVisitors.getReceiveCurrencyVisitor()); final CurrencyPair baseQuotePair = baseQuotePairs.getCurrencyPair(putCurrency, callCurrency); if (baseQuotePair == null) { throw new OpenGammaRuntimeException( "Could not get base/quote pair for currency pair (" + putCurrency + ", " + callCurrency + ")"); } final ValueSpecification resultSpec = new ValueSpecification(getValueRequirementName(), target.toSpecification(), getResultProperties(target, baseQuotePair, payCurveName, receiveCurveName, payCurveCalculationConfig, receiveCurveCalculationConfig).get()); return Collections.singleton(resultSpec); }
From source file:co.cask.cdap.operations.hdfs.HDFSNodes.java
@Nullable private String getNameService() { Collection<String> nameservices = conf.getTrimmedStringCollection(DFSConfigKeys.DFS_NAMESERVICES); if (nameservices.isEmpty()) { return null; }//w w w . j a va 2 s . com if (1 == nameservices.size()) { return Iterables.getOnlyElement(nameservices); } throw new IllegalStateException( "Found multiple nameservices configured in HDFS. CDAP currently does not support " + "HDFS Federation."); }
From source file:com.opengamma.financial.analytics.model.credit.isda.cds.StandardVanillaParallelCS01CDSFunction.java
@Override protected Set<ComputedValue> getComputedValue(final CreditDefaultSwapDefinition definition, final ISDACompliantYieldCurve yieldCurve, final ZonedDateTime[] times, final double[] marketSpreads, final ZonedDateTime valuationDate, final ComputationTarget target, final ValueProperties properties, final FunctionInputs inputs, ISDACompliantCreditCurve hazardCurve, CDSAnalytic analytic) { //TODO: bump type Double bump = Double.valueOf(Iterables.getOnlyElement( properties.getValues(CreditInstrumentPropertyNamesAndValues.PROPERTY_SPREAD_CURVE_BUMP))); double cs01 = parallelCS01(definition, yieldCurve, times, marketSpreads, analytic, bump * 1e-4); final ValueSpecification spec = new ValueSpecification(ValueRequirementNames.CS01, target.toSpecification(), properties);/*from w w w . j av a2s .com*/ return Collections.singleton(new ComputedValue(spec, cs01)); }
From source file:org.immutables.generator.processor.Implicits.java
private TypeMirror getTargetTypeArgument(TypeMirror facetTypeSupertype) { TypeMirror typeArgument = Iterables .getOnlyElement(checkDeclaredType(facetTypeSupertype).getTypeArguments()); if (typeArgument instanceof TypeVariable) { return ((TypeVariable) typeArgument).getUpperBound(); }/* w w w .ja va 2 s . c om*/ return typeArgument; }
From source file:org.opendaylight.protocol.bgp.flowspec.l3vpn.AbstractFlowspecL3vpnRIBSupport.java
@Nonnull @Override/* w w w .java2s . c o m*/ protected DestinationType buildDestination(@Nonnull final Collection<MapEntryNode> routes) { final MapEntryNode routesCont = Iterables.getOnlyElement(routes); final PathId pathId = PathIdUtil.buildPathId(routesCont, routePathIdNid()); final RouteDistinguisher rd = extractRouteDistinguisher(routesCont, this.routeDistinguisherNID); return this.nlriParser.createAdvertizedRoutesDestinationType( new Object[] { rd, this.nlriParser.extractFlowspec(routesCont) }, pathId); }
From source file:eu.interedition.text.rdbms.RelationalNameRepository.java
public Name get(Name name) { return Iterables.getOnlyElement(get(singleton(name))); }
From source file:com.google.errorprone.bugpatterns.time.JavaDurationWithSeconds.java
@Override public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { if (!MATCHER.matches(tree, state)) { return Description.NO_MATCH; }//from w w w . j a va 2s . c o m SuggestedFix.Builder builder = SuggestedFix.builder(); ExpressionTree secondsArg = Iterables.getOnlyElement(tree.getArguments()); ExpressionTree receiver = ASTHelpers.getReceiver(tree); String replacement = SuggestedFixes.qualifyType(state, builder, "java.time.Duration") + ".ofSeconds(" + state.getSourceForNode(secondsArg) + ", " + state.getSourceForNode(receiver) + ".getNano())"; builder.replace(tree, replacement); return describeMatch(tree, builder.build()); }