Example usage for com.google.common.collect Iterables get

List of usage examples for com.google.common.collect Iterables get

Introduction

In this page you can find the example usage for com.google.common.collect Iterables get.

Prototype

public static <T> T get(Iterable<T> iterable, int position) 

Source Link

Document

Returns the element at the specified position in an iterable.

Usage

From source file:edu.harvard.med.screensaver.ui.arch.util.UISelectOneBean.java

@Override
final public void setDomain(Collection<T> objects) {
    setDomain(objects, objects.size() > 0 ? Iterables.get(objects, 0) : null);
}

From source file:com.replaymod.replaystudio.pathing.TimelineTestsBase.java

protected PathSegment actualSegment(int index) {
    return Iterables.get(path.getSegments(), index);
}

From source file:org.jclouds.cloudsigma.functions.SplitNewlinesAndReturnSecondField.java

@Override
public Set<String> apply(HttpResponse response) {
    return ImmutableSet
            .copyOf(Iterables.filter(Iterables.transform(super.apply(response), new Function<String, String>() {

                @Override/*  w  ww .  j a  v  a 2s.  co  m*/
                public String apply(String arg0) {
                    if (arg0 == null)
                        return null;
                    Iterable<String> parts = Splitter.on(' ').split(arg0);
                    if (Iterables.size(parts) == 2)
                        return Iterables.get(parts, 1);
                    else if (Iterables.size(parts) == 1)
                        return Iterables.get(parts, 0);
                    return null;
                }

            }), Predicates.notNull()));
}

From source file:org.jclouds.vcloud.functions.OrgNameAndCatalogNameToEndpoint.java

@SuppressWarnings("unchecked")
public URI apply(Object from) {
    Iterable<Object> orgCatalog = (Iterable<Object>) checkNotNull(from, "args");
    Object org = Iterables.get(orgCatalog, 0);
    Object catalog = Iterables.get(orgCatalog, 1);
    if (org == null && catalog == null)
        return defaultUri;
    else if (org == null)
        org = defaultOrg;/*from   ww w  . j a  v a2 s.c  o  m*/

    try {
        Map<String, ReferenceType> catalogs = checkNotNull(orgMap.get().get(org)).getCatalogs();
        return catalog == null ? Iterables.getLast(catalogs.values()).getHref()
                : catalogs.get(catalog).getHref();
    } catch (NullPointerException e) {
        throw new NoSuchElementException(org + "/" + catalog + " not found in " + orgMap.get());
    }
}

From source file:org.jclouds.rackspace.cloudloadbalancers.v1.functions.ParseAlgorithms.java

@Override
public List<String> apply(HttpResponse response) {
    Map<String, List<Map<String, String>>> map = json.apply(response);

    if (map == null || map.size() == 0)
        throw new HttpResponseException("Unexpected JSON format returned.", null, response);

    List<Map<String, String>> list = Iterables.get(map.values(), 0);
    List<String> algorithms = Lists.newArrayList();

    for (Map<String, String> nameAlgorithmPair : list) {
        algorithms.add(Iterables.get(nameAlgorithmPair.values(), 0));
    }//  ww w .java  2s  .  co m

    return algorithms;
}

From source file:com.google.devtools.build.lib.syntax.SelectorValue.java

public SelectorValue(Map<?, ?> dictionary, String noMatchError) {
    // Put the dict through a sorting to avoid depending on insertion order.
    this.dictionary = ImmutableMap.copyOf(new TreeMap<>(dictionary));
    this.type = dictionary.isEmpty() ? Object.class : Iterables.get(dictionary.values(), 0).getClass();
    this.noMatchError = noMatchError;
}

From source file:org.apache.brooklyn.location.basic.HostLocationResolver.java

