1/* 2 * [The "BSD license"] 3 * Copyright (c) 2010 Terence Parr 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28package org.antlr.misc; 29 30import org.antlr.tool.Grammar; 31 32import java.util.List; 33 34/** A generic set of ints that has an efficient implementation, BitSet, 35 * which is a compressed bitset and is useful for ints that 36 * are small, for example less than 500 or so, and w/o many ranges. For 37 * ranges with large values like unicode char sets, this is not very efficient. 38 * Consider using IntervalSet. Not all methods in IntervalSet are implemented. 39 * 40 * @see org.antlr.misc.BitSet 41 * @see org.antlr.misc.IntervalSet 42 */ 43public interface IntSet { 44 /** Add an element to the set */ 45 void add(int el); 46 47 /** Add all elements from incoming set to this set. Can limit 48 * to set of its own type. 49 */ 50 void addAll(IntSet set); 51 52 /** Return the intersection of this set with the argument, creating 53 * a new set. 54 */ 55 IntSet and(IntSet a); 56 57 IntSet complement(IntSet elements); 58 59 IntSet or(IntSet a); 60 61 IntSet subtract(IntSet a); 62 63 /** Return the size of this set (not the underlying implementation's 64 * allocated memory size, for example). 65 */ 66 int size(); 67 68 boolean isNil(); 69 70 boolean equals(Object obj); 71 72 int getSingleElement(); 73 74 boolean member(int el); 75 76 /** remove this element from this set */ 77 void remove(int el); 78 79 List toList(); 80 81 String toString(); 82 83 String toString(Grammar g); 84} 85