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:com.torodb.torod.core.subdocument.values.ScalarArray.java

@Nonnull
public ScalarValue<?> get(int index) throws IndexOutOfBoundsException {
    return Iterables.get(this, index);
}

From source file:org.jclouds.trmk.vcloud_0_8.functions.OrgNameAndTasksListNameToEndpoint.java

@SuppressWarnings("unchecked")
public URI apply(Object from) {
    Iterable<Object> orgTasksList = (Iterable<Object>) checkNotNull(from, "args");
    Object org = Iterables.get(orgTasksList, 0);
    Object tasksList = Iterables.get(orgTasksList, 1);
    if (org == null && tasksList == null)
        return defaultTasksList.get().getHref();
    else if (org == null)
        org = defaultOrg.get().getName();

    try {/*from   w  w  w. ja v  a  2s .  com*/
        Map<String, ReferenceType> tasksLists = checkNotNull(orgMap.get().get(org)).getTasksLists();
        return tasksList == null ? Iterables.getLast(tasksLists.values()).getHref()
                : tasksLists.get(tasksList).getHref();
    } catch (NullPointerException e) {
        throw new NoSuchElementException(org + "/" + tasksList + " not found in " + orgMap.get());
    }
}

From source file:org.jclouds.trmk.vcloud_0_8.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 defaultVDC.get().getHref();
    else if (org == null)
        org = defaultOrg.get().getName();

    try {//from   w  w w.  ja va  2 s .c  om
        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:gobblin.publisher.CommitSequencePublisher.java

@Override
public void publish(Collection<? extends WorkUnitState> states) throws IOException {
    super.publish(states);

    if (!states.isEmpty()) {

        String jobName = Iterables.get(states, 0).getProp(ConfigurationKeys.JOB_NAME_KEY);
        String datasetUrn = Iterables.get(states, 0).getProp(ConfigurationKeys.DATASET_URN_KEY,
                ConfigurationKeys.DEFAULT_DATASET_URN);
        this.commitSequenceBuilder.get().withJobName(jobName).withDatasetUrn(datasetUrn);
    } else {//from  ww w .j a v a2  s. co m
        log.warn("No workunitstate to publish");
        this.commitSequenceBuilder = Optional.<CommitSequence.Builder>absent();
    }
}

From source file:com.opengamma.financial.marketdatasnapshot.StructuredSnapper.java

protected static String getSingleProperty(final ValueSpecification spec, final String propertyName) {
    final ValueProperties properties = spec.getProperties();
    final Set<String> curves = properties.getValues(propertyName);
    if (curves.size() != 1) {
        throw new IllegalArgumentException("Couldn't find curve property from " + spec);
    }//from   w  w w . j a va2s  .  co  m
    final String curve = Iterables.get(curves, 0);
    return curve;
}

From source file:com.blurengine.blur.session.SessionManager.java

public BlurSession getLastSession() {
    return this.blurSessions.isEmpty() ? null : Iterables.get(this.blurSessions, this.blurSessions.size() - 1);
}

From source file:org.jclouds.suppliers.SupplyKeyMatchingValueOrNull.java

@Override
public K get() {//from   w w w .  j a  v  a2  s. c o m
    V uri = valueSupplier.get();
    // eagerly get all the values, so we can see which is default
    Map<K, V> map = Maps.transformValues(supplier.get(), Suppliers.<V>supplierFunction());
    K region = ImmutableBiMap.copyOf(map).inverse().get(uri);
    if (region == null && map.size() > 0) {
        region = Iterables.get(map.keySet(), 0);
        logger.warn("failed to find key for value %s in %s; choosing first: %s", uri, map, region);
    }
    return region;
}

From source file:com.eucalyptus.autoscaling.common.internal.configurations.LaunchConfigurations.java

public static boolean containsSecurityGroupIdentifiers(final Iterable<String> groups) {
    return !Iterables.isEmpty(groups) && Iterables.get(groups, 0).matches("sg-[0-9A-Fa-f]{8}");
}

From source file:org.jclouds.vcloud.functions.OrgNameCatalogNameVAppTemplateNameToEndpoint.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);
    Object catalogItem = Iterables.get(orgCatalog, 2);
    if (org == null)
        org = defaultOrg;/*w  ww .j a v a 2s.c om*/
    if (catalog == null)
        catalog = defaultCatalog;
    Map<String, Map<String, Map<String, ? extends CatalogItem>>> orgCatalogItemMap = this.orgCatalogItemMap
            .get();

    if (!orgCatalogItemMap.containsKey(org))
        throw new NoSuchElementException("org: " + org + " not found in " + orgCatalogItemMap.keySet());
    Map<String, Map<String, ? extends CatalogItem>> catalogs = orgCatalogItemMap.get(org);

    if (!catalogs.containsKey(catalog))
        throw new NoSuchElementException(
                "catalog: " + org + "/" + catalog + " not found in " + catalogs.keySet());
    Map<String, ? extends CatalogItem> catalogMap = catalogs.get(catalog);

    if (!catalogMap.containsKey(catalogItem))
        throw new NoSuchElementException(
                "item: " + org + "/" + catalog + "/" + catalogItem + " not found in " + catalogMap.keySet());
    CatalogItem item = catalogMap.get(catalogItem);

    return checkNotNull(item.getEntity(), "item: " + org + "/" + catalog + "/" + catalogItem + " has no entity")
            .getHref();
}

From source file:org.jclouds.vcloud.functions.OrgNameVDCNameResourceNameToEndpoint.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);
    Object resource = Iterables.get(orgVDC, 2);
    if (org == null)
        org = defaultOrg.get().getName();
    if (vDC == null)
        vDC = defaultVDC.get().getName();
    Map<String, Map<String, org.jclouds.vcloud.domain.VDC>> orgToVDCs = orgVDCMap.get();
    checkState(orgToVDCs != null, "could not get map of org name to vdcs!");
    Map<String, org.jclouds.vcloud.domain.VDC> vDCs = orgToVDCs.get(org);
    if (vDCs == null)
        throw new NoSuchElementException("org " + org + " not found in " + orgToVDCs.keySet());
    org.jclouds.vcloud.domain.VDC vDCObject = vDCs.get(vDC);
    if (vDCObject == null)
        throw new NoSuchElementException("vdc " + vDC + " in org " + org + " not found in " + vDCs.keySet());
    return getEndpointOfResourceInVDC(org, vDC, resource, vDCObject);
}