@SuppressWarnings("rawtypes")
@Override/*from w w w  . java2 s  . c  o  m*/
public Location newLocationFromString(Map locationFlags, String spec, LocationRegistry registry) {
    // Extract args from spec
    ParsedSpec parsedSpec = specParser.parse(spec);
    Map<String, String> argsMap = parsedSpec.argsMap;
    if (argsMap.isEmpty()) {
        throw new IllegalArgumentException("Invalid host spec (no host supplied): " + spec);
    } else if (argsMap.size() == 1 && Iterables.get(argsMap.values(), 0) == null) {
        // only given ip or hostname
        argsMap = ImmutableMap.of("hosts", Iterables.get(argsMap.keySet(), 0));
    } else if (!(argsMap.containsKey("host") || argsMap.containsKey("hosts"))) {
        throw new IllegalArgumentException("Invalid host spec (no host supplied): " + spec);
    }

    // Find generic applicable properties
    Map globalProperties = registry.getProperties();
    String namedLocation = (String) locationFlags.get(LocationInternal.NAMED_SPEC_NAME.getName());
    Map<String, Object> filteredProperties = new LocationPropertiesFromBrooklynProperties()
            .getLocationProperties(null, namedLocation, globalProperties);
    ConfigBag flags = ConfigBag.newInstance(locationFlags).putIfAbsent(filteredProperties);
    flags.remove(LocationInternal.NAMED_SPEC_NAME);

    // Generate target spec
    String target = "byon(" + KeyValueParser.toLine(argsMap) + ")";
    Maybe<Location> testResolve = managementContext.getLocationRegistry().resolve(target, false, null);
    if (!testResolve.isPresent()) {
        throw new IllegalArgumentException(
                "Invalid target location '" + target + "' for location '" + HOST + "': "
                        + Exceptions.collapseText(((Absent<?>) testResolve).getException()),
                ((Absent<?>) testResolve).getException());
    }

    return managementContext.getLocationManager()
            .createLocation(LocationSpec.create(SingleMachineProvisioningLocation.class)
                    .configure("location", target).configure("locationFlags", flags.getAllConfig())
                    .configure(LocationConfigUtils.finalAndOriginalSpecs(spec, locationFlags, globalProperties,
                            namedLocation)));
}

From source file:com.datastax.drivers.jdbc.pool.cassandra.connection.RoundRobinBalancingPolicy.java

private HClientPool getPoolSafely(Collection<HClientPool> pools) {
    try {//from  w  w  w  .j a  v  a  2s .c o  m
        return Iterables.get(pools, getAndIncrement(pools.size()));
    } catch (IndexOutOfBoundsException e) {
        return pools.iterator().next();
    }
}

From source file:org.jclouds.vcloud.functions.OrgNameAndVDCNameToEndpoint.java

@SuppressWarnings("unchecked")
public URI apply(Object from) {
    Iterable<Object> orgVdc = (Iterable<Object>) checkNotNull(from, "args");
    Object org = Iterables.get(orgVdc, 0);
    Object vdc = Iterables.get(orgVdc, 1);
    if (org == null && vdc == null)
        return defaultUri;
    else if (org == null)
        org = defaultOrg;//from   w  w w  .j a  v a2s  .co  m

    try {
        Map<String, ReferenceType> vdcs = checkNotNull(orgNameToVDCEndpoint.get().get(org)).getVDCs();
        return vdc == null ? Iterables.getLast(vdcs.values()).getHref() : vdcs.get(vdc).getHref();
    } catch (NullPointerException e) {
        throw new NoSuchElementException(org + "/" + vdc + " not found in " + orgNameToVDCEndpoint.get());
    }
}

From source file:org.jclouds.rackspace.cloudloadbalancers.functions.ParseConnectionThrottle.java

@Override
public ConnectionThrottle apply(HttpResponse response) {
    Map<String, ConnectionThrottle> map = json.apply(response);

    if (map == null || map.size() == 0)
        throw new HttpResponseException("Unexpected connection throttle format returned.", null, response);

    ConnectionThrottle connectionThrottle = Iterables.get(map.values(), 0);

    return connectionThrottle.isValid() ? connectionThrottle : null;
}