Example usage for com.google.common.collect ImmutableList get

List of usage examples for com.google.common.collect ImmutableList get

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableList get.

Prototype

E get(int index);

Source Link

Document

Returns the element at the specified position in this list.

Usage

From source file:AntColonyPDP.GFAnt.java

private Point redirectInBounds(Point point, RoadModel rm) {
    ImmutableList<Point> bounds = rm.getBounds();
    if (point.x < bounds.get(0).x)
        point = new Point(0, point.y);
    if (point.x > bounds.get(1).x)
        point = new Point(10, point.y);
    if (point.y < bounds.get(0).y)
        point = new Point(point.x, 0);
    if (point.y > bounds.get(1).y)
        point = new Point(point.x, 10);
    return point;
}

From source file:com.sk89q.squirrelid.resolver.HttpRepositoryService.java

@Nullable
@Override/*w ww . ja  v  a2  s .c om*/
public Profile findByName(String name) throws IOException, InterruptedException {
    ImmutableList<Profile> profiles = findAllByName(Arrays.asList(name));
    if (!profiles.isEmpty()) {
        return profiles.get(0);
    } else {
        return null;
    }
}

From source file:com.google.devtools.build.lib.remote.CachedLocalSpawnRunner.java

private void passRemoteOutErr(ActionResult result, FileOutErr outErr) throws CacheNotFoundException {
    ImmutableList<byte[]> streams = actionCache
            .downloadBlobs(ImmutableList.of(result.getStdoutDigest(), result.getStderrDigest()));
    outErr.printOut(new String(streams.get(0), UTF_8));
    outErr.printErr(new String(streams.get(1), UTF_8));
}

From source file:auto.http.internal.codegen.AutoHttpWriter.java

private void buildMethods() {
    for (AutoHttpDescriptor.MethodDescriptor methodDescriptor : autoHttpDescriptor.methodElements()) {
        ExecutableElement methodElement = methodDescriptor.methodElement();
        MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder(methodElement.getSimpleName().toString())
                .addAnnotation(Override.class)
                .addModifiers(Sets.difference(methodElement.getModifiers(), ImmutableSet.of(ABSTRACT)))
                .returns(methodDescriptor.returnTypeName());

        String returnType = "returnType";
        StringBuilder returnTypeFormat = new StringBuilder("$T $N = $T.wrapType($N.class,");
        ImmutableList<Class<?>> returnTypeArguments = methodDescriptor.returnTypeArguments();
        for (int i = 0; i < returnTypeArguments.size(); i++) {
            returnTypeFormat.append(returnTypeArguments.get(i).getSimpleName());
            returnTypeFormat.append(".class,");
        }// ww w .j  a v  a2 s  . c o m
        returnTypeFormat.deleteCharAt(returnTypeFormat.length() - 1).append(")");
        methodBuilder.addStatement(returnTypeFormat.toString(), Type.class, returnType, Utils.class,
                methodDescriptor.returnType().getSimpleName());

        String convertType = "convertType";
        StringBuilder convertTypeFormat = new StringBuilder("$T $N = $T.wrapType($N.class,");
        ImmutableList<Class<?>> converterTypeArguments = methodDescriptor.converterTypeArguments();
        for (int i = 0; i < converterTypeArguments.size(); i++) {
            convertTypeFormat.append(converterTypeArguments.get(i).getSimpleName());
            convertTypeFormat.append(".class,");
        }
        convertTypeFormat.deleteCharAt(convertTypeFormat.length() - 1).append(")");
        methodBuilder.addStatement(convertTypeFormat.toString(), Type.class, convertType, Utils.class,
                methodDescriptor.converterType().getSimpleName());

        //TODO method body impl
        String builder = "builder";

        methodBuilder.addStatement("$T $N = new $T()", Request.Builder.class, builder, Request.Builder.class)
                .addStatement("$N.url($N.baseUrl())", builder, FIELD_PLUGINS)
                .addStatement("return $T.result($N.build(),$N,$N,$N)", ResultFactory.class, builder,
                        FIELD_PLUGINS, returnType, convertType);

        autoHttpClass.addMethod(methodBuilder.build());
    }
}

From source file:com.facebook.buck.rules.macros.QueryOutputsMacroExpander.java

@Override
public Object extractRuleKeyAppendables(BuildTarget target, CellPathResolver cellNames,
        final BuildRuleResolver resolver, ImmutableList<String> input) throws MacroException {
    if (input.isEmpty()) {
        throw new MacroException("One quoted query expression is expected");
    }// www  .jav a 2  s. c o  m
    String queryExpression = CharMatcher.anyOf("\"'").trimFrom(input.get(0));

    // Return a list of SourcePaths to the outputs of our query results. This enables input-based
    // rule key hits.
    return resolveQuery(target, cellNames, resolver, queryExpression).map(queryTarget -> {
        Preconditions.checkState(queryTarget instanceof QueryBuildTarget);
        try {
            return resolver.requireRule(((QueryBuildTarget) queryTarget).getBuildTarget());
        } catch (NoSuchBuildTargetException e) {
            throw new RuntimeException(new MacroException("Error extracting rule key appendables", e));
        }
    }).filter(rule -> rule.getPathToOutput() != null)
            .map(rule -> SourcePaths.getToBuildTargetSourcePath().apply(rule))
            .collect(MoreCollectors.toImmutableSortedSet(Ordering.natural()));
}

