Example usage for com.google.common.collect Range closed

List of usage examples for com.google.common.collect Range closed

Introduction

In this page you can find the example usage for com.google.common.collect Range closed.

Prototype

public static <C extends Comparable<?>> Range<C> closed(C lower, C upper) 

Source Link

Document

Returns a range that contains all values greater than or equal to lower and less than or equal to upper .

Usage

From source file:org.opendaylight.yangtools.yang.data.impl.codec.StringStringCodec.java

StringStringCodec(final StringTypeDefinition typeDef) {
    super(Optional.of(typeDef), String.class);

    final Collection<LengthConstraint> constraints = typeDef.getLengthConstraints();
    if (!constraints.isEmpty()) {
        final RangeSet<Integer> tmp = TreeRangeSet.create();
        for (LengthConstraint c : constraints) {
            tmp.add(Range.closed(c.getMin().intValue(), c.getMax().intValue()));
        }//from w w w  . j  a v a2 s. com

        lengths = ImmutableRangeSet.copyOf(tmp);
    } else {
        lengths = null;
    }
}

From source file:us.eharning.atomun.mnemonic.spi.electrum.v2.CJKCleanupUtility.java

private static RangeSet<Integer> buildRanges() {
    LineProcessor<RangeSet<Integer>> lineProcess = new LineProcessor<RangeSet<Integer>>() {
        private final RangeSet<Integer> resultBuilder = TreeRangeSet.create();

        @Override//from w w  w .ja v a  2  s. c o m
        public boolean processLine(@Nonnull String line) throws IOException {
            /* Skip comments and empty lines */
            int commentIndex = line.indexOf('#');
            if (commentIndex >= 0) {
                line = line.substring(0, commentIndex);
            }
            line = CharMatcher.WHITESPACE.trimFrom(line);
            if (line.isEmpty()) {
                return true;
            }
            /* NOTE: Assuming 0xHEX-0xHEX notation */
            int splitMarker = line.indexOf('-');
            assert splitMarker >= 0;
            int start = Integer.parseInt(line.substring(2, splitMarker), 16);
            int stop = Integer.parseInt(line.substring(splitMarker + 3), 16);
            resultBuilder.add(Range.closed(start, stop));
            return true;
        }

        @Override
        public RangeSet<Integer> getResult() {
            return ImmutableRangeSet.copyOf(resultBuilder);
        }
    };
    try {
        return Resources.readLines(MnemonicUtility.class.getResource("cjk_ranges.dat"), Charsets.UTF_8,
                lineProcess);
    } catch (IOException e) {
        throw new Error(e);
    }
}

From source file:org.apache.aurora.common.args.parsers.RangeParser.java

@Override
public Range<Integer> doParse(String raw) throws IllegalArgumentException {
    ImmutableList<String> numbers = ImmutableList.copyOf(Splitter.on('-').omitEmptyStrings().split(raw));
    try {//ww w  .  ja  v  a  2  s  . co m
        int from = Integer.parseInt(numbers.get(0));
        int to = Integer.parseInt(numbers.get(1));
        if (numbers.size() != 2) {
            throw new IllegalArgumentException("Failed to parse the range:" + raw);
        }
        if (to < from) {
            return Range.closed(to, from);
        } else {
            return Range.closed(from, to);
        }
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException("Failed to parse the range:" + raw, e);
    }
}

From source file:com.google.android.apps.forscience.whistlepunk.Arbitrary.java

public static Range<Long> longRange() {
    long a = longInteger();
    long b = longInteger();
    return Range.closed(Math.min(a, b), Math.max(a, b));
}

From source file:org.graylog2.indexer.results.HighlightParser.java

private static Set<Range<Integer>> extractRange(List<String> highlights) {
    final ImmutableSet.Builder<Range<Integer>> builder = ImmutableSet.builder();
    highlights.forEach(highlight -> {
        final Matcher matcher = highlightPattern.matcher(highlight);
        Integer count = -1;//  w w w. j a v  a2 s.  c om
        while (matcher.find()) {
            count++;
            final Integer start = matcher.start() - count * (startTokenLength + endTokenLength);
            final Integer end = start + (matcher.end(1) - matcher.start(1));
            builder.add(Range.closed(start, end));
        }
    });
    return builder.build();
}

From source file:net.sf.mzmine.parameters.parametertypes.tolerances.RTTolerance.java

public Range<Double> getToleranceRange(final double rtValue) {

    final double absoluteTolerance = isAbsolute ? tolerance : rtValue * tolerance;
    return Range.closed(rtValue - absoluteTolerance, rtValue + absoluteTolerance);
}

From source file:com.github.s4ke.moar.util.RangeRep.java

private RangeRep(int from, int to) {
    this.rangeSet = TreeRangeSet.create();
    this.rangeSet.add(Range.closed(from, to));
}

From source file:net.sf.mzmine.util.XMLUtils.java

public static Range<Double> parseDoubleRange(Element xmlElement, String tagName) {
    NodeList items = xmlElement.getElementsByTagName(tagName);
    if (items.getLength() == 0)
        return null;
    Element tag = (Element) items.item(0);
    items = tag.getElementsByTagName("min");
    if (items.getLength() == 0)
        return null;
    Element min = (Element) items.item(0);
    items = tag.getElementsByTagName("max");
    if (items.getLength() == 0)
        return null;
    Element max = (Element) items.item(0);

    String minText = min.getTextContent();
    String maxText = max.getTextContent();
    Range<Double> r = Range.closed(Double.valueOf(minText), Double.valueOf(maxText));
    return r;//from w  w w . j ava  2  s.com
}

From source file:org.sonar.java.filters.AnyRuleIssueFilter.java

private static Set<Integer> filteredLines(Tree tree) {
    SyntaxToken firstSyntaxToken = tree.firstToken();
    SyntaxToken lastSyntaxToken = tree.lastToken();
    if (firstSyntaxToken != null && lastSyntaxToken != null) {
        return ContiguousSet.create(Range.closed(firstSyntaxToken.line(), lastSyntaxToken.line()),
                DiscreteDomain.integers());
    }//from  w w  w.java 2s .  c o  m
    return new HashSet<>();
}

From source file:org.nmdp.ngs.align.GenewiseExon.java

/**
 * Create a new genewise exon./*from  w  w w.  j  av  a  2s  . c o  m*/
 *
 * @param start start, in 1-based coordinate system, fully closed range
 * @param end end, in 1-based coordinate system, fully closed range
 * @param phase phase
 */
GenewiseExon(final long start, final long end, final int phase) {
    this.start = start;
    this.end = end;
    this.phase = phase;
    range = Range.closed(start, end);
}