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.DepsFunction.java

/**
 * Evaluates to the dependencies of the argument.
 * Breadth first search from the given argument until there are no more unvisited nodes in the
 * transitive closure or the maximum depth (if supplied) is reached.
 *//*ww  w .j a v  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);
    int depthBound = args.size() > 1 ? args.get(1).getInteger() : Integer.MAX_VALUE;
    env.buildTransitiveClosure(argumentSet, depthBound, executor);

    // LinkedHashSet preserves the order of insertion when iterating over the values.
    // The order by which we traverse the result is meaningful because the dependencies are
    // traversed level-by-level.
    Set<QueryTarget> result = new LinkedHashSet<>();
    Set<QueryTarget> current = argumentSet;

    // Iterating depthBound+1 times because the first one processes the given argument set.
    for (int i = 0; i <= depthBound; i++) {
        Set<QueryTarget> next = env.getFwdDeps(Iterables.filter(current, Predicates.not(result::contains)));
        result.addAll(current);
        if (next.isEmpty()) {
            break;
        }
        current = next;
    }
    return result;
}

From source file:com.google.cloud.bigtable.grpc.scanner.SimpleRowConverter.java

public Row.Builder buildRow(SimpleRow row) {
    Row.Builder rowBuilder = Row.newBuilder();
    String prevKey = "";
    Family.Builder familyBuilder = null;
    ImmutableList<SimpleColumn> list = SimpleRow.FamilyColumnOrdering.DEFAULT_ORDERING
            .immutableSortedCopy(row.getList());

    for (int i = 0; i < list.size(); i++) {
        SimpleColumn column = list.get(i);
        if (!prevKey.equals(column.getFamily())) {
            familyBuilder = rowBuilder.addFamiliesBuilder().setName(column.getFamily());
        }/*  w  w  w.  ja v  a2s .  co m*/
        Column.Builder columnBuilder = Column.newBuilder().setQualifier(column.getQualifier());
        columnBuilder.addCells(Cell.newBuilder().setTimestampMicros(column.getTimestamp())
                .addAllLabels(column.getLabels()).setValue(column.getValue()).build());
        familyBuilder.addColumns(columnBuilder);
        prevKey = column.getFamily();
    }
    return rowBuilder;
}

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

@Override
public Set<QueryTarget> eval(QueryEnvironment env, ImmutableList<Argument> args,
        ListeningExecutorService executor) throws QueryException, InterruptedException {
    String label = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, args.get(0).getWord());
    Set<QueryTarget> inputs = args.get(1).getExpression().eval(env, executor);
    Set<QueryTarget> result = new LinkedHashSet<>();
    for (QueryTarget input : inputs) {
        result.addAll(env.getTargetsInAttribute(input, label));
    }//  w w  w.  j  a  va 2 s  . co  m
    return result;
}

From source file:com.spectralogic.ds3cli.views.cli.TableView.java

public void setTableDataAlignment(final ImmutableList<Integer> columnAlign) {
    // set alignment
    if (this.header != null && this.columnCount > 0) {
        for (int i = 0; i < this.columnCount; i++) {
            this.header[i].setDataAlign(columnAlign.get(i).shortValue());
        }/*from w  w  w . j  a  v a  2s.  c  o  m*/
    }
}

From source file:org.apache.calcite.sql.type.CompositeSingleOperandTypeChecker.java

public boolean checkSingleOperandType(SqlCallBinding callBinding, SqlNode node, int iFormalOperand,
        boolean throwOnFailure) {
    assert allowedRules.size() >= 1;

    final ImmutableList<? extends SqlSingleOperandTypeChecker> rules = getRules();
    if (composition == Composition.SEQUENCE) {
        return rules.get(iFormalOperand).checkSingleOperandType(callBinding, node, 0, throwOnFailure);
    }//from  w w w  .  j a  va 2 s  .  com

    int typeErrorCount = 0;

    boolean throwOnAndFailure = (composition == Composition.AND) && throwOnFailure;

    for (SqlSingleOperandTypeChecker rule : rules) {
        if (!rule.checkSingleOperandType(callBinding, node, iFormalOperand, throwOnAndFailure)) {
            typeErrorCount++;
        }
    }

    boolean ret;
    switch (composition) {
    case AND:
        ret = typeErrorCount == 0;
        break;
    case OR:
        ret = typeErrorCount < allowedRules.size();
        break;
    default:
        // should never come here
        throw Util.unexpected(composition);
    }

    if (!ret && throwOnFailure) {
        // In the case of a composite OR, we want to throw an error
        // describing in more detail what the problem was, hence doing the
        // loop again.
        for (SqlSingleOperandTypeChecker rule : rules) {
            rule.checkSingleOperandType(callBinding, node, iFormalOperand, true);
        }

        // If no exception thrown, just throw a generic validation signature
        // error.
        throw callBinding.newValidationSignatureError();
    }

    return ret;
}

