List of usage examples for com.google.common.collect ImmutableList get
E get(int index);
From source file:com.publictransitanalytics.scoregenerator.workflow.RetrospectiveMovementAssembler.java
@Override public MovementPath assemble(final PointLocation terminal, final Map<PointLocation, DynamicProgrammingRecord> lastRow) { final ImmutableList.Builder<Movement> movementsBuilder = ImmutableList.builder(); PointLocation location = terminal;/*from w w w .j ava 2 s . co m*/ DynamicProgrammingRecord record = lastRow.get(location); while (record != null) { final ModeInfo mode = record.getMode(); final ModeType type = mode.getType(); if (type.equals(ModeType.TRANSIT)) { final EntryPoint trip = mode.getTransitTrip(); final Movement movement = new TransitRideMovement(trip.getTrip(), location, record.getReachTime(), record.getPredecessor(), trip.getTime()); movementsBuilder.add(movement); } else if (type.equals(ModeType.WALKING)) { final WalkingCosts costs = mode.getWalkCosts(); final PointLocation predecessor = record.getPredecessor(); final LocalDateTime predecessorReachTime = lastRow.get(predecessor).getReachTime(); final double distanceMeters = costs.getDistanceMeters(); final LocalDateTime reachTime = record.getReachTime(); final Movement movement = new WalkMovement(reachTime, distanceMeters, location, predecessorReachTime, predecessor); movementsBuilder.add(movement); } location = record.getPredecessor(); record = (location == null) ? null : lastRow.get(location); final ImmutableList<Movement> movements = movementsBuilder.build(); if (movements.size() > 1) { final Movement recentMovement = movements.get(movements.size() - 1); final Movement priorMovement = movements.get(movements.size() - 2); if (recentMovement instanceof WalkMovement && priorMovement instanceof WalkMovement) { } } } return new FixedPath(movementsBuilder.build()); }
From source file:bots.mctsbot.ai.bots.bot.gametree.mcts.strategies.selection.SampleProportionateSelector.java
@Override public INode select(InnerNode innerNode) { ImmutableList<INode> children = innerNode.getChildren(); int[] cumulSums = new int[children.size()]; int cumulSum = 0; for (int i = 0; i < children.size(); i++) { int nbSamples = children.get(i).getNbSamples(); cumulSum += nbSamples;//from w ww. j a v a 2 s . c o m cumulSums[i] = cumulSum; } int randVar = random.nextInt(cumulSum); 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 newMap(Iterable<? extends Expression> keys, Iterable<? extends Expression> values, ConstructorRef constructorRef, Type mapType) { final ImmutableList<Expression> keysCopy = ImmutableList.copyOf(keys); final ImmutableList<Expression> valuesCopy = ImmutableList.copyOf(values); checkArgument(keysCopy.size() == valuesCopy.size()); for (int i = 0; i < keysCopy.size(); i++) { checkArgument(keysCopy.get(i).resultType().getSort() == Type.OBJECT); checkArgument(valuesCopy.get(i).resultType().getSort() == Type.OBJECT); }// w w w . ja va2 s . co m final Expression construct = constructorRef.construct(constant(hashMapCapacity(keysCopy.size()))); return new Expression(mapType, Feature.NON_NULLABLE) { @Override protected void doGen(CodeBuilder mv) { construct.gen(mv); for (int i = 0; i < keysCopy.size(); i++) { Expression key = keysCopy.get(i); Expression value = valuesCopy.get(i); mv.dup(); key.gen(mv); value.gen(mv); MethodRef.MAP_PUT.invokeUnchecked(mv); mv.pop(); // pop the Object result of map.put } } }; }
From source file:com.google.devtools.build.lib.syntax.SkylarkCallbackFunction.java
/** * Creates a list of actual arguments that contains the given arguments and all attribute values * required from the specified context.//from w ww . j av a 2 s .co m */ private ImmutableList<Object> buildArgumentList(ClassObject ctx, Object... arguments) { Builder<Object> builder = ImmutableList.<Object>builder(); ImmutableList<String> names = getParameterNames(); int requiredParameters = names.size() - arguments.length; for (int pos = 0; pos < requiredParameters; ++pos) { String name = names.get(pos); Object value = ctx.getValue(name); if (value == null) { throw new IllegalArgumentException(ctx.errorMessage(name)); } builder.add(value); } return builder.add(arguments).build(); }
From source file:com.facebook.buck.rules.macros.EnvironmentVariableMacroExpander.java
@Override protected String parse(BuildTarget target, CellPathResolver cellNames, ImmutableList<String> input) throws MacroException { if (input.size() != 1) { throw new MacroException(String.format("expected a single argument: %s", input)); }/*from w w w .j av a 2s .co m*/ return input.get(0); }
From source file:com.facebook.buck.apple.xcode.xcconfig.TokenValue.java
public TokenValue interpolate(Function<String, Optional<TokenValue>> function) { switch (type) { case LITERAL: return this; case INTERPOLATION: ImmutableList<TokenValue> newValue = interpolateList(function, interpolationValue); if (newValue.size() == 1 && newValue.get(0).type == Type.LITERAL) { Optional<TokenValue> interpolated = function.apply(newValue.get(0).literalValue); if (interpolated.isPresent()) { return interpolated.get(); }/*from w ww. java 2 s. c om*/ } return interpolation(newValue); } // unreachable throw new IllegalStateException("'type' should always be of type 'LITERAL' or 'INTERPOLATION'"); }
From source file:com.github.rinde.rinsim.examples.pdptw.gradientfield.GradientModel.java
@Override public void registerModelProvider(ModelProvider mp) { pdpModel = mp.tryGetModel(PDPModel.class); final ImmutableList<Point> bs = mp.getModel(RoadModel.class).getBounds(); minX = bs.get(0).x; maxX = bs.get(1).x;//from ww w . ja v a2 s. co m minY = bs.get(0).y; maxY = bs.get(1).y; }
From source file:com.google.cloud.firestore.ResourcePath.java
/** * The Path's id (last component).// w w w . j a va 2 s. c o m * * @return The last component of the Path or null if the path points to the root. */ @Nullable String getId() { ImmutableList<String> parts = getSegments(); if (!parts.isEmpty()) { return parts.get(parts.size() - 1); } else { return null; } }
From source file:com.google.errorprone.bugpatterns.argumentselectiondefects.NameInCommentHeuristic.java
/** * Return true if there are no comments on the original actual parameter of a change which match * the name of the formal parameter.//from w w w . jav a 2 s . co m */ @Override public boolean isAcceptableChange(Changes changes, Tree node, MethodSymbol symbol, VisitorState state) { // Now check to see if there is a comment in the position of any actual parameter we want to // change which matches the formal parameter ImmutableList<Commented<ExpressionTree>> comments = findCommentsForArguments(node, state); return changes.changedPairs().stream().noneMatch(p -> { MatchType match = NamedParameterComment.match(comments.get(p.formal().index()), p.formal().name()); return match == MatchType.EXACT_MATCH || match == MatchType.APPROXIMATE_MATCH; }); }
From source file:com.facebook.buck.query.AllPathsFunction.java
@Override public Set<QueryTarget> eval(QueryEnvironment env, ImmutableList<Argument> args, ListeningExecutorService executor) throws QueryException, InterruptedException { QueryExpression from = args.get(0).getExpression(); QueryExpression to = args.get(1).getExpression(); Set<QueryTarget> fromSet = from.eval(env, executor); Set<QueryTarget> toSet = to.eval(env, executor); // Algorithm: // 1) compute "reachableFromX", the forward transitive closure of the "from" set; // 2) find the intersection of "reachableFromX" with the "to" set, and traverse the graph using // the reverse dependencies. This will effectively compute the intersection between the nodes // reachable from the "from" set and the reverse transitive closure of the "to" set. env.buildTransitiveClosure(fromSet, Integer.MAX_VALUE, executor); Set<QueryTarget> reachableFromX = env.getTransitiveClosure(fromSet); Set<QueryTarget> result = MoreSets.intersection(reachableFromX, toSet); Collection<QueryTarget> worklist = result; while (!worklist.isEmpty()) { Collection<QueryTarget> reverseDeps = env.getReverseDeps(worklist); worklist = Lists.newArrayList(); for (QueryTarget target : reverseDeps) { if (reachableFromX.contains(target) && result.add(target)) { worklist.add(target);/*from w ww. jav a 2 s. com*/ } } } return result; }