MCPcopy Create free account
hub / github.com/antlr/codebuff / add

Method add

output/java_guava/1.4.19/TreeRangeSet.java:165–206  ·  view source on GitHub ↗
(Range<C> rangeToAdd)

Source from the content-addressed store, hash-verified

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

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