FileDocCategorySizeDatePackage
terminal_set.javaAPI DocJava SE 5 API6638Fri Aug 26 14:54:54 BST 2005com.sun.java_cup.internal

terminal_set

public class terminal_set extends Object
A set of terminals implemented as a bitset.
version
last updated: 11/25/95
author
Scott Hudson

Fields Summary
public static final terminal_set
EMPTY
Constant for the empty set.
protected BitSet
_elements
Bitset to implement the actual set.
Constructors Summary
public terminal_set()
Constructor for an empty set.

 
      /* allocate the bitset at what is probably the right size */
      _elements = new BitSet(terminal.number());
    
public terminal_set(terminal_set other)
Constructor for cloning from another set.

param
other the set we are cloning from.

      not_null(other);
      _elements = (BitSet)other._elements.clone();
    
Methods Summary
public booleanadd(com.sun.java_cup.internal.terminal_set other)
Add (union) in a complete set.

param
other the set being added.
return
true if this changes the set.

      not_null(other);

      /* make a copy */
      BitSet copy = (BitSet)_elements.clone();

      /* or in the other set */
      _elements.or(other._elements);

      /* changed if we are not the same as the copy */
      return !_elements.equals(copy);
    
public booleanadd(terminal sym)
Add a single terminal to the set.

param
sym the terminal being added.
return
true if this changes the set.

      boolean result;

      not_null(sym); 

      /* see if we already have this */ 
      result = _elements.get(sym.index());

      /* if not we add it */
      if (!result)
	_elements.set(sym.index());

      return result;
    
public booleancontains(terminal sym)
Determine if the set contains a particular terminal.

param
sym the terminal symbol we are looking for.

      not_null(sym); 
      return _elements.get(sym.index());
    
public booleancontains(int indx)
Given its index determine if the set contains a particular terminal.

param
indx the index of the terminal in question.

      return _elements.get(indx);
    
public booleanempty()
Determine if the set is empty.

      return equals(EMPTY);
    
public booleanequals(com.sun.java_cup.internal.terminal_set other)
Equality comparison.

      if (other == null) 
	return false;
      else
	return _elements.equals(other._elements);
    
public booleanequals(java.lang.Object other)
Generic equality comparison.

      if (!(other instanceof terminal_set))
	return false;
      else
	return equals((terminal_set)other);
    
public booleanintersects(com.sun.java_cup.internal.terminal_set other)
Determine if this set intersects another.

param
other the other set in question.

       not_null(other);

       /* make a copy of the other set */
       BitSet copy = (BitSet)other._elements.clone();

       /* xor out our values */
       copy.xor(this._elements);

       /* see if its different */
       return !copy.equals(other._elements);
     
public booleanis_subset_of(com.sun.java_cup.internal.terminal_set other)
Determine if this set is an (improper) subset of another.

param
other the set we are testing against.

      not_null(other);

      /* make a copy of the other set */
      BitSet copy_other = (BitSet)other._elements.clone();

      /* and or in */
      copy_other.or(_elements);

      /* if it hasn't changed, we were a subset */
      return copy_other.equals(other._elements);
    
public booleanis_superset_of(com.sun.java_cup.internal.terminal_set other)
Determine if this set is an (improper) superset of another.

param
other the set we are testing against.

      not_null(other);
      return other.is_subset_of(this);
    
protected voidnot_null(java.lang.Object obj)
Helper function to test for a null object and throw an exception if one is found.

param
obj the object we are testing.


  /*-----------------------------------------------------------*/
  /*--- General Methods ----------------------------------------*/
  /*-----------------------------------------------------------*/

                              
       
    
      if (obj == null) 
	throw new internal_error("Null object used in set operation");
    
public voidremove(terminal sym)
Remove a terminal if it is in the set.

param
sym the terminal being removed.

      not_null(sym); 
      _elements.clear(sym.index());
    
public java.lang.StringtoString()
Convert to string.

      String result;
      boolean comma_flag;
      
      result = "{";
      comma_flag = false;
      for (int t = 0; t < terminal.number(); t++)
	{
	  if (_elements.get(t))
	    {
	      if (comma_flag)
	        result += ", ";
	      else
	        comma_flag = true;

	      result += terminal.find(t).name();
	    }
	}
      result += "}";

      return result;