List of usage examples for com.google.common.collect RangeSet add
void add(Range<C> range);
From source file:org.dishevelled.bio.align.Alignments.java
/** * Return the sum of lengths of the specified ranges, after merging overlapping ranges. * * @param ranges ranges, must not be null, must not contain any null ranges, and all ranges must be [closed, open) * @return the sum of lengths of the specified ranges, after merging overlapping ranges */// w w w . jav a 2 s.com public static long length(final Iterable<Range<Long>> ranges) { checkNotNull(ranges); RangeSet<Long> rangeSet = TreeRangeSet.create(); for (Range<Long> range : ranges) { rangeSet.add(range); } long length = 0L; for (Range<Long> range : rangeSet.asRanges()) { length += length(range); } return length; }
From source file:com.rockhoppertech.music.examples.Guava.java
public static void ranges() { RangeSet<Double> set = TreeRangeSet.create(); // for (double i = 1d; i < 4d; i++) { // set.add(Range.closed(i, i + 1d)); // }/*from w w w . j a v a 2s. c o m*/ set.add(Range.closed(1d, 4d)); logger.debug("the set {}", set); set.remove(Range.closed(2.5, 3d)); logger.debug("after remove: set {}", set); RangeSet<Double> comp = set.complement(); logger.debug("after remove: set comp {}", comp); Range<Double> first = Iterables.getFirst(set.asRanges(), null); logger.debug("first {}", first); //Iterables. for (Range<Double> r : set.asRanges()) { logger.debug("iterated range {}", r); } //lowerEndpoint(); set.clear(); set.add(Range.open(1d, 4d)); comp = set.complement(); logger.debug("open comp {}", comp); }
From source file:org.jpmml.evaluator.ArgumentUtil.java
static private RangeSet<Double> parseValidRanges(DataField dataField) { RangeSet<Double> result = TreeRangeSet.create(); List<Interval> intervals = dataField.getIntervals(); for (Interval interval : intervals) { Range<Double> range = DiscretizationUtil.toRange(interval); result.add(range); }//from ww w .j av a 2 s . co m return result; }
From source file:com.google.googlejavaformat.java.Formatter.java
/** * Converts zero-indexed, [closed, open) line ranges in the given source file to character ranges. *//* w w w . j a v a 2s. co m*/ public static RangeSet<Integer> lineRangesToCharRanges(String input, RangeSet<Integer> lineRanges) { List<Integer> lines = new ArrayList<>(); Iterators.addAll(lines, Newlines.lineOffsetIterator(input)); lines.add(input.length() + 1); final RangeSet<Integer> characterRanges = TreeRangeSet.create(); for (Range<Integer> lineRange : lineRanges.subRangeSet(Range.closedOpen(0, lines.size() - 1)).asRanges()) { int lineStart = lines.get(lineRange.lowerEndpoint()); // Exclude the trailing newline. This isn't strictly necessary, but handling blank lines // as empty ranges is convenient. int lineEnd = lines.get(lineRange.upperEndpoint()) - 1; Range<Integer> range = Range.closedOpen(lineStart, lineEnd); characterRanges.add(range); } return characterRanges; }
From source file:com.google.testing.pogen.parser.template.TemplateParser.java
/** * Returns a {@link RangeSet} of indexes between the start and the end tags * for non-nested tags./*from ww w. ja v a2s.c om*/ * * @param text * the string to be parsed * @param startPattern * the regular expression of start tags to find * @param endPattern * the regular expression of end tags to find * @return the {@link RangeSet} of the indexes between the start and the end * tags * @throws TemplateParseException * if the specified template is in bad format where broken pairs * of start and end tags appear */ protected static RangeSet<Integer> getIndexRangesOfNonNestedTags(String text, Pattern startPattern, Pattern endPattern) throws TemplateParseException { RangeSet<Integer> rangeSet = TreeRangeSet.create(); List<Integer> startIndexes = getMatchedIndexes(text, startPattern); List<Integer> endIndexes = getMatchedIndexes(text, endPattern); // Check whether all start tags and end tags are paired correctly if (startIndexes.size() != endIndexes.size()) { throw new TemplateParseException( String.format("There are broken pairs of start and end tags (#start tags: %d, #end tags: %d)", startIndexes.size(), endIndexes.size())); } for (int i = 0; i < startIndexes.size(); i++) { rangeSet.add(Range.closedOpen(startIndexes.get(i), endIndexes.get(i))); } return rangeSet; }
From source file:org.mskcc.shenkers.view.GeneViewBuilder.java
public RangeSet<Integer> asClosed(RangeSet<Integer> s) { RangeSet<Integer> exons = TreeRangeSet.create(); for (Range<Integer> r : s.asRanges()) { exons.add(Range.closed(r.lowerBoundType() == BoundType.OPEN ? r.lowerEndpoint() + 1 : r.lowerEndpoint(), r.upperBoundType() == BoundType.OPEN ? r.upperEndpoint() - 1 : r.upperEndpoint())); }/*from w w w .j ava 2s .c o m*/ return exons; }
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 ww .j a va 2 s .c om*/ lengths = ImmutableRangeSet.copyOf(tmp); } else { lengths = null; } }
From source file:org.eclipse.fx.ui.controls.styledtext.internal.VerticalLineFlow.java
public RangeSet<Integer> getVisibleLines() { RangeSet<Integer> visibleLines = TreeRangeSet.create(); visibleLines.add(this.visibleLines.get()); return visibleLines .subRangeSet(Range.closedOpen(Integer.valueOf(0), Integer.valueOf(this.numberOfLines.get()))); }
From source file:org.apache.lens.server.api.driver.hooks.QueryCostBasedQueryHook.java
public RangeSet<T> parseRangeSet(String rangeStr) { if (rangeStr == null) { return null; }// w ww . j a v a2s. c o m RangeSet<T> set = TreeRangeSet.create(); for (String range : rangeStr.split("U")) { set.add(parseRange(range)); } return set; }
From source file:com.google.googlejavaformat.java.FormatFileCallable.java
private RangeSet<Integer> characterRanges(String input) { final RangeSet<Integer> characterRanges = TreeRangeSet.create(); if (parameters.lines().isEmpty() && parameters.offsets().isEmpty()) { characterRanges.add(Range.closedOpen(0, input.length())); return characterRanges; }//from ww w .ja v a 2 s . co m characterRanges.addAll(Formatter.lineRangesToCharRanges(input, parameters.lines())); for (int i = 0; i < parameters.offsets().size(); i++) { Integer length = parameters.lengths().get(i); if (length == 0) { // 0 stands for "format the line under the cursor" length = 1; } characterRanges .add(Range.closedOpen(parameters.offsets().get(i), parameters.offsets().get(i) + length)); } return characterRanges; }