List of usage examples for com.google.common.collect Iterables getOnlyElement
public static <T> T getOnlyElement(Iterable<T> iterable)
From source file:com.groupon.jenkins.dynamic.buildconfiguration.NotificationsSection.java
public List<PostBuildNotifier> getNotifiers() { List<?> notifierSpecs = getConfigValue().getValue(); List<PostBuildNotifier> notifiers = new ArrayList<PostBuildNotifier>(notifierSpecs.size()); for (Object pluginSpec : notifierSpecs) { String pluginName;/*from www. ja v a2 s . c o m*/ Object options; if (pluginSpec instanceof String) { pluginName = (String) pluginSpec; options = new HashMap<String, String>(); } else { // has to be a Map Map<String, Object> pluginSpecMap = (Map<String, Object>) pluginSpec; pluginName = Iterables.getOnlyElement(pluginSpecMap.keySet()); options = pluginSpecMap.get(pluginName); } notifiers.add(createNotifier(pluginName, options)); } return notifiers; }
From source file:com.google.template.soy.jssrc.dsl.ConditionalBuilder.java
private boolean isRepresentableAsTernaryExpression(ImmutableList<IfThenPair> pairs) { if (pairs.size() != 1 || trailingElse == null) { return false; }//from w w w. j a v a 2 s . c om IfThenPair ifThen = Iterables.getOnlyElement(pairs); CodeChunk.WithValue predicate = ifThen.predicate; CodeChunk consequent = ifThen.consequent; return consequent instanceof CodeChunk.WithValue && trailingElse instanceof CodeChunk.WithValue && predicate.initialStatements().containsAll(((WithValue) consequent).initialStatements()) && predicate.initialStatements().containsAll(((WithValue) trailingElse).initialStatements()); }
From source file:edu.uci.ics.jung.layout.algorithms.BalloonLayoutAlgorithm.java
protected void setRootPolars(LayoutModel<N> layoutModel) { Graph<N> graph = layoutModel.getGraph(); Set<N> roots = TreeUtils.roots(graph); int width = layoutModel.getWidth(); if (roots.size() == 1) { // its a Tree N root = Iterables.getOnlyElement(roots); setRootPolar(layoutModel, root); setPolars(layoutModel, graph.successors(root), getCenter(layoutModel), width / 2); } else if (roots.size() > 1) { // its a Network setPolars(layoutModel, roots, getCenter(layoutModel), width / 2); }/*from w w w.j ava 2s.c o m*/ }
From source file:org.sosy_lab.cpachecker.cpa.smg.refiner.SMGStrongestPostOperator.java
@Override public Optional<SMGState> getStrongestPost(SMGState pOrigin, Precision pPrecision, CFAEdge pOperation) throws CPAException, InterruptedException { final Collection<? extends AbstractState> successors = transfer.getAbstractSuccessorsForEdge(pOrigin, pPrecision, pOperation);//from www .j a v a 2 s .c o m if (successors.isEmpty()) { return Optional.absent(); } else { return Optional.of((SMGState) Iterables.getOnlyElement(successors)); } }
From source file:com.vmware.photon.controller.apife.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 = (HostEntity) Iterables.getOnlyElement(entityList); // Call deployer for action and error handling. try {//www . ja v a 2 s . c om taskCommand.getDeployerClient().enterSuspendedMode(hostEntity.getId()); hostBackend.updateState(hostEntity, HostState.SUSPENDED); } catch (InterruptedException | RpcException e) { HostStateChangeException exception = new HostStateChangeException(hostEntity, HostState.SUSPENDED, e); throw exception; } }
From source file:com.opengamma.financial.analytics.model.future.FutureSecurityDeltaFunction.java
@Override public Set<ComputedValue> execute(FunctionExecutionContext executionContext, FunctionInputs inputs, ComputationTarget target, Set<ValueRequirement> desiredValues) throws AsynchronousExecution { final ValueRequirement desiredValue = desiredValues.iterator().next(); ValueProperties properties = desiredValue.getConstraints(); String scaleProperty = Double.toString(1); double scaleFactor = 1.0; if (target.getSecurity() instanceof InterestRateFutureSecurity) { // Add scaling and adjust properties to reflect final Set<String> scaleValue = desiredValue.getConstraints().getValues(ValuePropertyNames.SCALE); if (scaleValue != null && scaleValue.size() > 0) { scaleProperty = Iterables.getOnlyElement(scaleValue); scaleFactor = Double.parseDouble(scaleProperty); }/*from w w w .java 2 s . co m*/ properties = properties.copy().withoutAny(ValuePropertyNames.SCALE) .with(ValuePropertyNames.SCALE, scaleProperty).get(); } final ValueSpecification valueSpecification = new ValueSpecification(getValueRequirementName(), target.toSpecification(), properties); final ComputedValue result = new ComputedValue(valueSpecification, scaleFactor); return Sets.newHashSet(result); }
From source file:com.cloudera.nav.plugin.model.relations.InstanceOfRelation.java
public String getTemplateId() { return Iterables.getOnlyElement(getEp1Ids()); }
From source file:ezbake.services.graph.SelectorVertexFactory.java
private Long lookup(String uniqueVal) { SecureTitanTx tx = graph.buildTransaction() .setReadToken(AccumuloSecurityToken.getInstance().newReadToken(UNIQUE_VIS)).start(); Iterable<Vertex> itrbl = tx.getVertices(EzGraphServiceConstants.UNIQUE_KEY, uniqueVal); Long vid = null;//w w w. j a v a 2s. c o m if (!Iterables.isEmpty(itrbl)) { TitanVertex selectorVertex = (TitanVertex) Iterables.getOnlyElement(itrbl); vid = selectorVertex.getID(); } return vid; }
From source file:com.google.devtools.build.lib.rules.android.AndroidDeviceScriptFixture.java
/** * Gets the fixture script from the {@code script} attribute if set or else writes a file * containing the contents of the {@code cmd} attribute. Also, checks that exactly one of {@code * script} and {@code cmd} is set./* w w w.ja v a 2 s . c o m*/ */ private static Artifact getFixtureScript(RuleContext ruleContext) throws RuleErrorException, InterruptedException { String cmd = null; if (ruleContext.attributes().isAttributeValueExplicitlySpecified("cmd")) { cmd = ruleContext.attributes().get("cmd", Type.STRING); } TransitiveInfoCollection script = ruleContext.getPrerequisite("script", Mode.TARGET); if (((cmd == null) && (script == null)) || ((cmd != null) && (script != null))) { ruleContext.throwWithRuleError( "android_host_service_fixture requires that exactly one of the script and cmd attributes " + "be specified"); } if (cmd == null) { // The fact that there is only one file and that it has the right extension is enforced by the // rule definition. return Iterables.getOnlyElement(script.getProvider(FileProvider.class).getFilesToBuild()); } else { return writeFixtureScript(ruleContext, cmd); } }
From source file:io.crate.execution.ddl.ESClusterUpdateSettingsTask.java
static Settings buildSettingsFrom(Map<String, List<Expression>> settingsMap, Row parameters) { Settings.Builder settings = Settings.builder(); for (Map.Entry<String, List<Expression>> entry : settingsMap.entrySet()) { String settingsName = entry.getKey(); if (CrateSettings.isValidSetting(settingsName) == false) { throw new IllegalArgumentException("Setting '" + settingsName + "' is not supported"); }/*from ww w . ja v a 2 s .c o m*/ List<Expression> value = entry.getValue(); // value can be null to reset settings if (value == null) { settings.put(settingsName, (String) null); } else { CrateSettings.flattenSettings(settings, settingsName, ExpressionToObjectVisitor.convert(Iterables.getOnlyElement(value), parameters)); } } return settings.build(); }