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

Method add

corpus/java/training/guava/collect/TreeRangeSet.java:165–210  ·  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
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) {

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