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.haulmont.cuba.desktop.gui.components.DesktopScrollBoxLayout.java

@Nullable
@Override
public Component getComponent(int index) {
    return Iterables.get(components, index);
}

From source file:com.github.naios.wide.framework.internal.storage.server.builder.SQLScope.java

private void buildUpdates(final StringBuilder builder,
        final Multimap<ServerStorageStructure, SQLUpdateInfo> multimap) {
    final SQLMaker sqlMaker = new SQLMaker(sqlBuilder, sqlBuilder.getUpdateConfig());

    // TODO Group updates by key or updates
    final Multimap<String /*changes*/, ServerStorageStructure> changesPerStructure = HashMultimap.create();

    // Build Changeset (updates without key)
    for (final Entry<ServerStorageStructure, Collection<SQLUpdateInfo>> info : multimap.asMap().entrySet())
        changesPerStructure.put(sqlMaker.createUpdateFields(info.getKey(), info.getValue()), info.getKey());

    for (final Entry<String, Collection<ServerStorageStructure>> change : changesPerStructure.asMap()
            .entrySet()) {//w w  w.  j a  v  a 2 s .  c o m
        final String tableName = Iterables.get(change.getValue(), 0).getOwner().getTableName();

        final String keyPart = sqlMaker.createKeyPart(change.getValue());

        builder.append(SQLMaker.createUpdateQuery(tableName, change.getKey(), keyPart));
    }

    if (!multimap.isEmpty())
        builder.append(SQLMaker.NEWLINE);
}

From source file:org.obiba.mica.study.domain.Population.java

@Override
public int compareTo(Population pop) {
    if (!hasDataCollectionEvents())
        return 1;
    if (!pop.hasDataCollectionEvents())
        return -1;
    int result = Iterables.get(dataCollectionEvents, 0).compareTo(Iterables.get(pop.dataCollectionEvents, 0));

    return result != 0 ? result : this.getId().compareTo(pop.getId());
}

From source file:org.apache.brooklyn.location.jclouds.JcloudsPropertiesFromBrooklynProperties.java

protected String getProviderFromDefinition(String definition) {
    return Iterables.get(Splitter.on(":").split(definition), 1);
}

From source file:edu.byu.nlp.util.Collections3.java

/**
 * Samples a single element with replacement from the specified collection with uniform probability.
 *//*  ww w.ja v  a  2 s. c  o m*/
public static <T> T sample(Collection<T> coll, RandomGenerator rnd) {
    if (coll instanceof List) {
        // More efficient for Random access lists.
        return sample((List<T>) coll, rnd);
    }

    return Iterables.get(coll, rnd.nextInt(coll.size()));
}

From source file:eu.numberfour.n4js.scoping.utils.ProjectImportEnablingScope.java

@Override
public IEObjectDescription getSingleElement(QualifiedName name) {
    final Iterable<IEObjectDescription> result = getElements(name);
    int size = Iterables.size(result);
    if (size == 1) {
        return result.iterator().next();
    }/*  w  w  w  .j ava 2  s .  c o  m*/

    // Special case handling when we have a definition and a pure JS file in the score.
    // In such cases we return with the description that corresponds to the definition file.
    if (size == 2) {

        final IEObjectDescription first = Iterables.get(result, 0);
        final IEObjectDescription second = Iterables.get(result, 1);

        final String firstExtension = first.getEObjectURI().fileExtension();
        final String secondExtension = second.getEObjectURI().fileExtension();

        if (JS_FILE_EXTENSION.equals(firstExtension) && N4JSD_FILE_EXTENSION.equals(secondExtension)) {
            return second;
        }

        if (N4JSD_FILE_EXTENSION.equals(firstExtension) && JS_FILE_EXTENSION.equals(secondExtension)) {
            return first;
        }

    }

    // handle error cases to help user fix the issue
    StringBuilder sbErrrorMessage = new StringBuilder("Cannot resolve import target ::");

    ImportType importType = computeImportType(name, this.contextProject);
    switch (importType) {
    case PROJECT_IMPORT:
        sbErrrorMessage.append(" resolving project import :");
        break;
    case COMPLETE_IMPORT:
        sbErrrorMessage.append(" resolving full module import :");
        break;
    case SIMPLE_IMPORT:
        sbErrrorMessage.append(" resolving simple module import :");
        break;
    case PROJECT_IMPORT_NO_MAIN:
        sbErrrorMessage.append(" no main module in target project");
        break;
    default:
        sbErrrorMessage.append(" unrecognized import structure :");
        break;
    }

    if (!importType.equals(ImportType.PROJECT_IMPORT_NO_MAIN)) {
        if (size == 0) {
            sbErrrorMessage.append(" found no matching modules");
        } else {
            sbErrrorMessage.append(" found multiple matching modules ");
            sbErrrorMessage.append(IterableExtensions.join(result, ","));
        }
    }

    return new InvalidImportTargetModuleDescription(
            EObjectDescription.create("impDecl", this.importDeclaration), sbErrrorMessage.toString(),
            IssueCodes.IMP_UNRESOLVED);

}

