edu.washington.cs.supple.rep
Class SimpleBeanType

java.lang.Object
  extended byedu.washington.cs.supple.rep.SuppleBeanImpl
      extended byedu.washington.cs.supple.rep.SimpleBeanType
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable, SuppleBean, SuppleType

public abstract class SimpleBeanType
extends SuppleBeanImpl
implements java.io.Serializable, java.lang.Cloneable, SuppleType

Author:
Krzysztof Gajos An abstraction for all types to be used to represent the interfaces
See Also:
Serialized Form

Field Summary
protected  boolean finalLegalValues
           
protected  boolean hasOrdering
           
protected static int lastUid
           
protected  java.util.Vector legalValues
           
protected  java.util.Vector likelyValues
           
protected  int maxNumLegalValues
           
protected  int typicalIndexLength
           
protected  int uid
           
 
Fields inherited from class edu.washington.cs.supple.rep.SuppleBeanImpl
pcs
 
Constructor Summary
SimpleBeanType()
           
SimpleBeanType(java.util.Collection likelyValues)
           
SimpleBeanType(java.util.Collection likelyValues, java.util.Collection legalValues)
           
SimpleBeanType(java.lang.Object[] likelyValues, java.lang.Object[] legalValues)
           
 
Method Summary
 void addLegalValue(java.lang.Object v)
          Lets you add a legal value for this type instance
protected  boolean addLegalValueHelper(java.lang.Object v)
          Adds a legal value without sending out any notifications
 void addLegalValues(java.util.Collection vals)
          Lets you add a bunch of legal values at once for this type instance
 void addLikelyValue(java.lang.Object v)
          Adds a new value to the list of likely values and fires property change notification if the list really changed
protected  boolean addLikelyValueHelper(java.lang.Object v)
          A helper function that adds a new value at the beginning of th elist and creates the storage object but does not fire property change;
protected  void ensureLegalValues()
          To be overriden by enumerable types that dynamically change the set of legal values.
 boolean equals(java.lang.Object o)
          Equality test is based on the unique id assigned to each instance of the BaseType
 java.lang.String getIndex(java.lang.Object value)
           
 java.lang.String getIndex(java.lang.Object value, int maxLength)
          Returns a version of the index that is no longer than the specified maximum
 java.util.Vector getLegalValues()
           
 java.util.Vector getLikelyValues()
           
 java.lang.String getLongestLegalIndex()
          If the type is enumerable, this method will scan through all legal values and return the longest index it finds; if the type is not enumerable, no guarantees are given for the result
 int getMaxNumLegalValues()
           
 int getNumLegalValues()
          For enumerable types, returns the number of legal values; throws UnsupportedOperationException otherwise
 int getNumLikelyValues()
           
 int getTypicalIndexLength()
          Returns the typical lenght of the index
 int hashCode()
          Hashcode is a function of the uid
