Java Code Examples for com.google.common.collect.TreeRangeSet#create()
The following examples show how to use
com.google.common.collect.TreeRangeSet#create() .
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: 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 3
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 4
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 5
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 6
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 7
Source File: FancierDiffLogger.java From tac-kbp-eal with MIT License | 5 votes |
private String context(final String originalDocText, final Response response) { // [1,3], [2,5], [8,10] => [1,5], [8,10] final List<CharOffsetSpan> charSpans = justificationSpans(response); final List<CharOffsetSpan> unitedSpans = Lists.newArrayList(); // use RangeSet to do this final RangeSet<Integer> disconnected = TreeRangeSet.create(); for (CharOffsetSpan charSpan : charSpans) { int startInclusive = charSpan.startInclusive(); int endInclusive = charSpan.endInclusive(); startInclusive = (startInclusive - 100) >= 0 ? startInclusive - 100 : 0; endInclusive = (endInclusive + 100) < originalDocText.length() ? endInclusive + 100 : endInclusive; disconnected.add(Range.closed(startInclusive, endInclusive)); } for (Range<Integer> range : disconnected.asRanges()) { unitedSpans.add(CharOffsetSpan.fromOffsetsOnly(range.lowerEndpoint(), range.upperEndpoint())); } Collections.sort(unitedSpans); String justificationsString = ""; if (unitedSpans.get(0).startInclusive() != 0) { justificationsString += "[.....]"; } for (CharOffsetSpan span : unitedSpans) { justificationsString += originalDocText.substring(span.startInclusive(), span.endInclusive() + 1); justificationsString += "[.....]"; } return justificationsString; }
Example 8
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 9
Source File: CrontabEntry.java From attic-aurora with Apache License 2.0 | 5 votes |
private RangeSet<Integer> parseDayOfMonth() { RangeSet<Integer> daysOfMonth = TreeRangeSet.create(); for (String component : getComponents(rawDayOfMonth)) { daysOfMonth.addAll(parseComponent(DAY_OF_MONTH, component)); } return ImmutableRangeSet.copyOf(daysOfMonth); }
Example 10
Source File: MarkerConfigXmlParser.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
private static RangeSet<Long> parseRangeSet(String rangeSetAttr) { if (rangeSetAttr.isEmpty()) { return ImmutableRangeSet.of(Range.all()); } RangeSet<Long> rangeSet = TreeRangeSet.create(); String[] ranges = rangeSetAttr.split(","); //$NON-NLS-1$ if (ranges.length == 0) { rangeSet.add(Range.all()); } else { for (String range : ranges) { rangeSet.add(parseRange(range)); } } return rangeSet; }
Example 11
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 12
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 13
Source File: DownloadRequestContext.java From rubix with Apache License 2.0 | 5 votes |
public DownloadRequestContext(String remoteFilePath, long fileSize, long lastModified) { this.remoteFilePath = remoteFilePath; this.fileSize = fileSize; this.lastModified = lastModified; this.rangeSet = TreeRangeSet.create(); }
Example 14
Source File: IdentifierPerType.java From tassal 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 15
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 16
Source File: SnippetFormatter.java From javaide with GNU General Public License v3.0 | 5 votes |
/** * Runs the Google Java formatter on the given source, with only the given ranges specified. */ public List<Replacement> format( SnippetKind kind, String source, List<Range<Integer>> ranges, int initialIndent, boolean includeComments) throws FormatterException { RangeSet<Integer> rangeSet = TreeRangeSet.create(); for (Range<Integer> range : ranges) { rangeSet.add(range); } if (includeComments) { if (kind != SnippetKind.COMPILATION_UNIT) { throw new IllegalArgumentException( "comment formatting is only supported for compilation units"); } return formatter.getFormatReplacements(source, ranges); } SnippetWrapper wrapper = snippetWrapper(kind, source, initialIndent); ranges = offsetRanges(ranges, wrapper.offset); String replacement = formatter.formatSource(wrapper.contents.toString(), ranges); replacement = replacement.substring( wrapper.offset, replacement.length() - (wrapper.contents.length() - wrapper.offset - source.length())); List<Replacement> replacements = toReplacements(source, replacement); List<Replacement> filtered = new ArrayList<>(); for (Replacement r : replacements) { if (rangeSet.encloses(r.getReplaceRange())) { filtered.add(r); } } return filtered; }
Example 17
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 18
Source File: SnippetFormatter.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
/** * Runs the Google Java formatter on the given source, with only the given ranges specified. */ public List<Replacement> format( SnippetKind kind, String source, List<Range<Integer>> ranges, int initialIndent, boolean includeComments) throws FormatterException { RangeSet<Integer> rangeSet = TreeRangeSet.create(); for (Range<Integer> range : ranges) { rangeSet.add(range); } if (includeComments) { if (kind != SnippetKind.COMPILATION_UNIT) { throw new IllegalArgumentException( "comment formatting is only supported for compilation units"); } return formatter.getFormatReplacements(source, ranges); } SnippetWrapper wrapper = snippetWrapper(kind, source, initialIndent); ranges = offsetRanges(ranges, wrapper.offset); String replacement = formatter.formatSource(wrapper.contents.toString(), ranges); replacement = replacement.substring( wrapper.offset, replacement.length() - (wrapper.contents.length() - wrapper.offset - source.length())); List<Replacement> replacements = toReplacements(source, replacement); List<Replacement> filtered = new ArrayList<>(); for (Replacement r : replacements) { if (rangeSet.encloses(r.getReplaceRange())) { filtered.add(r); } } return filtered; }
Example 19
Source File: NumberSpace.java From batfish with Apache License 2.0 | 4 votes |
/** Returns a new {@link NumberSpace} */ public final S build() { RangeSet<T> rangeSet = TreeRangeSet.<T>create(_including); rangeSet.removeAll(_excluding); return build(rangeSet); }
Example 20
Source File: TopCategoriesExtractor.java From ambiverse-nlu with Apache License 2.0 | 4 votes |
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException{ Integer runningId = RunningTimer.recordStartTime("TopCategoriesExtractor"); Language language = Language.getLanguageForString(aJCas.getDocumentLanguage()); Collection<ConceptMentionCandidate> conceptMentionCandidatesJcas = JCasUtil.select(aJCas, ConceptMentionCandidate.class); Mentions addedMentionsNE = Mentions.getNeMentionsFromJCas(aJCas); RangeSet<Integer> added_before = TreeRangeSet.create(); for (Map<Integer, Mention> innerMap : addedMentionsNE.getMentions().values()) { for (Mention m : innerMap.values()) { if (m.getCharLength() != 0) { // workaround for issue in knowner. added_before.add(Range.closed(m.getCharOffset(), m.getCharOffset() + m.getCharLength() - 1)); } } } Set<String> mentions = new HashSet<>(); for (ConceptMentionCandidate cc : conceptMentionCandidatesJcas) { if (added_before.contains(cc.getBegin()) || added_before.contains(cc.getEnd())) { continue; } mentions.add(cc.getConceptCandidate()); } Map<String, int[]> mentionTypes; try { mentionTypes = DataAccess.getCategoryIdsForMentions(mentions, language, false); } catch (EntityLinkingDataAccessException e) { throw new AnalysisEngineProcessException(e); } Set<Integer> topTypes = getTopWikipediaTypes(mentionTypes, MAX_TOP_TYPE); for (Integer typeId : topTypes) { WikiType type = new WikiType(aJCas); type.setId(typeId); type.setName(ALL_WIKIPEDIA_CATEGORY_TYPES.get(typeId).getName()); type.setKnowledgebase(ALL_WIKIPEDIA_CATEGORY_TYPES.get(typeId).getKnowledgeBase()); type.addToIndexes(); } RunningTimer.recordEndTime("TopCategoriesExtractor", runningId); }