List of usage examples for com.google.common.collect ImmutableList subList
@Override public ImmutableList<E> subList(int fromIndex, int toIndex)
From source file:com.google.devtools.build.docgen.RuleFamily.java
RuleFamily(ListMultimap<RuleType, RuleDocumentation> ruleTypeMap, String name) { this.name = name; this.id = normalize(name); this.binaryRules = ImmutableList.copyOf(ruleTypeMap.get(RuleType.BINARY)); this.libraryRules = ImmutableList.copyOf(ruleTypeMap.get(RuleType.LIBRARY)); this.testRules = ImmutableList.copyOf(ruleTypeMap.get(RuleType.TEST)); final ImmutableList<RuleDocumentation> otherRules = ImmutableList.copyOf(ruleTypeMap.get(RuleType.OTHER)); if (otherRules.size() >= 4) { this.otherRules1 = ImmutableList.copyOf(otherRules.subList(0, otherRules.size() / 2)); this.otherRules2 = ImmutableList.copyOf(otherRules.subList(otherRules.size() / 2, otherRules.size())); } else {//from ww w . j a v a 2 s . com this.otherRules1 = otherRules; this.otherRules2 = ImmutableList.of(); } rules = ImmutableList.<RuleDocumentation>builder().addAll(binaryRules).addAll(libraryRules) .addAll(testRules).addAll(otherRules1).addAll(otherRules2).build(); }
From source file:dagger.internal.codegen.writer.EnumWriter.java
@Override public Appendable write(Appendable appendable, Context context) throws IOException { context = context.createSubcontext(//from w w w.j a v a 2 s .co m FluentIterable.from(nestedTypeWriters).transform(new Function<TypeWriter, ClassName>() { @Override public ClassName apply(TypeWriter input) { return input.name; } }).toSet()); writeAnnotations(appendable, context); writeModifiers(appendable).append("enum ").append(name.simpleName()); Iterator<TypeName> implementedTypesIterator = implementedTypes.iterator(); if (implementedTypesIterator.hasNext()) { appendable.append(" implements "); implementedTypesIterator.next().write(appendable, context); while (implementedTypesIterator.hasNext()) { appendable.append(", "); implementedTypesIterator.next().write(appendable, context); } } appendable.append(" {"); checkState(!constantWriters.isEmpty(), "Cannot write an enum with no constants."); appendable.append('\n'); ImmutableList<ConstantWriter> constantWriterList = ImmutableList.copyOf(constantWriters.values()); for (ConstantWriter constantWriter : constantWriterList.subList(0, constantWriterList.size() - 1)) { constantWriter.write(appendable, context); appendable.append(",\n"); } constantWriterList.get(constantWriterList.size() - 1).write(appendable, context); appendable.append(";\n"); if (!fieldWriters.isEmpty()) { appendable.append('\n'); } for (VariableWriter fieldWriter : fieldWriters.values()) { fieldWriter.write(new IndentingAppendable(appendable), context).append("\n"); } for (ConstructorWriter constructorWriter : constructorWriters) { appendable.append('\n'); if (!isDefaultConstructor(constructorWriter)) { constructorWriter.write(new IndentingAppendable(appendable), context); } } for (MethodWriter methodWriter : methodWriters) { appendable.append('\n'); methodWriter.write(new IndentingAppendable(appendable), context); } for (TypeWriter nestedTypeWriter : nestedTypeWriters) { appendable.append('\n'); nestedTypeWriter.write(new IndentingAppendable(appendable), context); } appendable.append("}\n"); return appendable; }
From source file:com.google.javascript.jscomp.ScopeSubject.java
public DeclarationSubject declares(String name) { AbstractVar<?, ?> var = getVar(name); if (var == null) { ImmutableList<AbstractVar<?, ?>> declared = ImmutableList.copyOf(actual().getAllAccessibleVariables()); ImmutableList<String> names = declared.stream().map(AbstractVar::getName).collect(toImmutableList()); if (names.size() > 10) { names = ImmutableList.<String>builder().addAll(names.subList(0, 9)) .add("and " + (names.size() - 9) + " others").build(); }// w ww.j ava 2 s .c o m failWithBadResults("declares", name, "declares", Joiner.on(", ").join(names)); } return new DeclarationSubject(var); }
From source file:org.caleydo.view.bicluster.sorting.FuzzyClustering.java
public ImmutableList<IntFloat> positives(float threshold, int maxElements) { ImmutableSortedSet<IntFloat> r = memberships.tailSet(new IntFloat(Integer.MIN_VALUE, Math.abs(threshold)), true);/*from ww w.j a v a 2 s . co m*/ ImmutableList<IntFloat> l = r.asList(); if (l.size() <= maxElements || maxElements == UNBOUND_NUMBER) return l; // the lower the index the nearer to zero to less interesting return l.subList(l.size() - maxElements, l.size()); }
From source file:org.caleydo.view.bicluster.sorting.FuzzyClustering.java
public ImmutableList<IntFloat> negatives(float threshold, int maxElements) { ImmutableSortedSet<IntFloat> r = memberships.headSet(new IntFloat(Integer.MAX_VALUE, -Math.abs(threshold)), true);/*ww w .j av a 2s .c om*/ ImmutableList<IntFloat> l = r.asList(); if (l.size() <= maxElements || maxElements == UNBOUND_NUMBER) return l; // the larger the index the nearer to zero to less interesting return l.subList(0, maxElements); }
From source file:com.google.javascript.jscomp.testing.ScopeSubject.java
public DeclarationSubject declares(String name) { AbstractVar<?, ?> var = getVar(name); if (var == null) { ImmutableList<AbstractVar<?, ?>> declared = ImmutableList.copyOf(actual.getAllAccessibleVariables()); ImmutableList<String> names = declared.stream().map(AbstractVar::getName).collect(toImmutableList()); if (names.size() > 10) { names = ImmutableList.<String>builder().addAll(names.subList(0, 9)) .add("and " + (names.size() - 9) + " others").build(); }/*from www .j av a 2 s .c om*/ failWithoutActual(fact("expected to declare", name), simpleFact("but did not"), fact("did declare", Joiner.on(", ").join(names)), fact("scope was", actual)); } return new DeclarationSubject(var); }
From source file:com.facebook.buck.versions.VersionedTargetGraph.java
@Nullable @Override//from w w w . j ava 2 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; }
From source file:org.apache.james.mailetcontainer.impl.matchers.And.java
private Set<MailAddress> computeIntersection(ImmutableList<Set<MailAddress>> individualMatchedResults) { if (individualMatchedResults.size() == 0) { return ImmutableSet.of(); }//from w w w . jav a2 s. c om if (individualMatchedResults.size() == 1) { return individualMatchedResults.get(0); } return Sets.intersection(individualMatchedResults.get(0), computeIntersection(individualMatchedResults.subList(1, individualMatchedResults.size()))); }
From source file:com.facebook.buck.versions.AbstractFlavorSearchTargetNodeFinder.java
public Optional<TargetNode<?>> get(BuildTarget target) { // If this node is in the graph under the given name, return it. TargetNode<?> node = getBuildTargetIndex().get(target); if (node != null) { return Optional.of(node); }/*from w w w . j a va 2 s . c o m*/ ImmutableSet<ImmutableSet<Flavor>> flavorList = getBaseTargetFlavorMap() .get(target.getUnflavoredBuildTarget()); if (flavorList == null) { return Optional.empty(); } // 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(), "Expected to find larger flavor lists earlier in the flavor map " + "index (sizeof(%s) <= sizeof(%s))", firstMatch.size(), subsequentMatch.size()); Preconditions.checkState(firstMatch.containsAll(subsequentMatch), "Found multiple disjoint flavor matches for %s: %s and %s (from %s)", target, firstMatch, subsequentMatch, matches); } return Optional.of(Preconditions.checkNotNull(getBaseTargetIndex().get(target.withFlavors(firstMatch)), "%s missing in index", target.withFlavors(firstMatch))); } // Otherwise, return `null` to indicate this node isn't in the target graph. return Optional.empty(); }
From source file:com.palantir.atlasdb.keyvalue.impl.RemotingKeyValueService.java
@Override public ClosableIterator<RowResult<Value>> getRange(String tableName, RangeRequest range, long timestamp) { ClosableIterator<RowResult<Value>> it = super.getRange(tableName, range, timestamp); try {/*from w ww . j a va 2 s . c om*/ int pageSize = range.getBatchHint() != null ? range.getBatchHint() : 100; if (pageSize == 1) { pageSize = 2; } ImmutableList<RowResult<Value>> page = ImmutableList.copyOf(Iterators.limit(it, pageSize)); if (page.size() < pageSize) { return new RangeIterator(tableName, range, timestamp, false, page); } else { return new RangeIterator(tableName, range, timestamp, true, page.subList(0, pageSize - 1)); } } finally { it.close(); } }