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.forex.option.black.FXOptionBlackPhiFunction.java
@Override public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues) throws AsynchronousExecution { final FinancialSecurity security = (FinancialSecurity) target.getSecurity(); final ValueRequirement desiredValue = Iterables.getOnlyElement(desiredValues); final Object curveSensitivitiesObject = inputs.getValue(ValueRequirementNames.FX_CURVE_SENSITIVITIES); if (curveSensitivitiesObject == null) { throw new OpenGammaRuntimeException("Could not get curve sensitivities"); }/*from w ww . java 2 s.c om*/ final String putCurrency = security.accept(ForexVisitors.getPutCurrencyVisitor()).getCode(); final String putCurrencyCurve = desiredValue.getConstraint(FXOptionBlackFunction.PUT_CURVE); final String resultCurrency = FXOptionBlackSingleValuedFunction.getResultCurrency(target); final String fullCurveName = putCurrencyCurve + "_" + putCurrency; final MultipleCurrencyInterestRateCurveSensitivity curveSensitivities = (MultipleCurrencyInterestRateCurveSensitivity) curveSensitivitiesObject; final Map<String, List<DoublesPair>> sensitivitiesForCurrency = curveSensitivities .getSensitivity(Currency.of(resultCurrency)).getSensitivities(); final ValueSpecification spec = new ValueSpecification(ValueRequirementNames.VALUE_PHI, target.toSpecification(), getResultProperties(target, desiredValue).get()); final double phi = sensitivitiesForCurrency.get(fullCurveName).get(0).second; return Collections.singleton(new ComputedValue(spec, phi)); }
From source file:org.apache.beam.runners.core.construction.CombineTranslation.java
private static <K, InputT, AccumT> Coder<AccumT> extractAccumulatorCoder( GlobalCombineFn<InputT, AccumT, ?> combineFn, AppliedPTransform<PCollection<KV<K, InputT>>, ?, Combine.PerKey<K, InputT, ?>> transform) throws CannotProvideCoderException { KvCoder<K, InputT> inputCoder = (KvCoder<K, InputT>) ((PCollection<KV<K, InputT>>) Iterables .getOnlyElement(transform.getInputs().values())).getCoder(); return AppliedCombineFn.withInputCoder(combineFn, transform.getPipeline().getCoderRegistry(), inputCoder, transform.getTransform().getSideInputs(), ((PCollection<?>) Iterables.getOnlyElement(transform.getOutputs().values())).getWindowingStrategy()) .getAccumulatorCoder();//w w w. jav a 2 s. c o m }
From source file:com.facebook.presto.sql.planner.plan.TableFinishNode.java
@Override public PlanNode replaceChildren(List<PlanNode> newChildren) { return new TableFinishNode(getId(), Iterables.getOnlyElement(newChildren), target, outputs); }
From source file:io.prestosql.sql.planner.plan.OutputNode.java
@Override public PlanNode replaceChildren(List<PlanNode> newChildren) { return new OutputNode(getId(), Iterables.getOnlyElement(newChildren), columnNames, outputs); }
From source file:com.vmware.photon.controller.api.frontend.commands.steps.HostEnterMaintenanceModeStepCmd.java
@Override protected void execute() throws ApiFeException, InterruptedException, RpcException { List<BaseEntity> entityList = step.getTransientResourceEntities(); hostEntity = (HostEntity) Iterables.getOnlyElement(entityList); int vmCount = vmBackend.countVmsOnHost(hostEntity); if (vmCount > 0) { throw new HostHasVmsException(hostEntity.getId(), vmCount); }// w w w. j av a2 s .c o m logger.info("Calling deployer to enter host to maintenance mode {}", hostEntity); ChangeHostModeTaskService.State serviceDocument = taskCommand.getDeployerXenonClient() .enterMaintenanceMode(hostEntity.getId()); // pass remoteTaskId to XenonTaskStatusStepCmd for (StepEntity nextStep : taskCommand.getTask().getSteps()) { nextStep.createOrUpdateTransientResource(XenonTaskStatusStepCmd.REMOTE_TASK_LINK_RESOURCE_KEY, serviceDocument.documentSelfLink); } }
From source file:org.kitesdk.data.hbase.DaoView.java
EntityScanner<E> newEntityScanner() { Iterable<MarkerRange> markerRanges = constraints.toKeyRanges(); // TODO: combine all ranges into a single reader MarkerRange range = Iterables.getOnlyElement(markerRanges); return dataset.getDao().getScanner(toPartitionKey(range.getStart()), range.getStart().isInclusive(), toPartitionKey(range.getEnd()), range.getEnd().isInclusive()); }
From source file:org.mitre.openid.connect.service.impl.UUIDPairwiseIdentiferService.java
@Override public String getIdentifier(UserInfo userInfo, ClientDetailsEntity client) { String sectorIdentifier = null; if (!Strings.isNullOrEmpty(client.getSectorIdentifierUri())) { UriComponents uri = UriComponentsBuilder.fromUriString(client.getSectorIdentifierUri()).build(); sectorIdentifier = uri.getHost(); // calculate based on the host component only } else {//from w ww .j a v a 2s .c o m Set<String> redirectUris = client.getRedirectUris(); UriComponents uri = UriComponentsBuilder.fromUriString(Iterables.getOnlyElement(redirectUris)).build(); sectorIdentifier = uri.getHost(); // calculate based on the host of the only redirect URI } if (sectorIdentifier != null) { // if there's a sector identifier, use that for the lookup PairwiseIdentifier pairwise = pairwiseIdentifierRepository.getBySectorIdentifier(userInfo.getSub(), sectorIdentifier); if (pairwise == null) { // we don't have an identifier, need to make and save one pairwise = new PairwiseIdentifier(); pairwise.setIdentifier(UUID.randomUUID().toString()); pairwise.setUserSub(userInfo.getSub()); pairwise.setSectorIdentifier(sectorIdentifier); pairwiseIdentifierRepository.save(pairwise); } return pairwise.getIdentifier(); } else { return null; } }
From source file:org.apache.beam.runners.core.AssignWindowsDoFn.java
@Override @SuppressWarnings("unchecked") public void processElement(final ProcessContext c) throws Exception { Collection<W> windows = ((WindowFn<T, W>) fn).assignWindows(((WindowFn<T, W>) fn).new AssignContext() { @Override/*from w w w. j a v a 2 s . c o m*/ public T element() { return c.element(); } @Override public Instant timestamp() { return c.timestamp(); } @Override public BoundedWindow window() { return Iterables.getOnlyElement(c.windowingInternals().windows()); } }); c.windowingInternals().outputWindowedValue(c.element(), c.timestamp(), windows, PaneInfo.NO_FIRING); }
From source file:com.opengamma.financial.analytics.model.forex.BloombergSecurityFXHistoricalTimeSeriesFunction.java
@Override public Set<ValueRequirement> getRequirements(final FunctionCompilationContext context, final ComputationTarget target, final ValueRequirement desiredValue) { final ValueProperties constraints = desiredValue.getConstraints(); final FinancialSecurity security = (FinancialSecurity) target.getSecurity(); final Collection<Currency> securityCurrencies = FinancialSecurityUtils.getCurrencies(security, getSecuritySource());//from www . ja v a 2s. co m final Set<String> resultCurrencies = constraints.getValues(ValuePropertyNames.CURRENCY); if (resultCurrencies != null && resultCurrencies.size() == 1) { final Currency desiredCurrency = Currency.of(Iterables.getOnlyElement(resultCurrencies)); if (securityCurrencies.size() == 1) { final Currency securityCurrency = Iterables.getOnlyElement(securityCurrencies); ValueRequirement htsRequirement = getHTSRequirement(context, desiredCurrency, securityCurrency); return htsRequirement != null ? ImmutableSet.of(htsRequirement) : null; } final Set<ValueRequirement> requirements = new HashSet<ValueRequirement>(); for (final Currency securityCurrency : securityCurrencies) { ValueRequirement htsRequirement = getHTSRequirement(context, desiredCurrency, securityCurrency); if (htsRequirement != null) { requirements.add(htsRequirement); } } return !requirements.isEmpty() ? requirements : null; } return null; }
From source file:com.vmware.photon.controller.api.frontend.commands.steps.HostEnterSuspendedModeStepCmd.java
@Override protected void execute() throws ExternalException { // Precondition check: only one host can be referenced. List<BaseEntity> entityList = step.getTransientResourceEntities(); hostEntity = (HostEntity) Iterables.getOnlyElement(entityList); // Call deployer for action and error handling. logger.info("Calling deployer to suspend host {}", hostEntity); ChangeHostModeTaskService.State serviceDocument = taskCommand.getDeployerXenonClient() .enterSuspendedMode(hostEntity.getId()); // pass remoteTaskId to XenonTaskStatusStepCmd for (StepEntity nextStep : taskCommand.getTask().getSteps()) { nextStep.createOrUpdateTransientResource(XenonTaskStatusStepCmd.REMOTE_TASK_LINK_RESOURCE_KEY, serviceDocument.documentSelfLink); }/*from ww w . j a v a2 s.com*/ }