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:com.facebook.buck.query.InputsFunction.java

/**
 * Evaluates to the direct inputs of the argument.
 *//*from w  ww.  j av a 2 s .c om*/
@Override
public Set<QueryTarget> eval(QueryEnvironment env, ImmutableList<Argument> args,
        ListeningExecutorService executor) throws QueryException, InterruptedException {
    Set<QueryTarget> argumentSet = args.get(0).getExpression().eval(env, executor);
    env.buildTransitiveClosure(argumentSet, 0, executor);

    Set<QueryTarget> result = new LinkedHashSet<>();

    for (QueryTarget target : argumentSet) {
        result.addAll(env.getInputs(target));
    }
    return result;
}

From source file:com.google.devtools.build.android.desugar.BytecodeTypeInference.java

private static ImmutableList<InferredType> removeBackFromList(ImmutableList<InferredType> list,
        int countToRemove) {
    int origSize = list.size();
    int index = origSize - 1;

    while (index >= 0 && countToRemove > 0) {
        InferredType type = list.get(index);
        if (type.equals(InferredType.TOP) && index > 0 && list.get(index - 1).isCategory2()) {
            --index; // A category 2 takes two slots.
        }// w  w  w.j a va  2  s  .com
        --index; // Eat this local variable.
        --countToRemove;
    }
    checkState(countToRemove == 0, "countToRemove is %s but not 0. index=%s, list=%s", countToRemove, index,
            list);
    return list.subList(0, index + 1);
}

From source file:com.facebook.buck.query.AttrFilterFunction.java

@Override
public Set<QueryTarget> eval(QueryEnvironment env, ImmutableList<Argument> args,
        ListeningExecutorService executor) throws QueryException, InterruptedException {
    QueryExpression argument = args.get(args.size() - 1).getExpression();
    String attr = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, args.get(0).getWord());

    final String attrValue = args.get(1).getWord();
    final Predicate<Object> predicate = input -> attrValue.equals(input.toString());

    Set<QueryTarget> result = new LinkedHashSet<>();
    for (QueryTarget target : argument.eval(env, executor)) {
        ImmutableSet<Object> matchingObjects = env.filterAttributeContents(target, attr, predicate);
        if (!matchingObjects.isEmpty()) {
            result.add(target);//from w w  w  . ja v a  2s . co m
        }
    }
    return result;
}

From source file:com.facebook.buck.rules.coercer.EnvMacroTypeCoercer.java

@Override
public EnvMacro coerce(CellPathResolver cellRoots, ProjectFilesystem filesystem, Path pathRelativeToProjectRoot,
        TargetConfiguration targetConfiguration, ImmutableList<String> args) throws CoerceFailedException {
    Preconditions.checkState(args.size() == 1, String.format("expected a single argument: %s", args));
    return EnvMacro.of(args.get(0));
}

From source file:com.facebook.buck.query.OwnerFunction.java

@Override
public Set<QueryTarget> eval(QueryEnvironment env, ImmutableList<Argument> args,
        ListeningExecutorService executor) throws QueryException, InterruptedException {

    return Sets.newHashSet(env.getFileOwners(ImmutableList.of(args.get(0).getWord()), executor));
}

From source file:com.publictransitanalytics.scoregenerator.walking.ForwardTimeTracker.java

@Override
public boolean shouldReplace(final MovementPath currentPath, final LocalDateTime otherTime) {
    final ImmutableList<Movement> movements = currentPath.getMovements();
    if (movements.isEmpty()) {
        return false;
    }/*ww  w  . j av a  2  s. co m*/

    final Movement terminal = movements.get(movements.size() - 1);
    return otherTime.isBefore(terminal.getEndTime());
}

From source file:com.publictransitanalytics.scoregenerator.walking.BackwardTimeTracker.java

@Override
public boolean shouldReplace(final MovementPath currentPath, final LocalDateTime otherTime) {
    final ImmutableList<Movement> movements = currentPath.getMovements();
    if (movements.isEmpty()) {
        return false;
    }/*from  www  .  j a  va 2  s  . c  o m*/

    final Movement terminal = movements.get(0);
    return otherTime.isAfter(terminal.getStartTime());
}

From source file:com.github.hilcode.versionator.impl.DefaultVersionChangeExtractor.java

Result<String, RequestedVersionChange> extractAny(final ImmutableList<String> arguments) {
    final int indexOfLastArgument = arguments.size() - 1;
    final String lastArgument = arguments.get(indexOfLastArgument);
    final Matcher matcher = GAV.matcher(lastArgument);
    if (!matcher.matches()) {
        return Result.failure(String
                .format("Expected a GAV, but you provided: '%s'.\n\n" + "Perhaps try --help?", lastArgument));
    }/*from w  w  w . j  a  v a2s.com*/
    final Result<String, ImmutableList<Gav>> gavs = this.gavExtractor
            .extract(arguments.subList(0, indexOfLastArgument));
    if (gavs.isFailure()) {
        return Result.asFailure(gavs);
    } else {
        final FromAnyToNewVersion versionChange = new FromAnyToNewVersion(this.matchers.toGav(matcher));
        final Either<FromOldToNewVersion, FromAnyToNewVersion> fromAnyToNewVersion = Either
                .right(versionChange);
        return Result.success(new RequestedVersionChange(fromAnyToNewVersion, gavs.success()));
    }
}

From source file:com.facebook.buck.rules.coercer.QueryTargetsAndOutputsMacroTypeCoercer.java

@Override
public QueryTargetsAndOutputsMacro coerce(CellPathResolver cellRoots, ProjectFilesystem filesystem,
        Path pathRelativeToProjectRoot, TargetConfiguration targetConfiguration, ImmutableList<String> args)
        throws CoerceFailedException {
    String separator = " ";
    String query;/*from  ww w  .j  a va  2 s .  co  m*/
    if (args.size() == 2) {
        separator = args.get(0);
        query = args.get(1);
    } else if (args.size() == 1) {
        query = args.get(0);
    } else {
        throw new CoerceFailedException("One quoted query expression is expected, or a separator and a query");
    }
    return QueryTargetsAndOutputsMacro.of(separator,
            queryCoercer.coerce(cellRoots, filesystem, pathRelativeToProjectRoot, targetConfiguration, query));
}

From source file:com.squareup.wire.schema.internal.parser.ReservedElement.java

public final String toSchema() {
    StringBuilder builder = new StringBuilder();
    appendDocumentation(builder, documentation());
    builder.append("reserved ");
    ImmutableList<Object> value = values();
    for (int i = 0; i < value.size(); i++) {
        if (i > 0)
            builder.append(", ");

        Object reservation = value.get(i);
        if (reservation instanceof String) {
            builder.append('"').append(reservation).append('"');
        } else if (reservation instanceof Integer) {
            builder.append(reservation);
        } else if (reservation instanceof Range) {
            Range<Integer> range = (Range<Integer>) reservation;
            builder.append(range.lowerEndpoint()).append(" to ").append(range.upperEndpoint());
        } else {/*from  w ww  .j  av  a2  s.com*/
            throw new AssertionError();
        }
    }
    return builder.append(";\n").toString();
}