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:brooklyn.entity.container.docker.application.DockerEntitySpecResolver.java

@Override
public EntitySpec<?> resolve(String type, BrooklynClassLoadingContext loader, Set<String> encounteredTypes) {
    String dockerServiceType = getLocalType(type);
    List<String> parts = Splitter.on(":").splitToList(dockerServiceType);
    if (parts.isEmpty() || parts.size() > 2) {
        throw new IllegalArgumentException("Docker serviceType cannot be parsed: " + dockerServiceType);
    }/*w w  w  . java2s  .  co  m*/
    String imageName = Iterables.get(parts, 0);
    String imageTag = Iterables.get(parts, 1, "latest");
    log.debug("Creating Docker service entity with image {} and tag {}", imageName, imageTag);

    EntitySpec<VanillaDockerApplication> spec = EntitySpec.create(VanillaDockerApplication.class);
    spec.configure(DockerAttributes.DOCKER_IMAGE_NAME, imageName);
    if (parts.size() == 2) {
        spec.configure(DockerAttributes.DOCKER_IMAGE_TAG, imageTag);
    }
    return spec;
}

From source file:org.jclouds.vcloud.functions.OrgNameVDCNameResourceEntityNameToEndpoint.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 entityName = Iterables.get(orgVDC, 2);
    if (org == null)
        org = defaultOrg;//from w  w w . ja v a 2s. c o  m
    if (vDC == null)
        vDC = defaultVDC;
    try {
        Map<String, ? extends org.jclouds.vcloud.domain.VDC> vDCs = checkNotNull(orgVDCMap.get().get(org));
        return vDCs.get(vDC).getResourceEntities().get(entityName).getHref();
    } catch (NullPointerException e) {
        throw new NoSuchElementException(
                org + "/" + vDC + "/" + entityName + " not found in " + orgVDCMap.get());
    }
}

From source file:com.fredhopper.connector.query.populators.request.SearchSortPopulator.java

@Override
public void populate(final SearchQueryPageableData<FhSearchQueryData> source, final Query target)
        throws ConversionException {
    final PageableData pageableData = source.getPageableData();
    if (pageableData != null && StringUtils.isNotBlank(pageableData.getSort())) {
        final Iterable<String> split = Splitter.on('_').split(pageableData.getSort());
        if (Iterables.size(split) > 1) {
            final String attributeName = Iterables.get(split, 0);
            final String direction = Iterables.get(split, 1);

            if ("ASC".equalsIgnoreCase(direction)) {
                target.addSortingBy(attributeName, SortDirection.ASC);
            } else {
                target.addSortingBy(attributeName, SortDirection.DESC);
            }//w  ww .j a  v a2 s.c  o  m
        }
    }
}

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

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

    if (map == null || map.size() == 0)
        throw new HttpResponseException("Unexpected connection logging format returned.", null, response);
    else if (Iterables.get(map.values(), 0).size() == 0)
        return null;
    else// ww w. ja va 2  s  .c  om
        return Iterables.get(Iterables.get(map.values(), 0).values(), 0);
}

From source file:org.jclouds.ec2.options.internal.BaseEC2RequestOptions.java

protected Set<String> getFormValuesWithKeysPrefixedBy(final String prefix) {
    Builder<String> values = ImmutableSet.builder();
    for (String key : Iterables.filter(formParameters.keySet(), Predicates2.startsWith(prefix))) {
        values.add(Iterables.get(formParameters.get(key), 0));
    }/*from   w  w  w . ja  v a  2 s  . co  m*/
    return values.build();
}

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

public BlurSession getFirstSession() {
    return this.blurSessions.isEmpty() ? null : Iterables.get(this.blurSessions, 0);
}

From source file:com.github.benmanes.caffeine.cache.node.NodeRule.java

protected final Strength valueStrength() {
    return strengthOf(Iterables.get(context.generateFeatures, 1));
}

From source file:org.jclouds.vcloud.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;/*from   w  w w. j  ava2  s. co m*/
    if (catalog == null)
        catalog = defaultCatalog;
    try {
        Map<String, ? extends org.jclouds.vcloud.domain.Catalog> catalogs = checkNotNull(
                orgCatalogMap.get().get(org));
        return catalogs.get(catalog).get(catalogItem).getHref();
    } catch (NullPointerException e) {
        throw new NoSuchElementException(
                org + "/" + catalog + "/" + catalogItem + " not found in " + orgCatalogMap.get());
    }
}

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

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

    if (map == null || map.size() == 0)
        return null;

    NodeWithCLBMetadata nodeWithCLBMetadata = Iterables.get(map.values(), 0);
    Node node = Node.builder().address(nodeWithCLBMetadata.getAddress()).port(nodeWithCLBMetadata.getPort())
            .condition(nodeWithCLBMetadata.getCondition()).type(nodeWithCLBMetadata.getType())
            .weight(nodeWithCLBMetadata.getWeight()).id(nodeWithCLBMetadata.id)
            .status(nodeWithCLBMetadata.status)
            .metadata(ParseMetadata.transformCLBMetadataToMetadata(nodeWithCLBMetadata.metadata)).build();

    return node;//from  www .  j  ava2  s .c  o  m
}

From source file:com.urswolfer.intellij.plugin.gerrit.ui.action.CompareAction.java

private void diffChange(Project project) {
    GitRepositoryManager repositoryManager = GitUtil.getRepositoryManager(project);
    final Collection<GitRepository> repositoriesFromRoots = repositoryManager.getRepositories();

    final GitRepository gitRepository = Iterables.get(repositoriesFromRoots, 0);

    final String branchName = "FETCH_HEAD";
    final String currentBranch = gitRepository.getCurrentBranch().getFullName();

    final GitCommitCompareInfo compareInfo = GerritGitUtil.loadCommitsToCompare(repositoriesFromRoots,
            branchName, project);//from   www. ja  v a2s. c om
    new GitCompareBranchesDialog(project, branchName, currentBranch, compareInfo, gitRepository).show();
}