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

Method add

output/java_guava/1.4.18/TreeRangeSet.java:163–204  ·  view source on GitHub ↗
(Range<C> rangeToAdd)

Source from the content-addressed store, hash-verified

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