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:org.jclouds.rimuhosting.miro.functions.ParseServerFromJsonResponse.java

@Override
public Server apply(HttpResponse arg0) {
    return Iterables.get(json.apply(arg0).values(), 0).about_order;
}

From source file:org.jclouds.concurrent.TransformParallelException.java

public TransformParallelException(Map<?, Future<?>> success, Map<?, Exception> exceptions,
        String messagePrefix) {/*from  ww w .  ja v a  2  s  . c om*/
    super(String.format("error %s: %s", messagePrefix, exceptions));
    this.success = ImmutableMap.copyOf(success);
    this.exceptions = ImmutableMap.copyOf(exceptions);
    initCause(Iterables.get(exceptions.values(), 0));
}

From source file:org.jclouds.rimuhosting.miro.functions.ParseDestroyResponseFromJsonResponse.java

@Override
public List<String> apply(HttpResponse arg0) {
    return Iterables.get(json.apply(arg0).values(), 0).cancel_messages;
}

From source file:com.googlecode.blaisemath.util.xml.Point2DAdapter.java

@Override
public Point2D.Double unmarshal(String v) {
    if (v == null) {
        return null;
    }/*  w w  w . j  a  va  2s . co  m*/
    Matcher m = Pattern.compile("point\\[(.*)\\]").matcher(v.toLowerCase().trim());
    if (m.find()) {
        String inner = m.group(1);
        Iterable<String> kv = Splitter.on(",").trimResults().split(inner);
        try {
            Double x = Double.valueOf(Iterables.get(kv, 0));
            Double y = Double.valueOf(Iterables.get(kv, 1));
            return new Point2D.Double(x, y);
        } catch (NumberFormatException x) {
            Logger.getLogger(Point2DAdapter.class.getName()).log(Level.FINEST, "Not a double", x);
            return null;
        }
    } else {
        Logger.getLogger(Point2DAdapter.class.getName()).log(Level.FINEST, "Not a valid point", v);
        return null;
    }
}

From source file:org.jclouds.rimuhosting.miro.functions.ParseServerInfoFromJsonResponse.java

@Override
public ServerInfo apply(HttpResponse arg0) {
    return Iterables.get(json.apply(arg0).values(), 0).running_vps_info;
}

From source file:org.cinchapi.concourse.util.TCollections.java

/**
 * Return a random element from the {@code collection}.
 * /* ww  w  . j  a  v a  2 s.  c  o m*/
 * @param collection
 * @return a random element
 */
public static <T> T getRandomElement(Collection<T> collection) {
    int size = collection.size();
    return Iterables.get(collection, Math.abs(Random.getInt()) % size);
}

From source file:org.apache.metron.pcap.PcapHelper.java

public static Long getTimestamp(String filename) {
    try {/*from ww  w  . j  a v  a 2s  .co m*/
        return Long.parseUnsignedLong(Iterables.get(Splitter.on('_').split(filename), 2));
    } catch (Exception e) {
        //something went wrong here.
        return null;
    }
}

From source file:org.jclouds.cloudloadbalancers.functions.ConvertLB.java

@Override
public LoadBalancer apply(LB lb) {
    Builder builder = LoadBalancer.builder().region(region).name(lb.getName()).port(lb.getPort())
            .protocol(lb.getProtocol()).algorithm(lb.getAlgorithm()).nodes(lb.getNodes()).id(lb.id)
            .status(lb.status).virtualIPs(lb.virtualIps);
    if (lb.cluster.size() == 1)
        builder.clusterName(Iterables.get(lb.cluster.values(), 0));
    if (lb.sessionPersistence.size() == 1)
        builder.sessionPersistenceType(Iterables.get(lb.sessionPersistence.values(), 0));
    if (lb.created.size() == 1)
        builder.created(Iterables.get(lb.created.values(), 0));
    if (lb.updated.size() == 1)
        builder.updated(Iterables.get(lb.updated.values(), 0));
    if (lb.connectionLogging.size() == 1)
        builder.connectionLoggingEnabled(Iterables.get(lb.connectionLogging.values(), 0));
    return builder.build();
}

From source file:org.jclouds.rimuhosting.miro.functions.ParseImagesFromJsonResponse.java

@Override
public SortedSet<Image> apply(HttpResponse arg0) {
    return Iterables.get(json.apply(arg0).values(), 0).distro_infos;
}

From source file:org.jclouds.rimuhosting.miro.functions.ParseServersFromJsonResponse.java

@Override
public SortedSet<Server> apply(HttpResponse arg0) {
    return Iterables.get(json.apply(arg0).values(), 0).about_orders;
}