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