(Range<C> rangeToAdd)
| 161 | } |
| 162 | |
| 163 | @Override |
| 164 | public void add(Range<C> rangeToAdd) { |
| 165 | checkNotNull(rangeToAdd); |
| 166 | if (rangeToAdd.isEmpty()) { |
| 167 | return; |
| 168 | } |
| 169 | |
| 170 | // We will use { } to illustrate ranges currently in the range set, and < > |
| 171 | // to illustrate rangeToAdd. |
| 172 | Cut<C> lbToAdd = rangeToAdd.lowerBound; |
| 173 | Cut<C> ubToAdd = rangeToAdd.upperBound; |
| 174 | Entry<Cut<C>, Range<C>> entryBelowLB = rangesByLowerBound.lowerEntry(lbToAdd); |
| 175 | if (entryBelowLB != null) { |
| 176 | // { < |
| 177 | Range<C> rangeBelowLB = entryBelowLB.getValue(); |
| 178 | if (rangeBelowLB.upperBound.compareTo(lbToAdd) >= 0) { |
| 179 | // { < }, and we will need to coalesce |
| 180 | if (rangeBelowLB.upperBound.compareTo(ubToAdd) >= 0) { |
| 181 | // { < > } |
| 182 | ubToAdd = rangeBelowLB.upperBound; |
| 183 | /* |
| 184 | * TODO(cpovirk): can we just "return;" here? Or, can we remove this if() entirely? If |
| 185 | * not, add tests to demonstrate the problem with each approach |
| 186 | */ |
| 187 | } |
| 188 | lbToAdd = rangeBelowLB.lowerBound; |
| 189 | } |
| 190 | } |
| 191 | Entry<Cut<C>, Range<C>> entryBelowUB = rangesByLowerBound.floorEntry(ubToAdd); |
| 192 | if (entryBelowUB != null) { |
| 193 | // { > |
| 194 | Range<C> rangeBelowUB = entryBelowUB.getValue(); |
| 195 | if (rangeBelowUB.upperBound.compareTo(ubToAdd) >= 0) { |
| 196 | // { > }, and we need to coalesce |
| 197 | ubToAdd = rangeBelowUB.upperBound; |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | // Remove ranges which are strictly enclosed. |
| 202 | rangesByLowerBound.subMap(lbToAdd, ubToAdd).clear(); |
| 203 | replaceRangeWithSameLowerBound(Range.create(lbToAdd, ubToAdd)); |
| 204 | } |
| 205 | |
| 206 | @Override |
| 207 | public void remove(Range<C> rangeToRemove) { |
nothing calls this directly
no test coverage detected