An implementation of RangeMap based on a TreeMap, supporting all optional operations. Like all RangeMap implementations, this supports neither null keys nor null values. @author Louis Wasserman @since 14.0
| 51 | |
| 52 | |
| 53 | @Beta |
| 54 | @GwtIncompatible // NavigableMap |
| 55 | public final class TreeRangeMap<K extends Comparable, V> implements RangeMap<K, V> { |
| 56 | private final NavigableMap<Cut<K>, RangeMapEntry<K, V>> entriesByLowerBound; |
| 57 | |
| 58 | public static <K extends Comparable, V> TreeRangeMap<K, V> create() { |
| 59 | return new TreeRangeMap<K, V>(); |
| 60 | } |
| 61 | |
| 62 | private TreeRangeMap() { |
| 63 | this.entriesByLowerBound = Maps.newTreeMap(); |
| 64 | } |
| 65 | |
| 66 | private static final class RangeMapEntry<K extends Comparable, V> extends AbstractMapEntry<Range<K>, V> { |
| 67 | private final Range<K> range; |
| 68 | private final V value; |
| 69 | |
| 70 | RangeMapEntry(Cut<K> lowerBound, Cut<K> upperBound, V value) { |
| 71 | this(Range.create(lowerBound, upperBound), value); |
| 72 | } |
| 73 | |
| 74 | RangeMapEntry(Range<K> range, V value) { |
| 75 | this.range = range; |
| 76 | this.value = value; |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public Range<K> getKey() { |
| 81 | return range; |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public V getValue() { |
| 86 | return value; |
| 87 | } |
| 88 | |
| 89 | |
| 90 | public boolean contains(K value) { |
| 91 | return range.contains(value); |
| 92 | } |
| 93 | |
| 94 | Cut<K> getLowerBound() { |
| 95 | return range.lowerBound; |
| 96 | } |
| 97 | |
| 98 | Cut<K> getUpperBound() { |
| 99 | return range.upperBound; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | @Nullable |
| 105 | public V get(K key) { |
| 106 | Entry<Range<K>, V> entry = getEntry(key); |
| 107 | return (entry == null) ? null : entry.getValue(); |
| 108 | } |
| 109 | |
| 110 | @Override |
nothing calls this directly
no outgoing calls
no test coverage detected