abstract  boolean hasIndex()
          Index is a short unique summary of the value (which can be used for choosing present values, etc.
 boolean hasOrdering()
          This method returns true if there exists a natural ordering on the values of this type; false otherwise;
 boolean hasSetLegalValues()
           
abstract  boolean isEnumerable()
          This method tells you if possible values for this type can be (reasonably) enumerated
 boolean isFinalLegalValues()
          Returns true if the legal values are guaranteed not to change throughout the duration of this run time
 boolean isLegalValue(java.lang.Object value)
          Check if a value is legal for this type.
protected abstract  boolean isLegalValueType(java.lang.Object value)
          Check if the value is of the correct type (used when setting legal values)
 java.util.Vector orderValues(java.util.Vector v)
          This method enforces type-specific ordering on values (can only be legally invoked if hasOrdering() returns true)
 void setFinalLegalValues(boolean b)
           
 void setLegalValues(java.util.Collection c)
          Lets you set the legal values for this type instance
 void setLikelyValues(java.util.Collection c)
          Sets the list of likely values
 void setMaxNumLegalValues(int v)
           
 void setTypicalIndexLength(int i)
          Allows you to specify the typical lenght of an index for any value of this type
 java.lang.String toPrettyString(java.lang.String pref)
           
 java.lang.String toString()
           
 
Methods inherited from class edu.washington.cs.supple.rep.SuppleBeanImpl
addPropertyChangeListener, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface edu.washington.cs.supple.rep.SuppleType
accept, getUniqueId, isLegalValueClass, isPrimitiveType, verifyCurrentValue
 
Methods inherited from interface edu.washington.cs.supple.rep.SuppleBean
addPropertyChangeListener, removePropertyChangeListener
 

Field Detail

likelyValues

protected java.util.Vector likelyValues

uid

protected transient int uid

lastUid

protected static int lastUid

maxNumLegalValues

protected int maxNumLegalValues

finalLegalValues

protected boolean finalLegalValues

typicalIndexLength

protected int typicalIndexLength

hasOrdering

protected boolean hasOrdering

legalValues

protected java.util.Vector legalValues
Constructor Detail

SimpleBeanType

public SimpleBeanType()

SimpleBeanType

public SimpleBeanType(java.util.Collection likelyValues)
Parameters:
likelyValues - a collection of initial likely values

SimpleBeanType

public SimpleBeanType(java.util.Collection likelyValues,
                      java.util.Collection legalValues)

SimpleBeanType

public SimpleBeanType(java.lang.Object[] likelyValues,
                      java.lang.Object[] legalValues)
Method Detail

isEnumerable

public abstract boolean isEnumerable()
This method tells you if possible values for this type can be (reasonably) enumerated

Specified by:
isEnumerable in interface SuppleType

getNumLegalValues

public int getNumLegalValues()
For enumerable types, returns the number of legal values; throws UnsupportedOperationException otherwise

Specified by:
getNumLegalValues in interface SuppleType

getMaxNumLegalValues

public int getMaxNumLegalValues()
Specified by:
getMaxNumLegalValues in interface SuppleType

setMaxNumLegalValues

public void setMaxNumLegalValues(int v)

hasSetLegalValues

public boolean hasSetLegalValues()
Specified by:
hasSetLegalValues in interface SuppleType
Returns:
true if legal values have been set, false otherwise

isFinalLegalValues

public boolean isFinalLegalValues()
Description copied from interface: SuppleType
Returns true if the legal values are guaranteed not to change throughout the duration of this run time

Specified by:
isFinalLegalValues in interface SuppleType

setFinalLegalValues

public void setFinalLegalValues(boolean b)

isLegalValue

public boolean isLegalValue(java.lang.Object value)
Description copied from interface: SuppleType
Check if a value is legal for this type.

Specified by:
isLegalValue in interface SuppleType
Parameters:
value - value to be checked
Returns:
true if value is legal (of right type an in the domain), false otherwise

isLegalValueType

protected abstract boolean isLegalValueType(java.lang.Object value)
Check if the value is of the correct type (used when setting legal values)

Parameters:
value - value to be checked
Returns:
true if all is ok

setLegalValues

public void setLegalValues(java.util.Collection c)
Lets you set the legal values for this type instance

Parameters:
c - the collection of legal values

addLegalValues

public void addLegalValues(java.util.Collection vals)
Lets you add a bunch of legal values at once for this type instance

Parameters:
vals - new values to be added

addLegalValue

public void addLegalValue(java.lang.Object v)
Lets you add a legal value for this type instance

Parameters:
v - a new value to be added

addLegalValueHelper

protected boolean addLegalValueHelper(java.lang.Object v)
Adds a legal value without sending out any notifications

Parameters:
v - value to be added
Returns:
true if all went well, false if for some reason the value could not be added (e.g. it is not of legal type)

hasOrdering

public boolean hasOrdering()
This method returns true if there exists a natural ordering on the values of this type; false otherwise;

Specified by:
hasOrdering in interface SuppleType

orderValues

public java.util.Vector orderValues(java.util.Vector v)
This method enforces type-specific ordering on values (can only be legally invoked if hasOrdering() returns true)

Specified by:
orderValues in interface SuppleType
Parameters:
v - values to be ordered
Returns:
ordered vector of values

addLikelyValueHelper

protected boolean addLikelyValueHelper(java.lang.Object v)
A helper function that adds a new value at the beginning of th elist and creates the storage object but does not fire property change;

Parameters:
v - value to be added
Returns:
true if this value was NOT a duplicate (i.e. the list of likely values really changed); false otherwise

addLikelyValue

public void addLikelyValue(java.lang.Object v)
Adds a new value to the list of likely values and fires property change notification if the list really changed

Parameters:
v - the value to be added

setLikelyValues

public void setLikelyValues(java.util.Collection c)
Sets the list of likely values

Parameters:
c - the new list of likely values

getLikelyValues

public java.util.Vector getLikelyValues()
Specified by:
getLikelyValues in interface SuppleType
Returns:
the clone of the current list of likely values

getNumLikelyValues

public int getNumLikelyValues()
Specified by:
getNumLikelyValues in interface SuppleType
Returns:
the number of likely values

getLegalValues

public java.util.Vector getLegalValues()
Specified by:
getLegalValues in interface SuppleType
Returns:
if the type is enumerable, returns an ordered vector of current legal values; null if not enumerable

ensureLegalValues

protected void ensureLegalValues()
To be overriden by enumerable types that dynamically change the set of legal values. Inside this method you should set the value of legalValues field.


hasIndex

public abstract boolean hasIndex()
Index is a short unique summary of the value (which can be used for choosing present values, etc.

Specified by:
hasIndex in interface SuppleType
Returns:
true if the val is set and has an index defined, false otherwise

getIndex

public java.lang.String getIndex(java.lang.Object value)
Specified by:
getIndex in interface SuppleType
Returns:
the index of the var (if exists); null otherwise

getIndex

public java.lang.String getIndex(java.lang.Object value,
                                 int maxLength)
Returns a version of the index that is no longer than the specified maximum

Specified by:
getIndex in interface SuppleType
Parameters:
maxLength - the maximum lenght allowed for the index (in characters)
Returns:
the limitted length version of the index

getTypicalIndexLength

public int getTypicalIndexLength()
Returns the typical lenght of the index

Specified by:
getTypicalIndexLength in interface SuppleType
Returns:
typical index length (in characters)

setTypicalIndexLength

public void setTypicalIndexLength(int i)
Allows you to specify the typical lenght of an index for any value of this type

Parameters:
i - the typical lenght of an index (in characters)

getLongestLegalIndex

public java.lang.String getLongestLegalIndex()
If the type is enumerable, this method will scan through all legal values and return the longest index it finds; if the type is not enumerable, no guarantees are given for the result

Specified by:
getLongestLegalIndex in interface SuppleType
Returns:
the longest index of all legal values

hashCode

public int hashCode()
Hashcode is a function of the uid

See Also:
Object.hashCode()

equals

public boolean equals(java.lang.Object o)
Equality test is based on the unique id assigned to each instance of the BaseType

Returns:
true if they are the same instance, false otherwise

toString

public java.lang.String toString()

toPrettyString

public java.lang.String toPrettyString(java.lang.String pref)
Specified by:
toPrettyString in interface SuppleType