(Range<K> rangeToRemove)
| 154 | } |
| 155 | |
| 156 | @Override |
| 157 | public void remove(Range<K> rangeToRemove) { |
| 158 | if (rangeToRemove.isEmpty()) { |
| 159 | return; |
| 160 | } |
| 161 | |
| 162 | /* |
| 163 | * The comments for this method will use [ ] to indicate the bounds of rangeToRemove and ( ) to |
| 164 | * indicate the bounds of ranges in the range map. |
| 165 | */ |
| 166 | Map.Entry<Cut<K>, RangeMapEntry<K, V>> mapEntryBelowToTruncate = entriesByLowerBound.lowerEntry(rangeToRemove.lowerBound); |
| 167 | if (mapEntryBelowToTruncate != null) { |
| 168 | // we know ( [ |
| 169 | RangeMapEntry<K, V> rangeMapEntry = mapEntryBelowToTruncate.getValue(); |
| 170 | if (rangeMapEntry.getUpperBound().compareTo(rangeToRemove.lowerBound) > 0) { |
| 171 | // we know ( [ ) |
| 172 | if (rangeMapEntry.getUpperBound().compareTo(rangeToRemove.upperBound) > 0) { |
| 173 | // we know ( [ ] ), so insert the range ] ) back into the map -- |
| 174 | // it's being split apart |
| 175 | putRangeMapEntry( |
| 176 | rangeToRemove.upperBound, |
| 177 | rangeMapEntry.getUpperBound(), |
| 178 | mapEntryBelowToTruncate.getValue().getValue()); |
| 179 | } |
| 180 | // overwrite mapEntryToTruncateBelow with a truncated range |
| 181 | putRangeMapEntry( |
| 182 | rangeMapEntry.getLowerBound(), |
| 183 | rangeToRemove.lowerBound, |
| 184 | mapEntryBelowToTruncate.getValue().getValue()); |
| 185 | } |
| 186 | } |
| 187 | Map.Entry<Cut<K>, RangeMapEntry<K, V>> mapEntryAboveToTruncate = entriesByLowerBound.lowerEntry(rangeToRemove.upperBound); |
| 188 | if (mapEntryAboveToTruncate != null) { |
| 189 | // we know ( ] |
| 190 | RangeMapEntry<K, V> rangeMapEntry = mapEntryAboveToTruncate.getValue(); |
| 191 | if (rangeMapEntry.getUpperBound().compareTo(rangeToRemove.upperBound) > 0) { |
| 192 | // we know ( ] ), and since we dealt with truncating below already, |
| 193 | // we know [ ( ] ) |
| 194 | putRangeMapEntry( |
| 195 | rangeToRemove.upperBound, |
| 196 | rangeMapEntry.getUpperBound(), |
| 197 | mapEntryAboveToTruncate.getValue().getValue()); |
| 198 | entriesByLowerBound.remove(rangeToRemove.lowerBound); |
| 199 | } |
| 200 | } |
| 201 | entriesByLowerBound.subMap(rangeToRemove.lowerBound, rangeToRemove.upperBound).clear(); |
| 202 | } |
| 203 | |
| 204 | @Override |
| 205 | public Map<Range<K>, V> asMapOfRanges() { |
no test coverage detected