com.google.common.collect.TreeRangeSet Java Examples
The following examples show how to use
com.google.common.collect.TreeRangeSet.
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: DateRangeRules.java From Quicksql with MIT License | 6 votes |
private RexNode compareFloorCeil(SqlKind comparison, RexNode operand, RexLiteral timeLiteral, TimeUnitRange timeUnit, boolean floor) { RangeSet<Calendar> rangeSet = operandRanges.get(operand); if (rangeSet == null) { rangeSet = ImmutableRangeSet.<Calendar>of().complement(); } final RangeSet<Calendar> s2 = TreeRangeSet.create(); final Calendar c = timestampValue(timeLiteral); final Range<Calendar> range = floor ? floorRange(timeUnit, comparison, c) : ceilRange(timeUnit, comparison, c); s2.add(range); // Intersect old range set with new. s2.removeAll(rangeSet.complement()); operandRanges.put(operand, ImmutableRangeSet.copyOf(s2)); if (range.isEmpty()) { return rexBuilder.makeLiteral(false); } return toRex(operand, range); }
Example #2
Source File: AbstractConsoleEventBusListener.java From buck with Apache License 2.0 | 6 votes |
/** * Get the summed elapsed time from all matched event pairs. Does not consider unmatched event * pairs. Pairs are determined by their {@link com.facebook.buck.event.EventKey}. * * @param eventIntervals a set of paired events (incomplete events are okay). * @return the sum of all times between matched event pairs. */ protected static long getTotalCompletedTimeFromEventIntervals( Collection<EventInterval> eventIntervals) { long totalTime = 0L; // Flatten the event groupings into a timeline, so that we don't over count parallel work. RangeSet<Long> timeline = TreeRangeSet.create(); for (EventInterval pair : eventIntervals) { if (pair.isComplete() && pair.getElapsedTimeMs() > 0) { timeline.add(Range.open(pair.getStartTime(), pair.getEndTime())); } } for (Range<Long> range : timeline.asRanges()) { totalTime += range.upperEndpoint() - range.lowerEndpoint(); } return totalTime; }
Example #3
Source File: FieldUtil.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 6 votes |
static private <F extends Field<F> & HasContinuousDomain<F>> RangeSet<Double> parseValidRanges(F field){ RangeSet<Double> result = TreeRangeSet.create(); if(field.hasIntervals()){ List<Interval> intervals = field.getIntervals(); for(Interval interval : intervals){ Range<Double> range = DiscretizationUtil.toRange(interval); result.add(range); } } return result; }
Example #4
Source File: DateRangeRules.java From calcite with Apache License 2.0 | 6 votes |
private RexNode compareFloorCeil(SqlKind comparison, RexNode operand, RexLiteral timeLiteral, TimeUnitRange timeUnit, boolean floor) { RangeSet<Calendar> rangeSet = operandRanges.get(operand); if (rangeSet == null) { rangeSet = ImmutableRangeSet.<Calendar>of().complement(); } final RangeSet<Calendar> s2 = TreeRangeSet.create(); final Calendar c = timestampValue(timeLiteral); final Range<Calendar> range = floor ? floorRange(timeUnit, comparison, c) : ceilRange(timeUnit, comparison, c); s2.add(range); // Intersect old range set with new. s2.removeAll(rangeSet.complement()); operandRanges.put(operand, ImmutableRangeSet.copyOf(s2)); if (range.isEmpty()) { return rexBuilder.makeLiteral(false); } return toRex(operand, range); }
Example #5
Source File: Networking.java From brooklyn-server with Apache License 2.0 | 6 votes |
public static RangeSet<Integer> portRulesToRanges(Collection<String> portRules) { RangeSet<Integer> result = TreeRangeSet.create(); for (String portRule : portRules) { if (portRule.contains("-")) { String[] fromTo = portRule.split("-"); checkArgument(fromTo.length == 2, "Invalid port range '%s'", portRule); checkArgument(Strings.countOccurrences(portRule, '-') == 1, "Invalid port range '%s'", portRule); checkArgument(Strings.isNonEmpty(fromTo[0]), "Invalid port range '%s'", portRule); checkArgument(Strings.isNonEmpty(fromTo[1]), "Invalid port range '%s'", portRule); result.add(closedRange(fromTo[0], fromTo[1])); } else { result.add(closedRange(portRule, portRule)); } } return result; }
Example #6
Source File: Formatter.java From google-java-format with Apache License 2.0 | 6 votes |
/** * Converts zero-indexed, [closed, open) line ranges in the given source file to character ranges. */ 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; }
Example #7
Source File: RemoveUnusedImports.java From google-java-format with Apache License 2.0 | 6 votes |
/** Applies the replacements to the given source, and re-format any edited javadoc. */ private static String applyReplacements(String source, RangeMap<Integer, String> replacements) { // save non-empty fixed ranges for reformatting after fixes are applied RangeSet<Integer> fixedRanges = TreeRangeSet.create(); // Apply the fixes in increasing order, adjusting ranges to account for // earlier fixes that change the length of the source. The output ranges are // needed so we can reformat fixed regions, otherwise the fixes could just // be applied in descending order without adjusting offsets. StringBuilder sb = new StringBuilder(source); int offset = 0; for (Map.Entry<Range<Integer>, String> replacement : replacements.asMapOfRanges().entrySet()) { Range<Integer> range = replacement.getKey(); String replaceWith = replacement.getValue(); int start = offset + range.lowerEndpoint(); int end = offset + range.upperEndpoint(); sb.replace(start, end, replaceWith); if (!replaceWith.isEmpty()) { fixedRanges.add(Range.closedOpen(start, end)); } offset += replaceWith.length() - (range.upperEndpoint() - range.lowerEndpoint()); } return sb.toString(); }
Example #8
Source File: ConcurrentOpenLongPairRangeSetTest.java From pulsar with Apache License 2.0 | 6 votes |
@Test public void testSpanWithGuava() { ConcurrentOpenLongPairRangeSet<LongPair> set = new ConcurrentOpenLongPairRangeSet<>(consumer); com.google.common.collect.RangeSet<LongPair> gSet = TreeRangeSet.create(); set.add(Range.openClosed(new LongPair(0, 97), new LongPair(0, 99))); gSet.add(Range.openClosed(new LongPair(0, 97), new LongPair(0, 99))); set.add(Range.openClosed(new LongPair(0, 99), new LongPair(1, 5))); gSet.add(Range.openClosed(new LongPair(0, 99), new LongPair(1, 5))); assertEquals(set.span(), gSet.span()); assertEquals(set.span(), Range.openClosed(new LongPair(0, 97), new LongPair(1, 5))); set.add(Range.openClosed(new LongPair(1, 9), new LongPair(1, 15))); set.add(Range.openClosed(new LongPair(1, 19), new LongPair(2, 10))); set.add(Range.openClosed(new LongPair(2, 24), new LongPair(2, 28))); set.add(Range.openClosed(new LongPair(3, 11), new LongPair(3, 20))); set.add(Range.openClosed(new LongPair(4, 11), new LongPair(4, 20))); gSet.add(Range.openClosed(new LongPair(1, 9), new LongPair(1, 15))); gSet.add(Range.openClosed(new LongPair(1, 19), new LongPair(2, 10))); gSet.add(Range.openClosed(new LongPair(2, 24), new LongPair(2, 28))); gSet.add(Range.openClosed(new LongPair(3, 11), new LongPair(3, 20))); gSet.add(Range.openClosed(new LongPair(4, 11), new LongPair(4, 20))); assertEquals(set.span(), gSet.span()); assertEquals(set.span(), Range.openClosed(new LongPair(0, 97), new LongPair(4, 20))); }
Example #9
Source File: TokenConceptAbstractQueryGenerator.java From bioasq with Apache License 2.0 | 6 votes |
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { Collection<Concept> concepts = TypeUtil.getConcepts(jcas); List<QueryConcept> qconcepts = ConceptAbstractQueryGenerator .createQueryConceptsFromConceptMentions(jcas, concepts, useType, useWeight); // filter tokens that are covered by concept mentions RangeSet<Integer> cmentionRanges = TreeRangeSet.create(); concepts.stream().map(TypeUtil::getConceptMentions).flatMap(Collection::stream) .map(cmention -> Range.closedOpen(cmention.getBegin(), cmention.getEnd())) .forEach(cmentionRanges::add); // create an aquery using all tokens with POS in posTags set List<Token> tokens = TypeUtil.getOrderedTokens(jcas).stream().filter(token -> !cmentionRanges .encloses(Range.closedOpen(token.getBegin(), token.getEnd()))).collect(toList()); List<QueryConcept> qconceptTokens = TokenSelectionAbstractQueryGenerator .createQueryConceptsFromTokens(jcas, tokens, posTags, stoplist); qconceptTokens.addAll(qconcepts); AbstractQuery aquery = TypeFactory.createAbstractQuery(jcas, qconceptTokens); aquery.addToIndexes(); // create a backup aquery using only nouns List<QueryConcept> qconceptNouns = TokenSelectionAbstractQueryGenerator .createQueryConceptsFromTokens(jcas, tokens, nounTags, stoplist); qconceptNouns.addAll(qconcepts); AbstractQuery aqueryNoun = TypeFactory.createAbstractQuery(jcas, qconceptNouns); aqueryNoun.addToIndexes(); }
Example #10
Source File: DateRangeRules.java From Bats with Apache License 2.0 | 6 votes |
private RexNode compareFloorCeil(SqlKind comparison, RexNode operand, RexLiteral timeLiteral, TimeUnitRange timeUnit, boolean floor) { RangeSet<Calendar> rangeSet = operandRanges.get(operand); if (rangeSet == null) { rangeSet = ImmutableRangeSet.<Calendar> of().complement(); } final RangeSet<Calendar> s2 = TreeRangeSet.create(); final Calendar c = timestampValue(timeLiteral); final Range<Calendar> range = floor ? floorRange(timeUnit, comparison, c) : ceilRange(timeUnit, comparison, c); s2.add(range); // Intersect old range set with new. s2.removeAll(rangeSet.complement()); operandRanges.put(operand, ImmutableRangeSet.copyOf(s2)); if (range.isEmpty()) { return rexBuilder.makeLiteral(false); } return toRex(operand, range); }
Example #11
Source File: Formatter.java From java-n-IDE-for-Android with Apache License 2.0 | 6 votes |
/** * Converts zero-indexed, [closed, open) line ranges in the given source file to character ranges. */ 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; }
Example #12
Source File: Formatter.java From javaide with GNU General Public License v3.0 | 6 votes |
/** * Converts zero-indexed, [closed, open) line ranges in the given source file to character ranges. */ 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; }
Example #13
Source File: DruidDateTimeUtils.java From calcite with Apache License 2.0 | 5 votes |
/** * Generates a list of {@link Interval}s equivalent to a given * expression. Assumes that all the predicates in the input * reference a single column: the timestamp column. */ @Nullable public static List<Interval> createInterval(RexNode e) { final List<Range<Long>> ranges = extractRanges(e, false); if (ranges == null) { // We did not succeed, bail out return null; } final TreeRangeSet condensedRanges = TreeRangeSet.create(); for (Range r : ranges) { condensedRanges.add(r); } LOGGER.debug("Inferred ranges on interval : {}", condensedRanges); return toInterval(ImmutableList.<Range<Long>>copyOf(condensedRanges.asRanges())); }
Example #14
Source File: AddressGroup.java From batfish with Apache License 2.0 | 5 votes |
/** * Returns a {@link com.google.common.collect.RangeSet} containing the union of all addresses * owned by members. Returns empty RangeSet if there are no members. */ public RangeSet<Ip> getIpRangeSet( Map<String, AddressObject> addressObjects, Map<String, AddressGroup> addressGroups) { RangeSet<Ip> rangeSet = TreeRangeSet.create(); getDescendantObjects(addressObjects, addressGroups, new HashSet<>()).stream() .map(addrObjName -> addressObjects.get(addrObjName).getAddressAsRangeSet()) .forEach(rangeSet::addAll); return ImmutableRangeSet.copyOf(rangeSet); }
Example #15
Source File: IdentifierPerType.java From codemining-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static final void addToMap( final Map<String, RangeSet<Integer>> identifiers, final ASTNode node, final String identifier) { final int startPosition = node.getStartPosition(); final Range<Integer> nodeRange = Range.closedOpen(startPosition, startPosition + node.getLength()); RangeSet<Integer> idRanges = identifiers.get(identifier); if (idRanges == null) { idRanges = TreeRangeSet.create(); identifiers.put(identifier, idRanges); } idRanges.add(nodeRange); }
Example #16
Source File: EncodedDiscreteResources.java From onos with Apache License 2.0 | 5 votes |
static EncodedDiscreteResources of(Set<DiscreteResource> resources, DiscreteResourceCodec codec) { RangeSet<Integer> rangeSet = TreeRangeSet.create(); resources.stream() .map(x -> x.valueAs(Object.class)) .flatMap(Tools::stream) .map(x -> codec.encode(x)) .map(Range::singleton) .map(x -> x.canonical(DiscreteDomain.integers())) .forEach(rangeSet::add); return new EncodedDiscreteResources(rangeSet, codec); }
Example #17
Source File: EncodedDiscreteResources.java From onos with Apache License 2.0 | 5 votes |
EncodedDiscreteResources difference(EncodedDiscreteResources other) { checkArgument(this.codec.getClass() == other.codec.getClass()); RangeSet<Integer> newRangeSet = TreeRangeSet.create(this.rangeSet); newRangeSet.removeAll(other.rangeSet); return new EncodedDiscreteResources(newRangeSet, this.codec); }
Example #18
Source File: EncodedDiscreteResources.java From onos with Apache License 2.0 | 5 votes |
EncodedDiscreteResources add(EncodedDiscreteResources other) { checkArgument(this.codec.getClass() == other.codec.getClass()); RangeSet<Integer> newRangeSet = TreeRangeSet.create(this.rangeSet); newRangeSet.addAll(other.rangeSet); return new EncodedDiscreteResources(newRangeSet, this.codec); }
Example #19
Source File: EncodedResourcesSerializer.java From onos with Apache License 2.0 | 5 votes |
@Override public EncodedDiscreteResources read(Kryo kryo, Input input, Class<EncodedDiscreteResources> cls) { @SuppressWarnings("unchecked") List<ClosedOpenRange> ranges = kryo.readObject(input, ArrayList.class); DiscreteResourceCodec codec = (DiscreteResourceCodec) kryo.readClassAndObject(input); RangeSet<Integer> rangeSet = TreeRangeSet.create(); ranges.stream() .map(x -> Range.closedOpen(x.lowerBound(), x.upperBound())) .forEach(rangeSet::add); return new EncodedDiscreteResources(rangeSet, codec); }
Example #20
Source File: GuavaRangeSetUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenRangeSet_whenQueryWithinRange_returnsSucessfully() { final RangeSet<Integer> numberRangeSet = TreeRangeSet.create(); numberRangeSet.add(Range.closed(0, 2)); numberRangeSet.add(Range.closed(3, 5)); numberRangeSet.add(Range.closed(6, 8)); assertTrue(numberRangeSet.contains(1)); assertFalse(numberRangeSet.contains(9)); }
Example #21
Source File: GuavaRangeSetUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenRangeSet_whenEnclosesWithinRange_returnsSucessfully() { final RangeSet<Integer> numberRangeSet = TreeRangeSet.create(); numberRangeSet.add(Range.closed(0, 2)); numberRangeSet.add(Range.closed(3, 10)); numberRangeSet.add(Range.closed(15, 18)); assertTrue(numberRangeSet.encloses(Range.closed(4, 5))); assertFalse(numberRangeSet.encloses(Range.closed(4, 11))); }
Example #22
Source File: GuavaRangeSetUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenRangeSet_whenComplementIsCalled_returnsSucessfully() { final RangeSet<Integer> numberRangeSet = TreeRangeSet.create(); numberRangeSet.add(Range.closed(0, 2)); numberRangeSet.add(Range.closed(3, 5)); numberRangeSet.add(Range.closed(6, 8)); final RangeSet<Integer> numberRangeComplementSet = numberRangeSet.complement(); assertTrue(numberRangeComplementSet.contains(-1000)); assertFalse(numberRangeComplementSet.contains(2)); assertFalse(numberRangeComplementSet.contains(3)); assertTrue(numberRangeComplementSet.contains(1000)); }
Example #23
Source File: GuavaRangeSetUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenRangeSet_whenIntersectsWithinRange_returnsSucessfully() { final RangeSet<Integer> numberRangeSet = TreeRangeSet.create(); numberRangeSet.add(Range.closed(0, 2)); numberRangeSet.add(Range.closed(3, 10)); numberRangeSet.add(Range.closed(15, 18)); assertTrue(numberRangeSet.intersects(Range.closed(4, 17))); assertFalse(numberRangeSet.intersects(Range.closed(19, 200))); }
Example #24
Source File: GuavaRangeSetUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenRangeSet_whenRemoveRangeIsCalled_removesSucessfully() { final RangeSet<Integer> numberRangeSet = TreeRangeSet.create(); numberRangeSet.add(Range.closed(0, 2)); numberRangeSet.add(Range.closed(3, 5)); numberRangeSet.add(Range.closed(6, 8)); numberRangeSet.add(Range.closed(9, 15)); numberRangeSet.remove(Range.closed(3, 5)); numberRangeSet.remove(Range.closed(7, 10)); assertTrue(numberRangeSet.contains(1)); assertFalse(numberRangeSet.contains(9)); assertTrue(numberRangeSet.contains(12)); }
Example #25
Source File: GuavaRangeSetUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenRangeSet_whenSpanIsCalled_returnsSucessfully() { final RangeSet<Integer> numberRangeSet = TreeRangeSet.create(); numberRangeSet.add(Range.closed(0, 2)); numberRangeSet.add(Range.closed(3, 5)); numberRangeSet.add(Range.closed(6, 8)); final Range<Integer> experienceSpan = numberRangeSet.span(); assertEquals(0, experienceSpan.lowerEndpoint().intValue()); assertEquals(8, experienceSpan.upperEndpoint().intValue()); }
Example #26
Source File: GuavaRangeSetUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenRangeSet_whenSubRangeSetIsCalled_returnsSubRangeSucessfully() { final RangeSet<Integer> numberRangeSet = TreeRangeSet.create(); numberRangeSet.add(Range.closed(0, 2)); numberRangeSet.add(Range.closed(3, 5)); numberRangeSet.add(Range.closed(6, 8)); final RangeSet<Integer> numberSubRangeSet = numberRangeSet.subRangeSet(Range.closed(4, 14)); assertFalse(numberSubRangeSet.contains(3)); assertFalse(numberSubRangeSet.contains(14)); assertTrue(numberSubRangeSet.contains(7)); }
Example #27
Source File: CrontabEntry.java From attic-aurora with Apache License 2.0 | 5 votes |
private RangeSet<Integer> parseMinute() { RangeSet<Integer> minutes = TreeRangeSet.create(); for (String component : getComponents(rawMinute)) { minutes.addAll(parseComponent(MINUTE, component)); } return ImmutableRangeSet.copyOf(minutes); }
Example #28
Source File: CrontabEntry.java From attic-aurora with Apache License 2.0 | 5 votes |
private RangeSet<Integer> parseHour() { RangeSet<Integer> hours = TreeRangeSet.create(); for (String component : getComponents(rawHour)) { hours.addAll(parseComponent(HOUR, component)); } return ImmutableRangeSet.copyOf(hours); }
Example #29
Source File: CrontabEntry.java From attic-aurora with Apache License 2.0 | 5 votes |
private RangeSet<Integer> parseDayOfWeek() { RangeSet<Integer> daysOfWeek = TreeRangeSet.create(); for (String component : getComponents(rawDayOfWeek)) { daysOfWeek.addAll(parseComponent(DAY_OF_WEEK, replaceNameAliases(component, DAY_NAMES))); } return ImmutableRangeSet.copyOf(daysOfWeek); }
Example #30
Source File: CrontabEntry.java From attic-aurora with Apache License 2.0 | 5 votes |
private RangeSet<Integer> parseMonth() { RangeSet<Integer> months = TreeRangeSet.create(); for (String component : getComponents(rawMonth)) { months.addAll(parseComponent(MONTH, replaceNameAliases(component, MONTH_NAMES))); } return ImmutableRangeSet.copyOf(months); }