Methods Summary |
---|
public boolean | add(com.sun.java_cup.internal.symbol_set other)Add (union) in a complete set.
boolean result = false;
not_null(other);
/* walk down the other set and do the adds individually */
for (Enumeration e = other.all(); e.hasMoreElements(); )
result = add((symbol)e.nextElement()) || result;
return result;
|
public boolean | add(symbol sym)Add a single symbol to the set.
Object previous;
not_null(sym);
/* put the object in */
previous = _all.put(sym.name(),sym);
/* if we had a previous, this is no change */
return previous == null;
|
public java.util.Enumeration | all()Access to all elements of the set.
return _all.elements();
|
public boolean | contains(symbol sym)Determine if the set contains a particular symbol.return _all.containsKey(sym.name());
|
public boolean | equals(com.sun.java_cup.internal.symbol_set other)Equality comparison.
if (other == null || other.size() != size()) return false;
/* once we know they are the same size, then improper subset does test */
try {
return is_subset_of(other);
} catch (internal_error e) {
/* can't throw the error (because super class doesn't), so we crash */
e.crash();
return false;
}
|
public boolean | equals(java.lang.Object other)Generic equality comparison.
if (!(other instanceof symbol_set))
return false;
else
return equals((symbol_set)other);
|
public int | hashCode()Compute a hash code.
int result = 0;
int cnt;
Enumeration e;
/* hash together codes from at most first 5 elements */
for (e = all(), cnt=0 ; e.hasMoreElements() && cnt<5; cnt++)
result ^= ((symbol)e.nextElement()).hashCode();
return result;
|
public boolean | is_subset_of(com.sun.java_cup.internal.symbol_set other)Determine if this set is an (improper) subset of another.
not_null(other);
/* walk down our set and make sure every element is in the other */
for (Enumeration e = all(); e.hasMoreElements(); )
if (!other.contains((symbol)e.nextElement()))
return false;
/* they were all there */
return true;
|
public boolean | is_superset_of(com.sun.java_cup.internal.symbol_set other)Determine if this set is an (improper) superset of another.
not_null(other);
return other.is_subset_of(this);
|
protected void | not_null(java.lang.Object obj)Helper function to test for a null object and throw an exception
if one is found.
if (obj == null)
throw new internal_error("Null object used in set operation");
|
public void | remove(symbol sym)Remove a single symbol if it is in the set.
not_null(sym);
_all.remove(sym.name());
|
public void | remove(com.sun.java_cup.internal.symbol_set other)Remove (set subtract) a complete set.
not_null(other);
/* walk down the other set and do the removes individually */
for (Enumeration e = other.all(); e.hasMoreElements(); )
remove((symbol)e.nextElement());
|
public int | size()size of the setreturn _all.size();
|
public java.lang.String | toString()Convert to a string.
String result;
boolean comma_flag;
result = "{";
comma_flag = false;
for (Enumeration e = all(); e.hasMoreElements(); )
{
if (comma_flag)
result += ", ";
else
comma_flag = true;
result += ((symbol)e.nextElement()).name();
}
result += "}";
return result;
|