(Range<C> rangeToAdd)
| 176 | } |
| 177 | |
| 178 | @Override |
| 179 | public void add(Range<C> rangeToAdd) { |
| 180 | checkNotNull(rangeToAdd); |
| 181 | |
| 182 | if (rangeToAdd.isEmpty()) { |
| 183 | return; |
| 184 | } |
| 185 | |
| 186 | // We will use { } to illustrate ranges currently in the range set, and < > |
| 187 | // to illustrate rangeToAdd. |
| 188 | Cut<C> lbToAdd = rangeToAdd.lowerBound; |
| 189 | Cut<C> ubToAdd = rangeToAdd.upperBound; |
| 190 | |
| 191 | Entry<Cut<C>, Range<C>> entryBelowLb = rangesByLowerBound.lowerEntry(lbToAdd); |
| 192 | if (entryBelowLb != null) { |
| 193 | // { < |
| 194 | Range<C> rangeBelowLb = entryBelowLb.getValue(); |
| 195 | if (rangeBelowLb.upperBound.compareTo(lbToAdd) >= 0) { |
| 196 | // { < }, and we will need to coalesce |
| 197 | if (rangeBelowLb.upperBound.compareTo(ubToAdd) >= 0) { |
| 198 | // { < > } |
| 199 | ubToAdd = rangeBelowLb.upperBound; |
| 200 | /* |
| 201 | * TODO(cpovirk): can we just "return;" here? Or, can we remove this if() entirely? If |
| 202 | * not, add tests to demonstrate the problem with each approach |
| 203 | */ |
| 204 | } |
| 205 | lbToAdd = rangeBelowLb.lowerBound; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | Entry<Cut<C>, Range<C>> entryBelowUb = rangesByLowerBound.floorEntry(ubToAdd); |
| 210 | if (entryBelowUb != null) { |
| 211 | // { > |
| 212 | Range<C> rangeBelowUb = entryBelowUb.getValue(); |
| 213 | if (rangeBelowUb.upperBound.compareTo(ubToAdd) >= 0) { |
| 214 | // { > }, and we need to coalesce |
| 215 | ubToAdd = rangeBelowUb.upperBound; |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | // Remove ranges which are strictly enclosed. |
| 220 | rangesByLowerBound.subMap(lbToAdd, ubToAdd).clear(); |
| 221 | |
| 222 | replaceRangeWithSameLowerBound(Range.create(lbToAdd, ubToAdd)); |
| 223 | } |
| 224 | |
| 225 | @Override |
| 226 | public void remove(Range<C> rangeToRemove) { |
nothing calls this directly
no test coverage detected