From source file:org.trnltk.apps.tokenizer.TextTokenizerDefaultTrainingApp.java

@App
public void dumpSmallTokenizationGraph_onlyForWordsAndDot_InDotFormat() {
    final TextTokenizerTrainer localTokenizer = new TextTokenizerTrainer(2, true);
    localTokenizer.train("ali veli.", "ali veli .");

    dumpTokenizationGraph(localTokenizer.build(), new Predicate<TokenizationGraphNode>() {
        @Override//from   ww w  .  jav  a 2s. c  o  m
        public boolean apply(TokenizationGraphNode input) {
            final ImmutableList<TextBlockType> types = input.getData().getTextBlockTypes();
            if (types.contains(TextBlockType.Abbreviation) || types.get(1).equals(TextBlockType.Sentence_Start))
                return false;
            return true;
        }
    },

            new Predicate<TokenizationGraphNode>() {
                @Override
                public boolean apply(TokenizationGraphNode input) {
                    final ImmutableList<TextBlockType> types = input.getData().getTextBlockTypes();
                    if (types.contains(TextBlockType.Abbreviation)
                            || types.get(0).equals(TextBlockType.Sentence_End)
                            || types.get(1).equals(TextBlockType.Dot))
                        return false;
                    return true;
                }
            },

            Predicates.<TokenizationGraphEdge>alwaysTrue());
}

From source file:com.github.explainable.sql.table.TempTable.java

/**
 * Initialization of the table columns occurs the first time this method is called. The return
 * value is memoized, and the same result is returned on all subsequent calls.
 *
 * @return The columns in the table/*  w  w w.j  a va2  s. com*/
 */
@Override
public ImmutableList<TempColumn> columns() {
    if (columns == null) {
        ImmutableList<String> columnNames = body.columnNames();
        ImmutableList.Builder<TempColumn> columnsBuilder = ImmutableList.builder();

        for (int i = 0; i < columnNames.size(); i++) {
            columnsBuilder.add(new TempColumn(columnNames.get(i), i, this));
        }

        columns = columnsBuilder.build();
    }

    return columns;
}

From source file:org.locationtech.geogig.plumbing.merge.MergeFeaturesOp.java

private Feature merge(RevFeature featureA, RevFeature featureB, RevFeature ancestor,
        RevFeatureType featureType) {/*from  w  w  w .  ja  va 2 s.  co m*/

    SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder((SimpleFeatureType) featureType.type());
    ImmutableList<PropertyDescriptor> descriptors = featureType.descriptors();
    for (int i = 0; i < descriptors.size(); i++) {
        final PropertyDescriptor descriptor = descriptors.get(i);
        final boolean isGeom = descriptor instanceof GeometryDescriptor;
        Name name = descriptor.getName();
        Object valueAncestor = ancestor.get(i).orNull();
        Object valueA = featureA.get(i).orNull();
        Object valueB = featureB.get(i).orNull();

        final boolean valueAEqualsAncestor = valueEquals(isGeom, valueA, valueAncestor);

        if (valueAEqualsAncestor) {
            featureBuilder.set(name, valueB);
        } else {
            Object merged = valueA;
            featureBuilder.set(name, merged);
        }
    }
    return featureBuilder.buildFeature(nodeRefA.name());

}

From source file:org.waveprotocol.box.server.persistence.blocks.impl.SegmentOperationImpl.java

public SegmentOperationImpl(ImmutableList<? extends WaveletOperation> operations) {
    Preconditions.checkArgument(!operations.isEmpty(), "No operations");
    rawOperation = new RawOperation(GsonSerializer.OPERATION_SERIALIZER, operations,
            operations.get(operations.size() - 1).getContext());
}

From source file:com.facebook.buck.versions.VersionedTargetGraph.java

@Nullable
@Override// w ww.j a va2 s .c  o  m
protected TargetNode<?, ?> getInternal(BuildTarget target) {

    // If this node is in the graph under the given name, return it.
    TargetNode<?, ?> node = targetsToNodes.get(target);
    if (node != null) {
        return node;
    }

    ImmutableList<ImmutableSet<Flavor>> flavorList = flavorMap.get(target.getUnflavoredBuildTarget());
    if (flavorList == null) {
        return null;
    }

    // Otherwise, see if this node exists in the graph with a "less" flavored name.  We initially
    // select all targets which contain a subset of the original flavors, which should be sorted by
    // from largest flavor set to smallest.  We then use the first match, and verify the subsequent
    // matches are subsets.
    ImmutableList<ImmutableSet<Flavor>> matches = RichStream.from(flavorList)
            .filter(target.getFlavors()::containsAll).toImmutableList();
    if (!matches.isEmpty()) {
        ImmutableSet<Flavor> firstMatch = matches.get(0);
        for (ImmutableSet<Flavor> subsequentMatch : matches.subList(1, matches.size())) {
            Preconditions.checkState(firstMatch.size() > subsequentMatch.size());
            Preconditions.checkState(firstMatch.containsAll(subsequentMatch),
                    "Found multiple disjoint flavor matches for %s: %s and %s",
                    target.getUnflavoredBuildTarget(), firstMatch, subsequentMatch);
        }
        return Preconditions.checkNotNull(targetsToNodes.get(target.withFlavors(firstMatch)))
                .withFlavors(target.getFlavors());
    }

    // Otherwise, return `null` to indicate this node isn't in the target graph.
    return null;
}