List of usage examples for com.google.common.collect Iterables getOnlyElement
public static <T> T getOnlyElement(Iterable<T> iterable)
From source file:org.jclouds.aws.ec2.predicates.PlacementGroupDeleted.java
private PlacementGroup refresh(PlacementGroup group) { return Iterables.getOnlyElement(client.getPlacementGroupApi().get() .describePlacementGroupsInRegion(group.getRegion(), group.getName())); }
From source file:org.jclouds.ec2.compute.predicates.InstancePresent.java
protected void refresh(RegionAndName instance) { Iterables.getOnlyElement(Iterables.getOnlyElement( client.getInstanceServices().describeInstancesInRegion(instance.getRegion(), instance.getName()))); }
From source file:org.apache.calcite.adapter.druid.UnaryPrefixOperatorConversion.java
@Override public String toDruidExpression(RexNode rexNode, RelDataType rowType, DruidQuery druidQuery) { final RexCall call = (RexCall) rexNode; final List<String> druidExpressions = DruidExpressions.toDruidExpressions(druidQuery, rowType, call.getOperands());//w w w .jav a 2 s . com if (druidExpressions == null) { return null; } return DruidQuery.format("(%s %s)", druidOperator, Iterables.getOnlyElement(druidExpressions)); }
From source file:org.cebolla.injection.RepositoryRegister.java
public Optional<Object> getRepositoryForInjection(Class<?> targetClass) { Set<Object> candidates = new HashSet<>(); for (Collection<?> collection : repositories.values()) { for (Object repository : collection) { if (targetClass.isAssignableFrom(repository.getClass())) { candidates.add(repository); }/*www .j a v a 2s . com*/ } } if (candidates.isEmpty()) { return Optional.absent(); } else if (candidates.size() > 1) { throw new RuntimeException( "Ambiguous fake repository for target-class " + targetClass + ": " + candidates); } else { return Optional.of(Iterables.getOnlyElement(candidates)); } }
From source file:com.opengamma.strata.report.framework.expression.BeanTokenEvaluator.java
@Override public Set<String> tokens(Bean bean) { if (bean.propertyNames().size() == 1) { String singlePropertyName = Iterables.getOnlyElement(bean.propertyNames()); Object propertyValue = bean.property(singlePropertyName).get(); Set<String> valueTokens = ValuePathEvaluator.tokens(propertyValue); return ImmutableSet.<String>builder().add(singlePropertyName).addAll(valueTokens).build(); } else {/* ww w . j av a2 s . c o m*/ return bean.propertyNames(); } }
From source file:com.opengamma.financial.analytics.model.forex.forward.FXForwardSpotRateFunction.java
@Override public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues) throws AsynchronousExecution { final ValueRequirement desiredValue = Iterables.getOnlyElement(desiredValues); final String dataType = desiredValue.getConstraint(PROPERTY_DATA_TYPE); final FinancialSecurity security = (FinancialSecurity) target.getSecurity(); final UnorderedCurrencyPair currencyPair = UnorderedCurrencyPair.of( security.accept(ForexVisitors.getPayCurrencyVisitor()), security.accept(ForexVisitors.getReceiveCurrencyVisitor())); if (dataType.equals(LIVE)) { final Object spotObject = inputs.getValue(ValueRequirementNames.SPOT_RATE); if (spotObject == null) { throw new OpenGammaRuntimeException("Could not get live market data for " + currencyPair); }//w w w. j av a2 s .c o m final double spot = (Double) spotObject; return Collections.singleton(new ComputedValue( new ValueSpecification(ValueRequirementNames.SPOT_RATE_FOR_SECURITY, target.toSpecification(), createValueProperties().with(PROPERTY_DATA_TYPE, LIVE).get()), spot)); } else if (dataType.equals(LAST_CLOSE)) { final Object spotObject = inputs.getValue(ValueRequirementNames.HISTORICAL_TIME_SERIES_LATEST); if (spotObject == null) { throw new OpenGammaRuntimeException("Could not get last close market data for " + currencyPair); } final double spot = (Double) spotObject; return Collections.singleton(new ComputedValue( new ValueSpecification(ValueRequirementNames.SPOT_RATE_FOR_SECURITY, target.toSpecification(), createValueProperties().with(PROPERTY_DATA_TYPE, LAST_CLOSE).get()), spot)); } throw new OpenGammaRuntimeException("Did not recognise property type " + dataType); }
From source file:com.opengamma.financial.analytics.model.credit.isda.cdsoption.ISDACreditDefaultSwapOptionBucketedCS01Function.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.getCS01BucketedCreditDefaultSwapOption(valuationTime, definition, vol, yieldCurve, hazardRateCurve, calibrationTenors, marketSpreads, spreadCurveBump, spreadBumpType); final int n = calibrationTenors.length; final LocalDate[] dates = new LocalDate[n]; for (int i = 0; i < n; i++) { dates[i] = calibrationTenors[i].toLocalDate(); }/* w w w . jav a2s . c o m*/ final LocalDateLabelledMatrix1D cs01Matrix = new LocalDateLabelledMatrix1D(dates, cs01); final ValueSpecification spec = new ValueSpecification(ValueRequirementNames.BUCKETED_CS01, target.toSpecification(), properties); return Collections.singleton(new ComputedValue(spec, cs01Matrix)); }
From source file:org.apache.beam.runners.samza.translation.SamzaPublishViewTransformOverride.java
@Override public PTransformReplacement<PCollection<ElemT>, PCollection<ElemT>> getReplacementTransform( AppliedPTransform<PCollection<ElemT>, PCollection<ElemT>, View.CreatePCollectionView<ElemT, ViewT>> transform) { @SuppressWarnings("unchecked") PCollection<ElemT> input = (PCollection<ElemT>) Iterables.getOnlyElement(transform.getInputs().values()); return PTransformReplacement.of(input, new SamzaCreatePCollectionViewTransform<>(transform.getTransform().getView())); }
From source file:com.opengamma.financial.analytics.model.forex.AbstractSecurityFXHistoricalTimeSeriesFunction.java
@Override public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues) { final ValueRequirement desiredValue = Iterables.getOnlyElement(desiredValues); final String desiredCurrency = desiredValue.getConstraint(ValuePropertyNames.CURRENCY); final Collection<Currency> currencies = FinancialSecurityUtils.getCurrencies(target.getSecurity(), _securitySource);//from w w w . j av a 2 s . c om if (currencies.size() != inputs.getAllValues().size()) { if (!currencies.contains(Currency.of(desiredCurrency))) { throw new OpenGammaRuntimeException("Do not have one FX series for each requested"); } } final Map<UnorderedCurrencyPair, HistoricalTimeSeries> fxSeries = new HashMap<UnorderedCurrencyPair, HistoricalTimeSeries>(); final Iterator<Currency> currencyIterator = currencies.iterator(); for (final ComputedValue input : inputs.getAllValues()) { final Currency currency = currencyIterator.next(); if (currency.getCode().equals(desiredCurrency)) { currencyIterator.next(); } else { fxSeries.put(UnorderedCurrencyPair.of(currency, Currency.of(desiredCurrency)), (HistoricalTimeSeries) input.getValue()); } } final ValueProperties properties = createValueProperties() .with(ValuePropertyNames.CURRENCY, desiredCurrency).get(); final ValueSpecification outputSpec = new ValueSpecification( ValueRequirementNames.HISTORICAL_FX_TIME_SERIES, target.toSpecification(), properties); return ImmutableSet.of(new ComputedValue(outputSpec, fxSeries)); }
From source file:org.eclipse.sirius.diagram.ui.internal.edit.parts.SiriusNoteEditPart.java
/** * Redirect the direct edit request to the * {@link DescriptionCompartmentEditPart}. * //from w w w. j a v a 2s . c o m * @param request * the direct edit request */ @Override protected void performDirectEditRequest(Request request) { Iterable<DescriptionCompartmentEditPart> descriptionCompartmentEditPartsfilter = Iterables .filter(this.getChildren(), DescriptionCompartmentEditPart.class); if (Iterables.size(descriptionCompartmentEditPartsfilter) == 1) { DescriptionCompartmentEditPart descriptionCompartmentEditPart = Iterables .getOnlyElement(descriptionCompartmentEditPartsfilter); descriptionCompartmentEditPart.performRequest(request); } }