List of usage examples for com.google.common.collect Iterables getOnlyElement
public static <T> T getOnlyElement(Iterable<T> iterable)
From source file:io.prestosql.sql.planner.plan.DeleteNode.java
@Override public PlanNode replaceChildren(List<PlanNode> newChildren) { return new DeleteNode(getId(), Iterables.getOnlyElement(newChildren), target, rowId, outputs); }
From source file:org.sosy_lab.cpachecker.util.templates.Template.java
private static Kind getKind(LinearExpression<CIdExpression> expr) { int s = expr.size(); if (s == 1 && Objects.equals(Iterables.getOnlyElement(expr).getValue(), Rational.ONE)) { return Kind.UPPER_BOUND; } else if (s == 1 && Objects.equals(Iterables.getOnlyElement(expr).getValue(), Rational.NEG_ONE)) { return Kind.NEG_LOWER_BOUND; } else if (s == 2) { Iterator<Entry<CIdExpression, Rational>> it = expr.iterator(); Rational a = it.next().getValue(); Rational b = it.next().getValue(); if (Objects.equals(a, Rational.ONE) && Objects.equals(b, Rational.ONE)) { return Kind.SUM; } else if (Objects.equals(a, Rational.NEG_ONE) && Objects.equals(b, Rational.NEG_ONE)) { return Kind.NEG_SUM_LOWER_BOUND; } else if ((Objects.equals(a, Rational.ONE) && Objects.equals(b, Rational.NEG_ONE)) || (Objects.equals(a, Rational.NEG_ONE) && Objects.equals(b, Rational.ONE))) { return Kind.DIFFERENCE; }//w w w .java 2 s . c o m } return Kind.COMPLEX; }
From source file:com.opengamma.financial.analytics.model.pnl.PnLPeriodTranslationFunction.java
@Override public Set<ValueRequirement> getRequirements(FunctionCompilationContext context, ComputationTarget target, ValueRequirement desiredValue) { Set<String> samplingPeriods = desiredValue.getConstraints().getValues(ValuePropertyNames.SAMPLING_PERIOD); if (samplingPeriods == null || samplingPeriods.size() != 1) { return null; }/*from w w w. j a va 2 s . c o m*/ String samplingPeriod = Iterables.getOnlyElement(samplingPeriods); DateConstraint start = DateConstraint.parse("-" + samplingPeriod); ValueProperties inputConstraints = desiredValue.getConstraints().copy() .withOptional(ValuePropertyNames.SAMPLING_PERIOD) .with(HistoricalTimeSeriesFunctionUtils.START_DATE_PROPERTY, start.toString()) .with(HistoricalTimeSeriesFunctionUtils.END_DATE_PROPERTY, DateConstraint.VALUATION_TIME.toString()) .get(); return ImmutableSet .of(new ValueRequirement(_valueRequirementName, target.toSpecification(), inputConstraints)); }
From source file:com.github.nethad.clustermeister.provisioning.jppf.JPPFManagementByJobsClient.java
public Properties getJPPFConfig(String host, int port) { JPPFJob job = new JPPFJob(); try {/*from w w w . j av a 2 s .co m*/ job.addTask(new JPPFConfigReaderTask(), host, port); } catch (JPPFException ex) { throw new RuntimeException(ex); } job.getSLA().setMaxNodes(1); job.setBlocking(true); job.getSLA().setSuspended(false); List<JPPFTask> results = Collections.EMPTY_LIST; try { results = jPPFClient.submit(job); } catch (Exception ex) { throw new RuntimeException(ex); } JPPFTask task = Iterables.getOnlyElement(results); return (Properties) task.getResult(); }
From source file:org.jclouds.openstack.marconi.v1.options.StreamMessagesOptions.java
/** * @return The String representation of the marker for these StreamMessagesOptions. *//*from w ww . j a v a2 s .c o m*/ public String getMarker() { return Iterables.getOnlyElement(queryParameters.get("marker")); }
From source file:org.apache.drill.exec.ref.rops.JoinROP.java
@Override protected void setupIterators(IteratorRegistry builder) { left = Iterables.getOnlyElement(builder.getOperator(config.getLeft())); right = Iterables.getOnlyElement(builder.getOperator(config.getRight())); }
From source file:com.facebook.presto.sql.planner.plan.ChildReplacer.java
@Override public PlanNode visitDistinctLimit(DistinctLimitNode node, List<PlanNode> newChildren) { return new DistinctLimitNode(node.getId(), Iterables.getOnlyElement(newChildren), node.getLimit(), node.getHashSymbol());/*from ww w . j av a 2 s . c om*/ }
From source file:grakn.core.graql.gremlin.fragment.LabelFragment.java
@Override public GraphTraversal<Vertex, ? extends Element> applyTraversalInner( GraphTraversal<Vertex, ? extends Element> traversal, TransactionOLTP tx, Collection<Variable> vars) { Set<Integer> labelIds = labels().stream().map(label -> tx.convertToId(label).getValue()).collect(toSet()); if (labelIds.size() == 1) { int labelId = Iterables.getOnlyElement(labelIds); return traversal.has(LABEL_ID.name(), labelId); } else {//from w w w .j a v a2 s . co m return traversal.has(LABEL_ID.name(), P.within(labelIds)); } }
From source file:com.groupon.jenkins.dynamic.buildconfiguration.PluginsSection.java
public List<DotCiPluginAdapter> getPlugins() { if (getConfigValue().isEmpty()) { return Collections.emptyList(); }//w w w . ja va 2 s . c om List<?> pluginSpecs = getConfigValue().getValue(); List<DotCiPluginAdapter> plugins = new ArrayList<DotCiPluginAdapter>(pluginSpecs.size()); for (Object pluginSpec : pluginSpecs) { String pluginName; Object options; if (pluginSpec instanceof String) { pluginName = (String) pluginSpec; options = new HashMap<Object, Object>(); } else { // has to be a Map Map<String, Object> pluginSpecMap = (Map<String, Object>) pluginSpec; pluginName = Iterables.getOnlyElement(pluginSpecMap.keySet()); options = pluginSpecMap.get(pluginName); } plugins.add(createPlugin(pluginName, options)); } return plugins; }
From source file:com.opengamma.financial.analytics.model.forex.option.BloombergFXOptionSpotRateFunction.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 FXOptionSecurity security = (FXOptionSecurity) target.getSecurity(); final UnorderedCurrencyPair currencyPair = UnorderedCurrencyPair.of(security.getPutCurrency(), security.getCallCurrency()); 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 a 2 s .c om*/ 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); }