From source file:org.cspoker.ai.bots.bot.gametree.mcts.strategies.selection.SquareSampleProportionateSelector.java

@Override
public INode select(InnerNode innerNode) {
    ImmutableList<INode> children = innerNode.getChildren();
    double[] cumulSums = new double[children.size()];
    double cumulSum = 0;
    for (int i = 0; i < cumulSums.length; i++) {
        long nbSamples = children.get(i).getNbSamples();
        cumulSum += nbSamples * nbSamples;
        cumulSums[i] = cumulSum;//  www . j  ava2  s. c o  m
    }
    for (int i = 0; i < cumulSums.length; i++) {
        cumulSums[i] = cumulSums[i] / cumulSum;
    }
    double randVar = random.nextDouble();
    for (int i = 0; i < cumulSums.length; i++) {
        if (randVar < cumulSums[i]) {
            return children.get(i);
        }
    }
    return children.get(cumulSums.length - 1);
}

From source file:com.google.template.soy.jbcsrc.restricted.BytecodeUtils.java

private static Expression doShortCircuitingLogicalOperator(
        final ImmutableList<? extends Expression> expressions, final boolean isOrOperator) {
    checkArgument(!expressions.isEmpty());
    for (Expression expr : expressions) {
        expr.checkAssignableTo(Type.BOOLEAN_TYPE);
    }//from w w  w  . ja v a2s  . co m
    if (expressions.size() == 1) {
        return expressions.get(0);
    }

    return new Expression(Type.BOOLEAN_TYPE,
            Expression.areAllCheap(expressions) ? Features.of(Feature.CHEAP) : Features.of()) {
        @Override
        protected void doGen(CodeBuilder adapter) {
            Label end = new Label();
            Label shortCircuit = new Label();
            for (int i = 0; i < expressions.size(); i++) {
                Expression expr = expressions.get(i);
                expr.gen(adapter);
                if (i == expressions.size() - 1) {
                    // if we are the last one, just goto end. Whatever the result of the last expression is
                    // determines the result of the whole expression (when all prior tests fail).
                    adapter.goTo(end);
                } else {
                    adapter.ifZCmp(isOrOperator ? Opcodes.IFNE : Opcodes.IFEQ, shortCircuit);
                }
            }
            adapter.mark(shortCircuit);
            adapter.pushBoolean(isOrOperator); // default for || is true && is false
            adapter.mark(end);
        }
    };
}

From source file:com.github.rinde.datgen.pdptw.DatasetGenerator.java

/**
 * Returns the point closest to the exact center of the area spanned by the
 * graph./* w ww  . j  a v  a2 s  . c  o  m*/
 * @param graph The graph.
 * @return The point of the graph closest to the exact center of the area
 *         spanned by the graph.
 */
public static Point getCenterMostPoint(Graph<?> graph) {
    final ImmutableList<Point> extremes = Graphs.getExtremes(graph);
    final Point exactCenter = Point.divide(Point.add(extremes.get(0), extremes.get(1)), 2d);
    Point center = graph.getRandomNode(new MersenneTwister());
    double distance = Point.distance(center, exactCenter);

    for (final Point p : graph.getNodes()) {
        final double pDistance = Point.distance(p, exactCenter);
        if (pDistance < distance) {
            center = p;
            distance = pDistance;
        }

        if (center.equals(exactCenter)) {
            return center;
        }
    }

    return center;
}

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

@Override
ImmutableSet<QueryTarget> eval(QueryEvaluator evaluator, QueryEnvironment env) throws QueryException {
    ImmutableList<QueryExpression> operands = getOperands();
    Set<QueryTarget> lhsValue = new LinkedHashSet<>(evaluator.eval(operands.get(0), env));

    for (int i = 1; i < operands.size(); i++) {
        Set<QueryTarget> rhsValue = evaluator.eval(operands.get(i), env);
        switch (getOperator()) {
        case INTERSECT:
            lhsValue.retainAll(rhsValue);
            break;
        case UNION:
            lhsValue.addAll(rhsValue);//from w w  w .j av a2 s.c om
            break;
        case EXCEPT:
            lhsValue.removeAll(rhsValue);
            break;
        default:
            throw new IllegalStateException("operator=" + getOperator());
        }
    }
    return ImmutableSet.copyOf(lhsValue);
}

From source file:backup.store.local.LocalBackupStore.java

private ExtendedBlock toExtendedBlock(File block) {
    String blockPoolId = block.getParentFile().getName();
    String name = block.getName();
    name = name.substring(0, name.indexOf('.'));
    ImmutableList<String> list = ImmutableList.copyOf(Splitter.on('_').split(name));
    long blockId = Long.parseLong(list.get(0));
    long genstamp = Long.parseLong(list.get(1));
    return new ExtendedBlock(blockPoolId, blockId, block.length(), genstamp);
}