RegularImmutableSortedSet<E> getSubSet(int newFromIndex, int newToIndex) { if (newFromIndex == 0 && newToIndex == size()) { return this; } else if (newFromIndex < newToIndex) { return new RegularImmutableSortedSet<E>( elements.subList(newFromIndex, newToIndex), comparator); } else { return emptySet(comparator); } }
@Override protected List<String> create(String[] elements) { String[] suffix = {"f", "g"}; String[] all = new String[elements.length + suffix.length]; System.arraycopy(elements, 0, all, 0, elements.length); System.arraycopy(suffix, 0, all, elements.length, suffix.length); return ImmutableList.copyOf(all).subList(0, elements.length); } }
@Override protected List<String> create(String[] elements) { String[] prefix = {"f", "g"}; String[] all = new String[elements.length + prefix.length]; System.arraycopy(prefix, 0, all, 0, 2); System.arraycopy(elements, 0, all, 2, elements.length); return ImmutableList.copyOf(all).subList(2, elements.length + 2); } }
@Override protected List<String> create(String[] elements) { String[] prefix = {"f", "g"}; String[] suffix = {"h", "i"}; String[] all = new String[2 + elements.length + 2]; System.arraycopy(prefix, 0, all, 0, 2); System.arraycopy(elements, 0, all, 2, elements.length); System.arraycopy(suffix, 0, all, 2 + elements.length, 2); return ImmutableList.copyOf(all).subList(2, elements.length + 2); } }
/** * Returns the ancestor of the current domain at the given number of levels "higher" (rightward) * in the subdomain list. The number of levels must be non-negative, and less than {@code N-1}, * where {@code N} is the number of parts in the domain. * * <p>TODO: Reasonable candidate for addition to public API. */ private InternetDomainName ancestor(int levels) { return from(DOT_JOINER.join(parts.subList(levels, parts.size()))); }
/** * Returns the ancestor of the current domain at the given number of levels "higher" (rightward) * in the subdomain list. The number of levels must be non-negative, and less than {@code N-1}, * where {@code N} is the number of parts in the domain. * * <p>TODO: Reasonable candidate for addition to public API. */ private InternetDomainName ancestor(int levels) { return from(DOT_JOINER.join(parts.subList(levels, parts.size()))); }
private static ImmutableList<String> sortedNumberNames(int i, int j) { return ImmutableList.copyOf(SORTED_NUMBER_NAMES.subList(i, j)); }
private ImmutableSortedMap<K, V> getSubMap(int fromIndex, int toIndex) { if (fromIndex == 0 && toIndex == size()) { return this; } else if (fromIndex == toIndex) { return emptyMap(comparator()); } else { return new ImmutableSortedMap<>( keySet.getSubSet(fromIndex, toIndex), valueList.subList(fromIndex, toIndex)); } }
private static ImmutableList<ErrorProneToken> getTokensAfterOpeningBrace( ImmutableList<ErrorProneToken> tokens) { for (int i = 0; i < tokens.size() - 1; ++i) { if (tokens.get(i).kind() == TokenKind.LBRACE) { return tokens.subList(i + 1, tokens.size()); } } return ImmutableList.of(); } }
/** * Returns the index of the leftmost part of the suffix, or -1 if not found. Note that the value * defined as a suffix may not produce {@code true} results from {@link #isPublicSuffix()} or * {@link #isRegistrySuffix()} if the domain ends with an excluded domain pattern such as {@code * "nhs.uk"}. * * <p>If a {@code desiredType} is specified, this method only finds suffixes of the given type. * Otherwise, it finds the first suffix of any type. */ private int findSuffixOfType(Optional<PublicSuffixType> desiredType) { final int partsSize = parts.size(); for (int i = 0; i < partsSize; i++) { String ancestorName = DOT_JOINER.join(parts.subList(i, partsSize)); if (matchesType( desiredType, Optional.fromNullable(PublicSuffixPatterns.EXACT.get(ancestorName)))) { return i; } // Excluded domains (e.g. !nhs.uk) use the next highest // domain as the effective public suffix (e.g. uk). if (PublicSuffixPatterns.EXCLUDED.containsKey(ancestorName)) { return i + 1; } if (matchesWildcardSuffixType(desiredType, ancestorName)) { return i; } } return NO_SUFFIX_FOUND; }
RegularImmutableSortedSet<E> getSubSet(int newFromIndex, int newToIndex) { if (newFromIndex == 0 && newToIndex == size()) { return this; } else if (newFromIndex < newToIndex) { return new RegularImmutableSortedSet<E>( elements.subList(newFromIndex, newToIndex), comparator); } else { return emptySet(comparator); } }
private TypeWithDims variableFragmentDims(boolean first, int leadingDims, Tree type) { if (type == null) { return null; } if (first) { return DimensionHelpers.extractDims(type, SortedDims.YES); } TypeWithDims dims = DimensionHelpers.extractDims(type, SortedDims.NO); return new TypeWithDims( null, leadingDims > 0 ? dims.dims.subList(0, dims.dims.size() - leadingDims) : dims.dims); }
private ImmutableSortedMap<K, V> getSubMap(int fromIndex, int toIndex) { if (fromIndex == 0 && toIndex == size()) { return this; } else if (fromIndex == toIndex) { return emptyMap(comparator()); } else { return new ImmutableSortedMap<>( keySet.getSubSet(fromIndex, toIndex), valueList.subList(fromIndex, toIndex)); } }
@Override public ImmutableList<E> subList(int fromIndex, int toIndex) { checkPositionIndexes(fromIndex, toIndex, size()); return forwardList.subList(reversePosition(toIndex), reversePosition(fromIndex)).reverse(); }
@Override protected List<String> create(String[] elements) { Comparator<String> comparator = createExplicitComparator(elements); ImmutableSortedSet.Builder<String> builder = ImmutableSortedSet.orderedBy(comparator); builder.add(BEFORE_FIRST); builder.add(elements); builder.add(AFTER_LAST); return builder.build().asList().subList(1, elements.length + 1); } }
public void testReadLines_withProcessor_stopsOnFalse() throws IOException { List<String> list = source.readLines( new LineProcessor<List<String>>() { List<String> list = Lists.newArrayList(); @Override public boolean processLine(String line) throws IOException { list.add(line); return false; } @Override public List<String> getResult() { return list; } }); if (expectedLines.isEmpty()) { assertTrue(list.isEmpty()); } else { assertEquals(expectedLines.subList(0, 1), list); } }
private Choice<List<BlockTemplateMatch>> matchesStartingAnywhere( JCBlock block, int offset, final ImmutableList<? extends StatementTree> statements, final Context context) { Choice<List<BlockTemplateMatch>> choice = Choice.none(); for (int i = 0; i < statements.size(); i++) { choice = choice.or( matchesStartingAtBeginning( block, offset + i, statements.subList(i, statements.size()), context)); } return choice.or(Choice.of(List.<BlockTemplateMatch>nil())); }
private ImmutableSortedMap<K, V> getSubMap(int fromIndex, int toIndex) { if (fromIndex == 0 && toIndex == size()) { return this; } else if (fromIndex == toIndex) { return emptyMap(comparator()); } else { return new ImmutableSortedMap<>( keySet.getSubSet(fromIndex, toIndex), valueList.subList(fromIndex, toIndex)); } }
public void testPowerSetEqualsAndHashCode_verifyAgainstHashSet() { ImmutableList<Integer> allElements = ImmutableList.of( 4233352, 3284593, 3794208, 3849533, 4013967, 2902658, 1886275, 2131109, 985872, 1843868); for (int i = 0; i < allElements.size(); i++) { Set<Integer> elements = newHashSet(allElements.subList(0, i)); Set<Set<Integer>> powerSet1 = powerSet(elements); Set<Set<Integer>> powerSet2 = powerSet(elements); new EqualsTester() .addEqualityGroup(powerSet1, powerSet2, toHashSets(powerSet1)) .addEqualityGroup(ImmutableSet.of()) .addEqualityGroup(ImmutableSet.of(9999999)) .addEqualityGroup("notASet") .testEquals(); assertEquals(toHashSets(powerSet1).hashCode(), powerSet1.hashCode()); } }
@Override protected List<String> create(String[] elements) { Comparator<String> comparator = createExplicitComparator(elements); ImmutableSortedSet.Builder<String> builder = ImmutableSortedSet.orderedBy(comparator); builder.add(BEFORE_FIRST); builder.add(BEFORE_FIRST_2); builder.add(elements); builder.add(AFTER_LAST); builder.add(AFTER_LAST_2); return builder .build() .subSet(BEFORE_FIRST_2, AFTER_LAST_2) .asList() .subList(1, elements.length + 1); } }