List of usage examples for com.google.common.collect Iterables getOnlyElement
public static <T> T getOnlyElement(Iterable<T> iterable)
From source file:tiger.TreeScopeSizer.java
public TreeScopeSizer(Map<ComponentInfo, ComponentInfo> scopeTree, @Nullable ComponentInfo rootComponentInfo) { this.scopeTree = scopeTree; if (!scopeTree.isEmpty()) { rootComponentInfo = Iterables .getOnlyElement(Sets.difference(Sets.newHashSet(scopeTree.values()), scopeTree.keySet())); } else {//from w w w . j a v a 2 s . c o m Preconditions.checkNotNull(rootComponentInfo); } scopeToDepthMap.put(rootComponentInfo, 0); largestScope = rootComponentInfo; for (ComponentInfo componentInfo : scopeTree.keySet()) { int depth = findTreeNodeDepth(scopeTree, componentInfo); scopeToDepthMap.put(componentInfo, depth); } int depth = 0; for (Map.Entry<ComponentInfo, Integer> entry : scopeToDepthMap.entrySet()) { int value = entry.getValue(); if (value > depth) { depth = value; } } largestSize = depth; System.out.println(String.format("scopeTree: %s", scopeTree)); System.out.println(String.format("scopeToDepthMap: %s", scopeToDepthMap)); }
From source file:org.jclouds.aws.ec2.predicates.VolumeAttached.java
public boolean apply(Attachment attachment) { logger.trace("looking for volume %s", attachment.getVolumeId()); Volume volume = Iterables .getOnlyElement(client.describeVolumesInRegion(attachment.getRegion(), attachment.getVolumeId())); if (volume.getAttachments().size() == 0) { return false; }//from w ww . j ava2 s .co m Attachment lastAttachment = Sets.newTreeSet(volume.getAttachments()).last(); logger.trace("%s: looking for status %s: currently: %s", lastAttachment, Attachment.Status.ATTACHED, lastAttachment.getStatus()); return lastAttachment.getStatus() == Attachment.Status.ATTACHED; }
From source file:com.urswolfer.gerrit.client.rest.http.projects.TagApiRestClient.java
@Override public TagInfo get() throws RestApiException { JsonElement jsonElement = gerritRestClient.getRequest(tagUrl()); return Iterables.getOnlyElement(tagInfoParser.parseTagInfos(jsonElement)); }
From source file:com.opengamma.financial.analytics.model.forex.option.callspreadblack.FXDigitalCallSpreadBlackGammaFunction.java
@Override protected Set<ComputedValue> getResult(final InstrumentDerivative fxDigital, final ForexOptionDataBundle<?> data, final ComputationTarget target, final Set<ValueRequirement> desiredValues, final FunctionInputs inputs, final ValueSpecification spec, final FunctionExecutionContext executionContext) { final String spreadName = Iterables.getOnlyElement(desiredValues) .getConstraint(CalculationPropertyNamesAndValues.PROPERTY_CALL_SPREAD_VALUE); final double spread = Double.parseDouble(spreadName); final GammaValueCallSpreadBlackForexCalculator calculator = new GammaValueCallSpreadBlackForexCalculator( spread);// www. ja v a 2 s .com final CurrencyAmount result = fxDigital.accept(calculator, data); final double amount = result.getAmount(); return Collections.singleton(new ComputedValue(spec, amount)); }
From source file:org.jclouds.ecs.compute.functions.OptionToLocation.java
@Inject OptionToLocation(JustProvider justProvider, @Iso3166 Supplier<Map<String, Supplier<Set<String>>>> isoCodesByIdSupplier) { this.provider = Iterables.getOnlyElement(justProvider.get()); this.isoCodesByIdSupplier = checkNotNull(isoCodesByIdSupplier, "isoCodesByIdSupplier"); }
From source file:org.apache.aurora.scheduler.cron.quartz.CronSchedulerImpl.java
@Override public Optional<CrontabEntry> getSchedule(IJobKey jobKey) throws IllegalStateException { requireNonNull(jobKey);//from ww w.j a v a2 s.com try { return Optional .of(Iterables.getOnlyElement(FluentIterable.from(scheduler.getTriggersOfJob(jobKey(jobKey))) .filter(CronTrigger.class).transform(Quartz::crontabEntry))); } catch (SchedulerException e) { LOG.error("Error reading job " + JobKeys.canonicalString(jobKey) + " cronExpression Quartz: " + e, e); return Optional.absent(); } }
From source file:org.jclouds.aws.ec2.compute.functions.RegionAndIdToImage.java
public Image apply(RegionAndName key) { try {//w ww . ja va 2s. c o m org.jclouds.aws.ec2.domain.Image image = Iterables.getOnlyElement( sync.getAMIServices().describeImagesInRegion(key.getRegion(), imageIds(key.getName()))); return parser.apply(image); } catch (Exception e) { logger.warn(e, "could not find image %s/%s: %s", key.getRegion(), key.getName(), e.getMessage()); return null; } }
From source file:org.jclouds.glesys.compute.functions.DatacenterToLocation.java
@Override public Location apply(String datacenter) { return new LocationBuilder().scope(LocationScope.ZONE).description(datacenter).id(datacenter) // TODO: iso3166Codes .parent(Iterables.getOnlyElement(provider.get())).build(); }
From source file:org.jclouds.ec2.predicates.VolumeDetached.java
public boolean apply(Attachment attachment) { logger.trace("looking for volume %s", attachment.getVolumeId()); Volume volume = Iterables .getOnlyElement(client.describeVolumesInRegion(attachment.getRegion(), attachment.getVolumeId())); /*If attachment size is 0 volume is detached for sure.*/ if (volume.getAttachments().size() == 0) { return true; }/*from w w w . j a va2 s. c om*/ /* But if attachment size is > 0, then the attachment could be in any state. * So we need to check if the status is DETACHED (return true) or not (return false). */ Attachment lastAttachment = getLast(volume.getAttachments()); logger.trace("%s: looking for status %s: currently: %s", lastAttachment, Attachment.Status.DETACHED, lastAttachment.getStatus()); return lastAttachment.getStatus() == Attachment.Status.DETACHED; }
From source file:com.opengamma.financial.analytics.model.forex.option.callspreadblack.FXDigitalCallSpreadBlackGammaSpotFunction.java
@Override protected Set<ComputedValue> getResult(final InstrumentDerivative fxDigital, final ForexOptionDataBundle<?> data, final ComputationTarget target, final Set<ValueRequirement> desiredValues, final FunctionInputs inputs, final ValueSpecification spec, final FunctionExecutionContext executionContext) { final String spreadName = Iterables.getOnlyElement(desiredValues) .getConstraint(CalculationPropertyNamesAndValues.PROPERTY_CALL_SPREAD_VALUE); final double spread = Double.parseDouble(spreadName); final GammaSpotCallSpreadBlackForexCalculator calculator = new GammaSpotCallSpreadBlackForexCalculator( spread);//from w w w .j ava 2 s. c o m final CurrencyAmount result = fxDigital.accept(calculator, data); final double gammaSpot = result.getAmount() / 100.0; // FIXME: the 100 should be removed when the scaling is available return Collections.singleton(new ComputedValue(spec, gammaSpot)); }