MCPcopy
hub / github.com/google/guava / remove

Method remove

guava/src/com/google/common/collect/TreeRangeMap.java:211–259  ·  view source on GitHub ↗
(Range<K> rangeToRemove)

Source from the content-addressed store, hash-verified

209 }
210
211 @Override
212 public void remove(Range<K> rangeToRemove) {
213 if (rangeToRemove.isEmpty()) {
214 return;
215 }
216
217 /*
218 * The comments for this method will use [ ] to indicate the bounds of rangeToRemove and ( ) to
219 * indicate the bounds of ranges in the range map.
220 */
221 Entry<Cut<K>, RangeMapEntry<K, V>> mapEntryBelowToTruncate =
222 entriesByLowerBound.lowerEntry(rangeToRemove.lowerBound);
223 if (mapEntryBelowToTruncate != null) {
224 // we know ( [
225 RangeMapEntry<K, V> rangeMapEntry = mapEntryBelowToTruncate.getValue();
226 if (rangeMapEntry.getUpperBound().compareTo(rangeToRemove.lowerBound) > 0) {
227 // we know ( [ )
228 if (rangeMapEntry.getUpperBound().compareTo(rangeToRemove.upperBound) > 0) {
229 // we know ( [ ] ), so insert the range ] ) back into the map --
230 // it's being split apart
231 putRangeMapEntry(
232 rangeToRemove.upperBound,
233 rangeMapEntry.getUpperBound(),
234 mapEntryBelowToTruncate.getValue().getValue());
235 }
236 // overwrite mapEntryToTruncateBelow with a truncated range
237 putRangeMapEntry(
238 rangeMapEntry.getLowerBound(),
239 rangeToRemove.lowerBound,
240 mapEntryBelowToTruncate.getValue().getValue());
241 }
242 }
243
244 Entry<Cut<K>, RangeMapEntry<K, V>> mapEntryAboveToTruncate =
245 entriesByLowerBound.lowerEntry(rangeToRemove.upperBound);
246 if (mapEntryAboveToTruncate != null) {
247 // we know ( ]
248 RangeMapEntry<K, V> rangeMapEntry = mapEntryAboveToTruncate.getValue();
249 if (rangeMapEntry.getUpperBound().compareTo(rangeToRemove.upperBound) > 0) {
250 // we know ( ] ), and since we dealt with truncating below already,
251 // we know [ ( ] )
252 putRangeMapEntry(
253 rangeToRemove.upperBound,
254 rangeMapEntry.getUpperBound(),
255 mapEntryAboveToTruncate.getValue().getValue());
256 }
257 }
258 entriesByLowerBound.subMap(rangeToRemove.lowerBound, rangeToRemove.upperBound).clear();
259 }
260
261 private void split(Cut<K> cut) {
262 /*

Callers 1

putMethod · 0.95

Calls 10

putRangeMapEntryMethod · 0.95
isEmptyMethod · 0.65
getValueMethod · 0.65
clearMethod · 0.65
lowerEntryMethod · 0.45
compareToMethod · 0.45
getUpperBoundMethod · 0.45
getLowerBoundMethod · 0.45
subMapMethod · 0.45
checkNotNullMethod · 0.45

Tested by

no test coverage detected