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.vcloud.director.v1_5.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  ww  w.  j a v  a  2s. c o  m
        Set<Reference> vdcs = checkNotNull(orgNameToVdcEndpoint.get().get(org)).getVdcs();
        return vdc == null ? Iterables.getLast(vdcs).getHref()
                : Iterables.find(vdcs, nameEquals((String) vdc)).getHref();
    } catch (NullPointerException e) {
        throw new NoSuchElementException(org + "/" + vdc + " not found in " + orgNameToVdcEndpoint.get());
    }
}

From source file:org.jclouds.vcloud.director.v1_5.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.director.v1_5.domain.Vdc>> orgToVdcs = orgVdcMap.get();
    checkState(orgToVdcs != null, "could not get map of org name to Vdcs!");
    Map<String, org.jclouds.vcloud.director.v1_5.domain.Vdc> Vdcs = orgToVdcs.get(org);
    if (Vdcs == null)
        throw new NoSuchElementException("org " + org + " not found in " + orgToVdcs.keySet());
    org.jclouds.vcloud.director.v1_5.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);
}

From source file:org.jclouds.vcloud.director.v1_5.functions.OrgNameCatalogNameItemNameToEndpoint.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.get().getName();
    if (catalog == null)
        catalog = defaultCatalog.get().getName();
    try {/*  w  w w. j  ava 2s .c  o  m*/
        Map<String, Catalog> catalogs = checkNotNull(orgCatalogMap.get().get(org));
        return Iterables.find(catalogs.get(catalog).getCatalogItems(), nameEquals((String) catalogItem))
                .getHref();
    } catch (NullPointerException e) {
        throw new NoSuchElementException(
                org + "/" + catalog + "/" + catalogItem + " not found in " + orgCatalogMap.get());
    }
}

From source file:org.jclouds.trmk.vcloud_0_8.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, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>> orgToVDCs = orgVDCMap.get();
    checkState(orgToVDCs != null, "could not get map of org name to vdcs!");
    Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC> vDCs = orgToVDCs.get(org);
    if (vDCs == null)
        throw new NoSuchElementException("org " + org + " not found in " + orgToVDCs.keySet());
    org.jclouds.trmk.vcloud_0_8.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);
}

From source file:org.syncany.operations.daemon.messages.api.JsonMessageFactory.java

/** 
 * Parses JSON message for message type. 
 * First key contains message name:/*from  www .jav  a 2 s  .com*/
 * 
 * <pre>
 * { "messageType":
 *   {
 *     // payload
 *   }
 * }
 * </pre>
 */
private static String getMessageType(String message) throws Exception {
    try {
        JsonObject result = PARSER.parse(message).getAsJsonObject();
        return Iterables.get(result.entrySet(), 0).getKey();
    } catch (Exception e) {
        throw new Exception("Cannot find type of message. Invalid JSON: " + message);
    }
}

From source file:org.richfaces.model.SwingTreeNodeImpl.java

public TreeNode getChildAt(int childIndex) {
    if (childIndex < getChildCount()) {
        return Iterables.get(children, childIndex);
    }//w w  w  .  jav  a2 s  .com

    return null;
}

From source file:com.eucalyptus.auth.policy.key.TokenIssueTime.java

@Override
public String value() throws AuthException {
    try {/*from  w ww .  j  ava 2  s . co m*/
        // Token issue time is available via the access key create date for
        // temporary credentials
        final Context context = Contexts.lookup();
        final Subject subject = context.getSubject();
        final List<AccessKey> keys = context.getUser().getKeys();
        final Set<AccessKeyCredential> accessKeyCredentials = subject == null ? Collections.emptySet()
                : subject.getPublicCredentials(AccessKeyCredential.class);
        if (accessKeyCredentials.size() == 1 && Iterables.get(accessKeyCredentials, 0).getType().isDefined()
                && keys.size() == 1) {
            return Iso8601DateParser.toString(keys.get(0).getCreateDate());
        }
    } catch (final IllegalContextAccessException e) {
        // so null
    }
    return null;
}

From source file:org.jclouds.vcloud.director.v1_5.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.get().getName();
    if (catalog == null)
        catalog = defaultCatalog.get().getName();
    Map<String, Map<String, Map<String, CatalogItem>>> orgCatalogItemMap = this.orgCatalogItemMap.get();

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

    if (!catalogs.containsKey(catalog))
        throw new NoSuchElementException(
                "catalog: " + org + "/" + catalog + " not found in " + catalogs.keySet());
    Map<String, 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 w  ww .  j a va2 s.co m*/
}

From source file:org.jclouds.vcloud.compute.functions.HardwareForVApp.java

@Override
public Hardware apply(VApp from) {
    checkNotNull(from, "VApp");
    // TODO make this work with composite vApps
    Vm vm = from.getChildren().size() == 0 ? null : Iterables.get(from.getChildren(), 0);
    if (vm == null)
        return null;

    VirtualHardwareSection hardware = vm.getVirtualHardwareSection();
    HardwareBuilder builder = rasdToHardwareBuilder.apply(hardware.getItems());
    builder.location(findLocationForResource.apply(checkNotNull(from, "from").getVDC()));
    builder.ids(from.getHref().toASCIIString()).name(from.getName())
            .supportsImage(ImagePredicates.idEquals(from.getHref().toASCIIString()));
    builder.hypervisor("VMware");
    return builder.build();
}

From source file:org.obm.provisioning.authorization.SubDomainAuthorizationFilter.java

@Override
protected String getPathPermission(ServletRequest request) {
    String pathInfo = ((HttpServletRequest) request).getRequestURI();
    Iterable<String> iterable = Splitter.on("/").split(pathInfo);
    return Iterables.get(iterable, DOMAIN_UID_PATH_INDEX) + ":"
            + Iterables.get(iterable, SUB_DOMAIN_PATH_INDEX);
}