Java Code Examples for com.google.common.collect.TreeRangeMap#create()
The following examples show how to use
com.google.common.collect.TreeRangeMap#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: RemoveUnusedImports.java From google-java-format with Apache License 2.0 | 7 votes |
/** Construct replacements to fix unused imports. */ private static RangeMap<Integer, String> buildReplacements( String contents, JCCompilationUnit unit, Set<String> usedNames, Multimap<String, Range<Integer>> usedInJavadoc) { RangeMap<Integer, String> replacements = TreeRangeMap.create(); for (JCImport importTree : unit.getImports()) { String simpleName = getSimpleName(importTree); if (!isUnused(unit, usedNames, usedInJavadoc, importTree, simpleName)) { continue; } // delete the import int endPosition = importTree.getEndPosition(unit.endPositions); endPosition = Math.max(CharMatcher.isNot(' ').indexIn(contents, endPosition), endPosition); String sep = Newlines.guessLineSeparator(contents); if (endPosition + sep.length() < contents.length() && contents.subSequence(endPosition, endPosition + sep.length()).toString().equals(sep)) { endPosition += sep.length(); } replacements.put(Range.closedOpen(importTree.getStartPosition(), endPosition), ""); } return replacements; }
Example 2
Source File: SomaticGVCFBlockCombiner.java From gatk with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Create {@link HomRefBlock}s which will collectively accept variants of any genotype quality * * Each individual block covers a band of tumor LODs with the splits between bands occurring at values in {@code gqPartitions}. * There will be {@code gqPartitions.size() +1} bands produced * * @param gqPartitions proposed TLOD partitions as Doubles in LOD-space * @return a list of HomRefBlocks accepting bands of genotypes qualities split at the points specified in gqPartitions */ @Override @VisibleForTesting RangeMap<Integer,Range<Integer>> parsePartitions(final List<Number> gqPartitions) { partitionPrecision = calculatePartitionPrecision(gqPartitions); Utils.nonEmpty(gqPartitions); Utils.containsNoNull(gqPartitions, "The list of TLOD partitions contains a null integer"); final RangeMap<Integer, Range<Integer>> result = TreeRangeMap.create(); int lastThreshold = Integer.MIN_VALUE; for (final Number num : gqPartitions) { final double value = num.doubleValue(); final int intThreshold = convertLODtoInt(value, partitionPrecision); result.put(Range.closedOpen(lastThreshold, intThreshold), Range.closedOpen(lastThreshold, intThreshold)); lastThreshold = intThreshold; } result.put(Range.closedOpen(lastThreshold, Integer.MAX_VALUE), Range.closedOpen(lastThreshold, Integer.MAX_VALUE)); return result; }
Example 3
Source File: GuavaRangeMapUnitTest.java From tutorials with MIT License | 6 votes |
@Test public void givenRangeMap_whenSubRangeMapIsCalled_returnsSubRangeSucessfully() { final RangeMap<Integer, String> experienceRangeDesignationMap = TreeRangeMap.create(); experienceRangeDesignationMap.put(Range.closed(0, 2), "Associate"); experienceRangeDesignationMap.put(Range.closed(3, 5), "Senior Associate"); experienceRangeDesignationMap.put(Range.closed(6, 8), "Vice President"); experienceRangeDesignationMap.put(Range.closed(8, 15), "Executive Director"); experienceRangeDesignationMap.put(Range.closed(16, 30), "Managing Director"); final RangeMap<Integer, String> experiencedSubRangeDesignationMap = experienceRangeDesignationMap.subRangeMap(Range.closed(4, 14)); assertNull(experiencedSubRangeDesignationMap.get(3)); assertTrue(experiencedSubRangeDesignationMap.asMapOfRanges().values() .containsAll(Arrays.asList("Executive Director", "Vice President", "Executive Director"))); }
Example 4
Source File: GuavaRangeMapUnitTest.java From tutorials with MIT License | 6 votes |
@Test public void givenRangeMap_whenRemoveRangeIsCalled_removesSucessfully() { final RangeMap<Integer, String> experienceRangeDesignationMap = TreeRangeMap.create(); experienceRangeDesignationMap.put(Range.closed(0, 2), "Associate"); experienceRangeDesignationMap.put(Range.closed(3, 5), "Senior Associate"); experienceRangeDesignationMap.put(Range.closed(6, 8), "Vice President"); experienceRangeDesignationMap.put(Range.closed(9, 15), "Executive Director"); experienceRangeDesignationMap.put(Range.closed(16, 30), "Managing Director"); experienceRangeDesignationMap.remove(Range.closed(8, 15)); experienceRangeDesignationMap.remove(Range.closed(20, 26)); assertNull(experienceRangeDesignationMap.get(9)); assertEquals("Managing Director", experienceRangeDesignationMap.get(16)); assertEquals("Managing Director", experienceRangeDesignationMap.get(30)); assertNull(experienceRangeDesignationMap.get(25)); }
Example 5
Source File: MutableDistribution.java From java-monitoring-client-library with Apache License 2.0 | 6 votes |
/** Constructs an empty Distribution with the specified {@link DistributionFitter}. */ public MutableDistribution(DistributionFitter distributionFitter) { this.distributionFitter = checkNotNull(distributionFitter); ImmutableSortedSet<Double> boundaries = distributionFitter.boundaries(); checkArgument(boundaries.size() > 0); checkArgument(Ordering.natural().isOrdered(boundaries)); this.intervalCounts = TreeRangeMap.create(); double[] boundariesArray = Doubles.toArray(distributionFitter.boundaries()); // Add underflow and overflow intervals this.intervalCounts.put(Range.lessThan(boundariesArray[0]), 0L); this.intervalCounts.put(Range.atLeast(boundariesArray[boundariesArray.length - 1]), 0L); // Add finite intervals for (int i = 1; i < boundariesArray.length; i++) { this.intervalCounts.put(Range.closedOpen(boundariesArray[i - 1], boundariesArray[i]), 0L); } }
Example 6
Source File: RegionManager.java From tikv-client-lib-java with Apache License 2.0 | 5 votes |
public RegionCache(ReadOnlyPDClient pdClient) { regionCache = new HashMap<>(); storeCache = new HashMap<>(); keyToRegionIdCache = TreeRangeMap.create(); this.pdClient = pdClient; }
Example 7
Source File: RegionManager.java From client-java with Apache License 2.0 | 5 votes |
public RegionCache(ReadOnlyPDClient pdClient) { regionCache = new HashMap<>(); storeCache = new HashMap<>(); keyToRegionIdCache = TreeRangeMap.create(); this.pdClient = pdClient; }
Example 8
Source File: GVCFBlockCombiner.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Create {@link HomRefBlock}s which will collectively accept variants of any genotype quality * * Each individual block covers a band of genotype qualities with the splits between bands occurring at values in {@code gqPartitions}. * There will be {@code gqPartitions.size() +1} bands produced covering the entire possible range of genotype qualities from 0 to {@link VCFConstants#MAX_GENOTYPE_QUAL}. * * Note that this has to return a RangeMap with concrete types because Numbers aren't Comparable * * @param gqPartitions proposed GQ partitions * @return a list of HomRefBlocks accepting bands of genotypes qualities split at the points specified in gqPartitions */ @VisibleForTesting RangeMap<Integer,Range<Integer>> parsePartitions(final List<Number> gqPartitions) { Utils.nonEmpty(gqPartitions); Utils.containsNoNull(gqPartitions, "The list of GQ partitions contains a null integer"); final RangeMap<Integer, Range<Integer>> result = TreeRangeMap.create(); int lastThreshold = 0; for (final Number num : gqPartitions) { final int value = num.intValue(); if (value < 0) { throw new IllegalArgumentException("The list of GQ partitions contains a non-positive integer."); } else if (value > MAX_GENOTYPE_QUAL + 1) { throw new IllegalArgumentException(String.format("The value %d in the list of GQ partitions is greater than VCFConstants.MAX_GENOTYPE_QUAL + 1 = %d.", value, MAX_GENOTYPE_QUAL + 1)); } else if (value < lastThreshold) { throw new IllegalArgumentException(String.format("The list of GQ partitions is out of order. Previous value is %d but the next is %d.", lastThreshold, value)); } else if (value == lastThreshold) { throw new IllegalArgumentException(String.format("The value %d appears more than once in the list of GQ partitions.", value)); } result.put(Range.closedOpen(lastThreshold, value), Range.closedOpen(lastThreshold, value)); lastThreshold = value; } if (lastThreshold <= MAX_GENOTYPE_QUAL) { result.put(Range.closedOpen(lastThreshold, MAX_GENOTYPE_QUAL + 1), Range.closedOpen(lastThreshold,MAX_GENOTYPE_QUAL + 1)); } return result; }
Example 9
Source File: DescriptionBasedDiff.java From Refaster with Apache License 2.0 | 5 votes |
private DescriptionBasedDiff(JCCompilationUnit compilationUnit) { this.compilationUnit = checkNotNull(compilationUnit); this.sourcePath = compilationUnit.getSourceFile().toUri().getPath(); this.importsToAdd = new HashSet<>(); this.importsToRemove = new HashSet<>(); this.endPosMap = JDKCompatible.getEndPosMap(compilationUnit); this.replacements = TreeRangeMap.create(); }
Example 10
Source File: RangeMapExample.java From levelup-java-examples with Apache License 2.0 | 5 votes |
@Test public void google_guava_range_map_example () { RangeMap<Integer, String> gradeScale = TreeRangeMap.create(); gradeScale.put(Range.closed(0, 60), "F"); gradeScale.put(Range.closed(61, 70), "D"); gradeScale.put(Range.closed(71, 80), "C"); gradeScale.put(Range.closed(81, 90), "B"); gradeScale.put(Range.closed(91, 100), "A"); String grade = gradeScale.get(77); assertEquals("C", grade); }
Example 11
Source File: AssertJGuavaUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenRangeMap_whenVerifying_thenShouldBeCorrect() throws Exception { final TreeRangeMap<Integer, String> map = TreeRangeMap.create(); map.put(Range.closed(0, 60), "F"); map.put(Range.closed(61, 70), "D"); assertThat(map).isNotEmpty().containsKeys(0).contains(MapEntry.entry(34, "F")); }
Example 12
Source File: GuavaRangeMapUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenRangeMap_whenQueryWithinRange_returnsSucessfully() { final RangeMap<Integer, String> experienceRangeDesignationMap = TreeRangeMap.create(); experienceRangeDesignationMap.put(Range.closed(0, 2), "Associate"); experienceRangeDesignationMap.put(Range.closed(3, 5), "Senior Associate"); experienceRangeDesignationMap.put(Range.closed(6, 8), "Vice President"); experienceRangeDesignationMap.put(Range.closed(9, 15), "Executive Director"); experienceRangeDesignationMap.put(Range.closed(16, 30), "Managing Director"); assertEquals("Vice President", experienceRangeDesignationMap.get(6)); assertEquals("Executive Director", experienceRangeDesignationMap.get(15)); }
Example 13
Source File: GuavaRangeMapUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenRangeMap_whenQueryOutsideRange_returnsNull() { final RangeMap<Integer, String> experienceRangeDesignationMap = TreeRangeMap.create(); experienceRangeDesignationMap.put(Range.closed(0, 2), "Associate"); experienceRangeDesignationMap.put(Range.closed(3, 5), "Senior Associate"); experienceRangeDesignationMap.put(Range.closed(6, 8), "Vice President"); experienceRangeDesignationMap.put(Range.closed(9, 15), "Executive Director"); experienceRangeDesignationMap.put(Range.closed(16, 30), "Managing Director"); assertNull(experienceRangeDesignationMap.get(31)); }
Example 14
Source File: GuavaRangeMapUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenRangeMap_whenSpanIsCalled_returnsSucessfully() { final RangeMap<Integer, String> experienceRangeDesignationMap = TreeRangeMap.create(); experienceRangeDesignationMap.put(Range.closed(0, 2), "Associate"); experienceRangeDesignationMap.put(Range.closed(3, 5), "Senior Associate"); experienceRangeDesignationMap.put(Range.closed(6, 8), "Vice President"); experienceRangeDesignationMap.put(Range.closed(9, 15), "Executive Director"); experienceRangeDesignationMap.put(Range.closed(16, 30), "Managing Director"); final Range<Integer> experienceSpan = experienceRangeDesignationMap.span(); assertEquals(0, experienceSpan.lowerEndpoint().intValue()); assertEquals(30, experienceSpan.upperEndpoint().intValue()); }
Example 15
Source File: MetricRetention.java From graphouse with Apache License 2.0 | 4 votes |
private MetricRetention(String function) { this.function = function; this.ranges = TreeRangeMap.create(); }
Example 16
Source File: ModifierOrderer.java From javaide with GNU General Public License v3.0 | 4 votes |
/** * Reorders all modifiers in the given text and within the given character ranges to be in JLS * order. */ static JavaInput reorderModifiers(JavaInput javaInput, Collection<Range<Integer>> characterRanges) throws FormatterException { if (javaInput.getTokens().isEmpty()) { // There weren't any tokens, possible because of a lexing error. // Errors about invalid input will be reported later after parsing. return javaInput; } RangeSet<Integer> tokenRanges = javaInput.characterRangesToTokenRanges(characterRanges); Iterator<? extends Token> it = javaInput.getTokens().iterator(); TreeRangeMap<Integer, String> replacements = TreeRangeMap.create(); while (it.hasNext()) { Token token = it.next(); if (!tokenRanges.contains(token.getTok().getIndex())) { continue; } Modifier mod = asModifier(token); if (mod == null) { continue; } List<Token> modifierTokens = new ArrayList<>(); List<Modifier> mods = new ArrayList<>(); int begin = token.getTok().getPosition(); mods.add(mod); modifierTokens.add(token); int end = -1; while (it.hasNext()) { token = it.next(); mod = asModifier(token); if (mod == null) { break; } mods.add(mod); modifierTokens.add(token); end = token.getTok().getPosition() + token.getTok().length(); } if (!Ordering.natural().isOrdered(mods)) { Collections.sort(mods); StringBuilder replacement = new StringBuilder(); for (int i = 0; i < mods.size(); i++) { if (i > 0) { addTrivia(replacement, modifierTokens.get(i).getToksBefore()); } replacement.append(mods.get(i).toString()); if (i < (modifierTokens.size() - 1)) { addTrivia(replacement, modifierTokens.get(i).getToksAfter()); } } replacements.put(Range.closedOpen(begin, end), replacement.toString()); } } return applyReplacements(javaInput, replacements); }
Example 17
Source File: MoreMaps.java From vjtools with Apache License 2.0 | 4 votes |
/** * 以Guava TreeRangeMap实现的, 一段范围的Key指向同一个Value的Map */ @SuppressWarnings("rawtypes") public static <K extends Comparable, V> TreeRangeMap<K, V> createRangeMap() { return TreeRangeMap.create(); }
Example 18
Source File: ModifierOrderer.java From google-java-format with Apache License 2.0 | 4 votes |
/** * Reorders all modifiers in the given text and within the given character ranges to be in JLS * order. */ static JavaInput reorderModifiers(JavaInput javaInput, Collection<Range<Integer>> characterRanges) throws FormatterException { if (javaInput.getTokens().isEmpty()) { // There weren't any tokens, possible because of a lexing error. // Errors about invalid input will be reported later after parsing. return javaInput; } RangeSet<Integer> tokenRanges = javaInput.characterRangesToTokenRanges(characterRanges); Iterator<? extends Token> it = javaInput.getTokens().iterator(); TreeRangeMap<Integer, String> replacements = TreeRangeMap.create(); while (it.hasNext()) { Token token = it.next(); if (!tokenRanges.contains(token.getTok().getIndex())) { continue; } Modifier mod = asModifier(token); if (mod == null) { continue; } List<Token> modifierTokens = new ArrayList<>(); List<Modifier> mods = new ArrayList<>(); int begin = token.getTok().getPosition(); mods.add(mod); modifierTokens.add(token); int end = -1; while (it.hasNext()) { token = it.next(); mod = asModifier(token); if (mod == null) { break; } mods.add(mod); modifierTokens.add(token); end = token.getTok().getPosition() + token.getTok().length(); } if (!Ordering.natural().isOrdered(mods)) { Collections.sort(mods); StringBuilder replacement = new StringBuilder(); for (int i = 0; i < mods.size(); i++) { if (i > 0) { addTrivia(replacement, modifierTokens.get(i).getToksBefore()); } replacement.append(mods.get(i).toString()); if (i < (modifierTokens.size() - 1)) { addTrivia(replacement, modifierTokens.get(i).getToksAfter()); } } replacements.put(Range.closedOpen(begin, end), replacement.toString()); } } return applyReplacements(javaInput, replacements); }
Example 19
Source File: MoreMaps.java From vjtools with Apache License 2.0 | 4 votes |
/** * 以Guava TreeRangeMap实现的, 一段范围的Key指向同一个Value的Map */ @SuppressWarnings("rawtypes") public static <K extends Comparable, V> TreeRangeMap<K, V> createRangeMap() { return TreeRangeMap.create(); }
Example 20
Source File: ModifierOrderer.java From java-n-IDE-for-Android with Apache License 2.0 | 4 votes |
/** * Reorders all modifiers in the given text and within the given character ranges to be in JLS * order. */ static JavaInput reorderModifiers(JavaInput javaInput, Collection<Range<Integer>> characterRanges) throws FormatterException { if (javaInput.getTokens().isEmpty()) { // There weren't any tokens, possible because of a lexing error. // Errors about invalid input will be reported later after parsing. return javaInput; } RangeSet<Integer> tokenRanges = javaInput.characterRangesToTokenRanges(characterRanges); Iterator<? extends Token> it = javaInput.getTokens().iterator(); TreeRangeMap<Integer, String> replacements = TreeRangeMap.create(); while (it.hasNext()) { Token token = it.next(); if (!tokenRanges.contains(token.getTok().getIndex())) { continue; } Modifier mod = asModifier(token); if (mod == null) { continue; } List<Token> modifierTokens = new ArrayList<>(); List<Modifier> mods = new ArrayList<>(); int begin = token.getTok().getPosition(); mods.add(mod); modifierTokens.add(token); int end = -1; while (it.hasNext()) { token = it.next(); mod = asModifier(token); if (mod == null) { break; } mods.add(mod); modifierTokens.add(token); end = token.getTok().getPosition() + token.getTok().length(); } if (!Ordering.natural().isOrdered(mods)) { Collections.sort(mods); StringBuilder replacement = new StringBuilder(); for (int i = 0; i < mods.size(); i++) { if (i > 0) { addTrivia(replacement, modifierTokens.get(i).getToksBefore()); } replacement.append(mods.get(i).toString()); if (i < (modifierTokens.size() - 1)) { addTrivia(replacement, modifierTokens.get(i).getToksAfter()); } } replacements.put(Range.closedOpen(begin, end), replacement.toString()); } } return applyReplacements(javaInput, replacements); }