MCPcopy
hub / github.com/google/guava / add

Method add

guava/src/com/google/common/collect/TreeRangeSet.java:178–223  ·  view source on GitHub ↗
(Range<C> rangeToAdd)

Source from the content-addressed store, hash-verified

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) {

Callers

nothing calls this directly

Calls 10

createMethod · 0.95
isEmptyMethod · 0.65
getValueMethod · 0.65
clearMethod · 0.65
checkNotNullMethod · 0.45
lowerEntryMethod · 0.45
compareToMethod · 0.45
floorEntryMethod · 0.45
subMapMethod · 0.45

Tested by

no test coverage detected