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.sqs.xml.RegexQueueHandler.java
@Override public Queue apply(HttpResponse response) { return Iterables.getOnlyElement(parse(returnStringIf200.apply(response))); }
From source file:org.apache.beam.runners.spark.translation.SparkAssignWindowFn.java
@Override @SuppressWarnings("unchecked") public WindowedValue<T> call(WindowedValue<T> windowedValue) throws Exception { final BoundedWindow boundedWindow = Iterables.getOnlyElement(windowedValue.getWindows()); final T element = windowedValue.getValue(); final Instant timestamp = windowedValue.getTimestamp(); Collection<W> windows = ((WindowFn<T, W>) fn).assignWindows(((WindowFn<T, W>) fn).new AssignContext() { @Override// w w w.ja v a2 s.c o m public T element() { return element; } @Override public Instant timestamp() { return timestamp; } @Override public BoundedWindow window() { return boundedWindow; } }); return WindowedValue.of(element, timestamp, windows, PaneInfo.NO_FIRING); }
From source file:org.jclouds.vagrant.functions.MachineToNodeMetadata.java
@Inject MachineToNodeMetadata(@Memoized Supplier<Set<? extends Location>> locations, BoxConfig.Factory boxConfigFactory) { this.location = Iterables.getOnlyElement(locations.get()); this.boxConfigFactory = boxConfigFactory; }
From source file:com.b2international.snowowl.identity.IdentityBootstrap.java
@Override public void init(SnowOwlConfiguration configuration, Environment env) throws Exception { final IdentityConfiguration conf = configuration.getModuleConfig(IdentityConfiguration.class); final List<IdentityProvider> providers = IdentityProvider.Factory.createProviders(env, conf.getProviderConfigurations()); IdentityProvider identityProvider = null; if (providers.isEmpty()) { throw new SnowOwlApplication.InitializationException("No identity provider configured"); } else if (providers.size() == 1) { identityProvider = Iterables.getOnlyElement(providers); } else {//from w w w .j a v a 2 s. co m identityProvider = new MultiIdentityProvider(providers); } if (conf.isAdminParty()) { identityProvider = new AdminPartyIdentityProvider(identityProvider); } IdentityProvider.LOG.info("Configured identity providers [{}]", identityProvider.getInfo()); env.services().registerService(IdentityProvider.class, identityProvider); }
From source file:org.jclouds.gogrid.compute.strategy.GoGridGetNodeMetadataStrategy.java
@Override public NodeMetadata getNode(String id) { try {/*from ww w. j av a 2 s . c o m*/ Server server = Iterables .getOnlyElement(client.getServerServices().getServersById(new Long(checkNotNull(id, "id")))); return server == null ? null : serverToNodeMetadata.apply(server); } catch (NoSuchElementException e) { return null; } }
From source file:com.google.jenkins.plugins.health.HealthCheckAction.java
/** * @return the {@link HealthCheckManager}. *///from w w w . ja v a2s .c o m @Override @VisibleForTesting protected HealthCheckManager getDerivedPageManager() { return Iterables.getOnlyElement(Jenkins.getActiveInstance().getExtensionList(HealthCheckManager.class)); }
From source file:org.jclouds.cloudstack.compute.functions.ZoneToLocation.java
@Override public Location apply(Zone zone) { return new LocationBuilder().scope(LocationScope.ZONE).metadata(ImmutableMap.<String, Object>of()) .description(zone.getName()).id(zone.getId()).parent(Iterables.getOnlyElement(provider.get())) .build();/*from w ww. ja va2 s .c om*/ }
From source file:com.cloudera.fts.avro.Ascii2AvroItemFn.java
@Override public void process(Pair<String, Pair<Collection<String>, Collection<String>>> input, Emitter<AvroItem> emitter) { // The first collection is events, the second attributes: need to sort them on seq if (input.second().first().size() < 1) return;/*from w ww. jav a 2s . c o m*/ String eventString = Iterables.getOnlyElement(input.second().first()); splitFactory.setType(SplitFactory.Type.EVENT); AbstractAttribsRecord eventRecord = splitFactory.create(eventString); LOG.debug(input.first() + " event: " + eventRecord.toString()); assert (eventRecord.getSerialNum().equals(input.first())); if (input.second().second().size() < 1) return; Set<AbstractAttribsRecord> attribs = new TreeSet<AbstractAttribsRecord>(); splitFactory.setType(SplitFactory.Type.ATTRS); Map<CharSequence, CharSequence> map = Maps.newHashMap(); for (String attrString : input.second().second()) { AbstractAttribsRecord attribsRecord = splitFactory.create(attrString); LOG.debug(input.first() + " attribs: " + attribsRecord.toString()); assert (attribsRecord.getSerialNum().equals(input.first())); if (attribsRecord.getSeq() <= eventRecord.getSeq()) { attribs.add(attribsRecord); } } for (AbstractAttribsRecord attribsRecord : attribs) { map.put(attribsRecord.getAttrName(), attribsRecord.getAttrValue()); } if (LOG.isDebugEnabled()) { for (Map.Entry<CharSequence, CharSequence> entry : map.entrySet()) { LOG.debug(input.first() + " map: " + entry.getKey() + "#" + entry.getValue()); } } emitter.emit(AvroItem.newBuilder().setSerialNum(input.first()).setStatus(eventRecord.getStatus()) .setSeq(eventRecord.getSeq()).setAttributes(map).build()); }
From source file:com.facebook.presto.sql.planner.plan.EnforceSingleRowNode.java
@Override public PlanNode replaceChildren(List<PlanNode> newChildren) { return new EnforceSingleRowNode(getId(), Iterables.getOnlyElement(newChildren)); }
From source file:org.jclouds.ec2.compute.functions.RegionAndIdToImage.java
public Image apply(RegionAndName key) { try {/*www . j a va 2s . com*/ org.jclouds.ec2.domain.Image image = Iterables.getOnlyElement( sync.getAMIServices().describeImagesInRegion(key.getRegion(), imageIds(key.getName()))); return parser.apply(image); } catch (NoSuchElementException e) { logger.debug(message(key, e)); return null; } catch (ResourceNotFoundException e) { logger.debug(message(key, e)); return null; } catch (Exception e) { logger.warn(e, message(key, e)); return null; } }