Java Code Examples for com.google.common.collect.Range#canonical()

The following examples show how to use com.google.common.collect.Range#canonical() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RangeMatcherBuilder.java    From grappa with Apache License 2.0 6 votes vote down vote up
private static Range<Integer> normalizeRange(final Range<Integer> range)
{
    Range<Integer> newRange = AT_LEAST_ZERO.intersection(range);

    if (newRange.isEmpty())
        throw new IllegalArgumentException("illegal range " + range
            + ": intersection with " + AT_LEAST_ZERO + " is empty");

    newRange = newRange.canonical(DiscreteDomain.integers());

    final int lowerBound = newRange.lowerEndpoint();

    return newRange.hasUpperBound()
        ? Range.closed(lowerBound, newRange.upperEndpoint() - 1)
        : Range.atLeast(lowerBound);
}
 
Example 2
Source File: JavaInput.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public RangeSet<Integer> characterRangesToTokenRanges(Collection<Range<Integer>> characterRanges)
        throws FormatterException {
    RangeSet<Integer> tokenRangeSet = TreeRangeSet.create();
    for (Range<Integer> characterRange0 : characterRanges) {
        Range<Integer> characterRange = characterRange0.canonical(DiscreteDomain.integers());
        tokenRangeSet.add(
                characterRangeToTokenRange(
                        characterRange.lowerEndpoint(),
                        characterRange.upperEndpoint() - characterRange.lowerEndpoint()));
    }
    return tokenRangeSet;
}
 
Example 3
Source File: JavaInput.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public RangeSet<Integer> characterRangesToTokenRanges(Collection<Range<Integer>> characterRanges)
        throws FormatterException {
    RangeSet<Integer> tokenRangeSet = TreeRangeSet.create();
    for (Range<Integer> characterRange0 : characterRanges) {
        Range<Integer> characterRange = characterRange0.canonical(DiscreteDomain.integers());
        tokenRangeSet.add(
                characterRangeToTokenRange(
                        characterRange.lowerEndpoint(),
                        characterRange.upperEndpoint() - characterRange.lowerEndpoint()));
    }
    return tokenRangeSet;
}
 
Example 4
Source File: JavaInput.java    From google-java-format with Apache License 2.0 5 votes vote down vote up
public RangeSet<Integer> characterRangesToTokenRanges(Collection<Range<Integer>> characterRanges)
    throws FormatterException {
  RangeSet<Integer> tokenRangeSet = TreeRangeSet.create();
  for (Range<Integer> characterRange0 : characterRanges) {
    Range<Integer> characterRange = characterRange0.canonical(DiscreteDomain.integers());
    tokenRangeSet.add(
        characterRangeToTokenRange(
            characterRange.lowerEndpoint(),
            characterRange.upperEndpoint() - characterRange.lowerEndpoint()));
  }
  return tokenRangeSet;
}
 
Example 5
Source File: SnippetFormatter.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
private static Range<Integer> offsetRange(Range<Integer> range, int offset) {
    range = range.canonical(DiscreteDomain.integers());
    return Range.closedOpen(range.lowerEndpoint() + offset, range.upperEndpoint() + offset);
}
 
Example 6
Source File: SnippetFormatter.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
private static Range<Integer> offsetRange(Range<Integer> range, int offset) {
    range = range.canonical(DiscreteDomain.integers());
    return Range.closedOpen(range.lowerEndpoint() + offset, range.upperEndpoint() + offset);
}
 
Example 7
Source File: SnippetFormatter.java    From google-java-format with Apache License 2.0 4 votes vote down vote up
private static Range<Integer> offsetRange(Range<Integer> range, int offset) {
  range = range.canonical(DiscreteDomain.integers());
  return Range.closedOpen(range.lowerEndpoint() + offset, range.upperEndpoint() + offset);
}