From source file:org.apache.whirr.actions.BootstrapClusterAction.java

private Set<Instance> getInstances(final Set<String> roles, Set<? extends NodeMetadata> nodes) {
    return Sets.newLinkedHashSet(
            Collections2.transform(Sets.newLinkedHashSet(nodes), new Function<NodeMetadata, Instance>() {
                @Override/*from w w  w . j a v a2  s  .  c  o m*/
                public Instance apply(NodeMetadata node) {
                    return new Instance(node.getCredentials(), roles,
                            Iterables.get(node.getPublicAddresses(), 0),
                            Iterables.get(node.getPrivateAddresses(), 0), node.getId(), node);
                }
            }));
}

From source file:org.aksw.mex.log4mex.Execution.java

/**
 *
 * @param algorithmidentifier (instanceName or algorithmID)
 * @return/*from   w  w  w  .j ava 2 s. c om*/
 * @throws Exception
 */
public boolean setAlgorithm(String algorithmidentifier) throws Exception {
    try {
        //check whether the algorithm exists into the experiment configuration
        Collection<AlgorithmVO> t = Collections2.filter(this.getExpConf().getAlgorithms(),
                p -> (p instanceof AlgorithmVO && (p.getIndividualName().equals(algorithmidentifier)
                        || p.getIdentifier().equals(algorithmidentifier))));
        if (t != null && t.size() > 0) {
            this._algo = Iterables.get(t, 0);
        } else {
            throw new Exception("The algorithm " + algorithmidentifier + " does not belong to the experiment");
        }

    } catch (Exception e) {
        throw new Exception(e);
    }
    return true;
}

From source file:org.jclouds.openstack.keystone.v2_0.suppliers.LocationIdToURIFromAccessForTypeAndVersion.java

@VisibleForTesting
Map<String, Endpoint> firstEndpointInLocation(Multimap<String, Endpoint> locationToEndpoints) {
    Builder<String, Endpoint> locationToEndpointBuilder = ImmutableMap.<String, Endpoint>builder();
    for (Map.Entry<String, Collection<Endpoint>> entry : locationToEndpoints.asMap().entrySet()) {
        String locationId = entry.getKey();
        Collection<Endpoint> endpoints = entry.getValue();
        switch (endpoints.size()) {
        case 0:// ww  w .  jav a2s.  co  m
            logNoEndpointsInLocation(locationId);
            break;
        default:
            locationToEndpointBuilder.put(locationId, Iterables.get(endpoints, 0));
        }
    }
    return locationToEndpointBuilder.build();
}

From source file:com.shopzilla.hadoop.repl.HadoopREPL.java

@Override
protected void evaluate(final String input) throws ExitSignal {
    popHistory();// w  w  w. jav a 2  s  .c o m
    final Iterable<String> inputParts = ARG_SPLITTER.limit(2).split(input);
    if (Iterables.isEmpty(inputParts)) {
        // Do nothing
    } else {
        final String command = Iterables.get(inputParts, 0).toLowerCase();
        if (commandMappings.containsKey(call(command))) {
            commandMappings.get(call(command)).execute(
                    new CommandInvocation(command, Iterables
                            .toArray(ARG_SPLITTER.split(Iterables.get(inputParts, 1, "")), String.class)),
                    sessionState);
        } else {
            sessionState.output("Unknown command \"%s\"", command);
        }
        pushHistory(input);
    }
}