| 317 | } |
| 318 | }; |
| 319 | private class SubRangeMap implements RangeMap<K, V> { |
| 320 | private final Range<K> subRange; |
| 321 | |
| 322 | SubRangeMap(Range<K> subRange) { |
| 323 | this.subRange = subRange; |
| 324 | } |
| 325 | |
| 326 | @Override |
| 327 | @Nullable |
| 328 | public V get(K key) { |
| 329 | return subRange.contains(key) ? TreeRangeMap.this.get(key) : null; |
| 330 | } |
| 331 | |
| 332 | @Override |
| 333 | @Nullable |
| 334 | public Entry<Range<K>, V> getEntry(K key) { |
| 335 | if (subRange.contains(key)) { |
| 336 | Entry<Range<K>, V> entry = TreeRangeMap.this.getEntry(key); |
| 337 | if (entry != null) { |
| 338 | return Maps.immutableEntry(entry.getKey().intersection(subRange), entry.getValue()); |
| 339 | } |
| 340 | } |
| 341 | return null; |
| 342 | } |
| 343 | |
| 344 | @Override |
| 345 | public Range<K> span() { |
| 346 | Cut<K> lowerBound; |
| 347 | Entry<Cut<K>, RangeMapEntry<K, V>> lowerEntry = entriesByLowerBound.floorEntry(subRange.lowerBound); |
| 348 | if (lowerEntry != null |
| 349 | && lowerEntry.getValue().getUpperBound().compareTo(subRange.lowerBound) > 0) { |
| 350 | lowerBound = subRange.lowerBound; |
| 351 | } else { |
| 352 | lowerBound = entriesByLowerBound.ceilingKey(subRange.lowerBound); |
| 353 | if (lowerBound == null || lowerBound.compareTo(subRange.upperBound) >= 0) { |
| 354 | throw new NoSuchElementException(); |
| 355 | } |
| 356 | } |
| 357 | Cut<K> upperBound; |
| 358 | Entry<Cut<K>, RangeMapEntry<K, V>> upperEntry = entriesByLowerBound.lowerEntry(subRange.upperBound); |
| 359 | if (upperEntry == null) { |
| 360 | throw new NoSuchElementException(); |
| 361 | } else if (upperEntry.getValue().getUpperBound().compareTo(subRange.upperBound) >= 0) { |
| 362 | upperBound = subRange.upperBound; |
| 363 | } else { |
| 364 | upperBound = upperEntry.getValue().getUpperBound(); |
| 365 | } |
| 366 | return Range.create(lowerBound, upperBound); |
| 367 | } |
| 368 | |
| 369 | @Override |
| 370 | public void put(Range<K> range, V value) { |
| 371 | checkArgument(subRange.encloses(range), "Cannot put range %s into a subRangeMap(%s)", range, subRange); |
| 372 | TreeRangeMap.this.put(range, value); |
| 373 | } |
| 374 | |
| 375 | @Override |
| 376 | public void putAll(RangeMap<K, V> rangeMap) { |
nothing calls this directly
no outgoing calls
no test coverage detected