/** Add a single element to the set. An isolated element is stored * as a range el..el. */ @Override public void add(int el) { if ( readonly ) throw new IllegalStateException("can't alter readonly IntervalSet"); add(el,el); }
expected.add(Token.EOF);
public IntervalSet(int... els) { if ( els==null ) { intervals = new ArrayList<Interval>(2); // most sets are 1 or 2 elements } else { intervals = new ArrayList<Interval>(els.length); for (int e : els) add(e); } }
public static IntervalSet toSet(BitSet bits) { IntervalSet s = new IntervalSet(); int i = bits.nextSetBit(0); while ( i >= 0 ) { s.add(i); i = bits.nextSetBit(i+1); } return s; }
/** Create a set with all ints within range [a..b] (inclusive) */ public static IntervalSet of(int a, int b) { IntervalSet s = new IntervalSet(); s.add(a,b); return s; }
/** Create a set with a single element, el. */ public static IntervalSet of(int a) { IntervalSet s = new IntervalSet(); s.add(a); return s; }
/** Add interval; i.e., add all integers from a to b to set. * If b<a, do nothing. * Keep list in sorted order (by left range value). * If overlap, combine ranges. For example, * If this is {1..5, 10..20}, adding 6..7 yields * {1..5, 6..7, 10..20}. Adding 4..8 yields {1..8, 10..20}. */ public void add(int a, int b) { add(Interval.of(a, b)); }
@Override public IntervalSet addAll(IntSet set) { if ( set==null ) { return this; } if (set instanceof IntervalSet) { IntervalSet other = (IntervalSet)set; // walk set and add each interval int n = other.intervals.size(); for (int i = 0; i < n; i++) { Interval I = other.intervals.get(i); this.add(I.a,I.b); } } else { for (int value : set.toList()) { add(value); } } return this; }
int oldb = I.b; I.b = el-1; // [a..x-1] add(el+1, oldb); // add [x+1..b]
private int deserializeSets(char[] data, int p, List<IntervalSet> sets, UnicodeDeserializer unicodeDeserializer) { int nsets = toInt(data[p++]); for (int i=0; i<nsets; i++) { int nintervals = toInt(data[p]); p++; IntervalSet set = new IntervalSet(); sets.add(set); boolean containsEof = toInt(data[p++]) != 0; if (containsEof) { set.add(-1); } for (int j=0; j<nintervals; j++) { int a = unicodeDeserializer.readUnicode(data, p); p += unicodeDeserializer.size(); int b = unicodeDeserializer.readUnicode(data, p); p += unicodeDeserializer.size(); set.add(a, b); } } return p; }
protected int getAltThatFinishedDecisionEntryRule(ATNConfigSet configs) { IntervalSet alts = new IntervalSet(); for (ATNConfig c : configs) { if ( c.getOuterContextDepth()>0 || (c.state instanceof RuleStopState && c.context.hasEmptyPath()) ) { alts.add(c.alt); } } if ( alts.size()==0 ) return ATN.INVALID_ALT_NUMBER; return alts.getMinElement(); }
/** Add a single element to the set. An isolated element is stored * as a range el..el. */ @Override public void add(int el) { if ( readonly ) throw new IllegalStateException("can't alter readonly IntervalSet"); add(el,el); }
/** Add a single element to the set. An isolated element is stored * as a range el..el. */ @Override public void add(int el) { if ( readonly ) throw new IllegalStateException("can't alter readonly IntervalSet"); add(el,el); }
public IntervalSet(int... els) { if ( els==null ) { intervals = new ArrayList<Interval>(2); // most sets are 1 or 2 elements } else { intervals = new ArrayList<Interval>(els.length); for (int e : els) add(e); } }
lastErrorStates.add(recognizer.getState()); IntervalSet followSet = getErrorRecoverySet(recognizer); consumeUntil(recognizer, followSet);
public static IntervalSet toSet(BitSet bits) { IntervalSet s = new IntervalSet(); int i = bits.nextSetBit(0); while ( i >= 0 ) { s.add(i); i = bits.nextSetBit(i+1); } return s; } }
/** Add interval; i.e., add all integers from a to b to set. * If b<a, do nothing. * Keep list in sorted order (by left range value). * If overlap, combine ranges. For example, * If this is {1..5, 10..20}, adding 6..7 yields * {1..5, 6..7, 10..20}. Adding 4..8 yields {1..8, 10..20}. */ public void add(int a, int b) { add(Interval.of(a, b)); }
private static void addIntervalForCategory( Map<String, IntervalSet> categoryMap, String categoryName, int start, int finish) { IntervalSet intervalSet = categoryMap.get(categoryName); if (intervalSet == null) { intervalSet = new IntervalSet(); categoryMap.put(categoryName, intervalSet); } intervalSet.add(start, finish); }