List of usage examples for com.google.common.collect ImmutableList size
int size();
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;//from w ww. ja va 2 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.jssrc.dsl.ConditionalExpressionBuilder.java
@Nullable private Expression tryCreateTernary(ImmutableList<IfThenPair<Expression>> pairs) { if (pairs.size() != 1 || trailingElse == null) { return null; }// ww w .j av a2 s . co m IfThenPair<Expression> ifThen = Iterables.getOnlyElement(pairs); Expression predicate = ifThen.predicate; Expression consequent = ifThen.consequent; // TODO(lukes): we could support nested ternaries with little additional difficulty if (predicate.initialStatements().containsAll(consequent.initialStatements()) && predicate.initialStatements().containsAll(trailingElse.initialStatements())) { return Ternary.create(predicate, consequent, trailingElse); } return null; }
From source file:com.facebook.buck.rules.macros.OutputMacroExpander.java
@Override protected OutputMacro parse(BuildTarget target, CellPathResolver cellNames, ImmutableList<String> args) throws MacroException { if (args.size() != 1) { throw new MacroException(String.format("expected exactly one argument (found %d)", args.size())); }//from www .j a v a2 s .c o m return OutputMacro.of(args.get(0)); }
From source file:com.google.devtools.build.skyframe.CycleDeduper.java
/** * Returns true iff//from w ww. jav a 2 s . c o m * listA[0], listA[1], ..., listA[listA.size()] * is the same as * listB[start], listB[start+1], ..., listB[listB.size()-1], listB[0], ..., listB[start-1] */ private boolean equalsWithSingleLoopFrom(ImmutableList<T> listA, ImmutableList<T> listB, int start) { if (listA.size() != listB.size()) { return false; } int length = listA.size(); for (int i = 0; i < length; i++) { if (!listA.get(i).equals(listB.get((i + start) % length))) { return false; } } return true; }
From source file:com.facebook.buck.event.listener.SimpleConsoleEventBusListener.java
private void printLines(ImmutableList.Builder<String> lines) { // Print through the {@code DirtyPrintStreamDecorator} so printing from the simple console // is considered to dirty stderr and stdout and so it gets synchronized to avoid interlacing // output./*w w w . ja va2 s . com*/ ImmutableList<String> stringList = lines.build(); if (stringList.size() == 0) { return; } console.getStdErr().println(Joiner.on("\n").join(stringList)); }
From source file:com.facebook.buck.rules.macros.BuildTargetMacroExpander.java
@Override protected BuildTarget 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)); }// w w w. ja v a 2 s . c o m try { return BuildTargetParser.INSTANCE.parse(input.get(0), BuildTargetPatternParser.forBaseName(target.getBaseName()), cellNames); } catch (BuildTargetParseException e) { throw new MacroException(e.getMessage(), e); } }
From source file:com.google.javascript.jscomp.newtypes.FunctionType.java
/** * Unify the two types symmetrically, given that we have already instantiated * the type variables of interest in {@code f1} and {@code f2}, treating * JSType.UNKNOWN as a "hole" to be filled. * @return The unified type, or null if unification fails *//*from ww w . j a v a2 s . c o m*/ static FunctionType unifyUnknowns(FunctionType f1, FunctionType f2) { Preconditions.checkState(f1 != null || f2 != null); if (f1 == null || f2 == null) { return null; } Preconditions.checkArgument(f1.typeParameters.isEmpty()); Preconditions.checkArgument(f2.typeParameters.isEmpty()); Preconditions.checkArgument(f1.outerVarPreconditions.isEmpty()); Preconditions.checkArgument(f2.outerVarPreconditions.isEmpty()); if (f1.equals(f2)) { return f1; } ImmutableList<JSType> formals1 = f1.requiredFormals; ImmutableList<JSType> formals2 = f2.requiredFormals; if (formals1.size() != formals2.size()) { return null; } FunctionTypeBuilder builder = new FunctionTypeBuilder(); int numReqFormals = formals1.size(); for (int i = 0; i < numReqFormals; i++) { JSType t = JSType.unifyUnknowns(formals1.get(i), formals2.get(i)); if (t == null) { return null; } builder.addReqFormal(t); } formals1 = f1.optionalFormals; formals2 = f2.optionalFormals; if (formals1.size() != formals2.size()) { return null; } int numOptFormals = formals1.size(); for (int i = 0; i < numOptFormals; i++) { JSType t = JSType.unifyUnknowns(formals1.get(i), formals2.get(i)); if (t == null) { return null; } builder.addOptFormal(t); } if (f1.restFormals == null && f2.restFormals != null || f1.restFormals != null && f2.restFormals == null) { return null; } if (f1.restFormals != null) { JSType t = JSType.unifyUnknowns(f1.restFormals, f2.restFormals); if (t == null) { return null; } builder.addRestFormals(t); } JSType t = JSType.unifyUnknowns(f1.returnType, f2.returnType); if (t == null) { return null; } builder.addRetType(t); // Don't unify unknowns in nominal types; it's going to be rare. if (!Objects.equals(f1.nominalType, f2.nominalType)) { return null; } builder.addNominalType(f1.nominalType); if (!Objects.equals(f1.receiverType, f2.receiverType)) { return null; } builder.addReceiverType(f1.receiverType); return builder.buildFunction(); }
From source file:uk.q3c.krail.core.option.hierarchy.SimpleUserHierarchy.java
@Override public synchronized int lowestRank() { ImmutableList<String> ranks = ranksForCurrentUser(); return ranks.size() - 1; }
From source file:com.spectralogic.ds3cli.views.cli.GetBucketView.java
protected String[][] formatTableContents() { final ImmutableList.Builder<String[]> builder = ImmutableList.builder(); for (final Contents content : contents) { final String[] arrayEntry = new String[5]; arrayEntry[0] = nullGuard(content.getKey()); arrayEntry[1] = nullGuard(Long.toString(content.getSize())); arrayEntry[2] = nullGuard(content.getOwner().getDisplayName()); arrayEntry[3] = nullGuardFromDate(content.getLastModified(), DATE_FORMAT); arrayEntry[4] = nullGuard(content.getETag()); builder.add(arrayEntry);/*from ww w.j a v a 2 s .c om*/ } final ImmutableList<String[]> contentStrings = builder.build(); return contentStrings.toArray(new String[contentStrings.size()][]); }
From source file:com.google.errorprone.matchers.method.ParameterMatcherImpl.java
@Override protected Optional<MatchState> matchResult(ExpressionTree item, MatchState info, VisitorState state) { ImmutableList<Type> actual = ImmutableList.copyOf(info.paramTypes()); if (info.sym().isVarArgs()) { if (actual.size() < expected.size()) { return Optional.absent(); }/*ww w. jav a 2 s .c o m*/ } else if (actual.size() != expected.size()) { return Optional.absent(); } for (int i = 0; i < actual.size(); ++i) { if (!state.getTypes().isSameType(actual.get(i), expected.get(i).get(state))) { return Optional.absent(); } } return Optional.of(info); }