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