edu.washington.cs.supple.rep
Class IntegerTypeImpl

java.lang.Object
  extended byedu.washington.cs.supple.rep.SuppleBeanImpl
      extended byedu.washington.cs.supple.rep.BaseType
          extended byedu.washington.cs.supple.rep.SimpleValueTypeImpl
              extended byedu.washington.cs.supple.rep.IntegerTypeImpl
All Implemented Interfaces:
java.lang.Cloneable, IntegerType, java.io.Serializable, SimpleValueType, SuppleBean, SuppleType, ValueListener

public final class IntegerTypeImpl
extends SimpleValueTypeImpl
implements IntegerType

Author:
kgajos
See Also:
Serialized Form

Field Summary
protected  boolean exact
           
protected  int increment
           
protected  java.lang.String[] labels
           
protected  java.lang.String longestLegalIndex
           
protected  int max
           
protected  ValueBinding maxBinding
           
protected  int min
           
protected  ValueBinding minBinding
           
 
Fields inherited from class edu.washington.cs.supple.rep.BaseType
finalLegalValues, hasOrdering, lastUid, legalValues, legalValuesBinding, likelyValues, likelyValuesBinding, maxNumLegalValues, nullLegal, typicalIndexLength, uid
 
Fields inherited from class edu.washington.cs.supple.rep.SuppleBeanImpl
pcs
 
Constructor Summary
IntegerTypeImpl(boolean exact)
           
IntegerTypeImpl(int min, int max, java.util.Collection likelyValues, boolean exact)
           
IntegerTypeImpl(int min, int max, int increment, java.util.Collection likelyValues, boolean exact)
           
 
Method Summary
 void bindMax(ValueBinding binding)
          Set max value
 void bindMin(ValueBinding binding)
           
protected  void ensureLegalValues()
          To be overriden by enumerable types that dynamically change the set of legal values.
 int getIncrement()
           
 java.lang.String getIndex(java.lang.Object value)
          If labels are set, getIndex will return the labels instead of integers.
 java.lang.Integer getIntegerValue(StateVar uiObject)
           
 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 getMax()
           
 int getMin()
           
 int getNumLegalValues()
          For enumerable types, returns the number of legal values; throws UnsupportedOperationException otherwise
 int getTypicalIndexLength()
          Returns the typical lenght of the index
 boolean hasOrdering()
          This method returns true if there exists a natural ordering on the values of this type; false otherwise;
 boolean isBounded()
          Checks if the type has both an upper and lower bound set
 boolean isEnumerable()
          We say that an Integer type is reasonably enumerable if it has fewer than a hundred legal values
 boolean isExact()
           
 boolean isLegalValue(java.lang.Object value)
          Check if a value is legal for this type.
 boolean isLegalValueClass(java.lang.Class c)
          Check if a class is legal for this type.
protected  boolean isWithinRange(int i)
           
 void setExact(boolean b)
           
 void setIndexLabels(java.lang.String[] labels)
          For types with bounded legal values, sets index labels.
 void setMax(int newMax)
           
 void setMin(int newMin)
           
 java.lang.String toPrettyString(java.lang.String pref)
           
 java.lang.String toString()
           
 void valueChanged(ValueBinding binding, java.lang.Object value)
          Signals variable change.
protected  boolean verifyLegalValuesChangeable(java.lang.String nameOfAttemptedOperation)
           
protected  void visitBoundProperties(UiVisitor visitor)
          Helper for accept() - allows subclasses to extend the bindings to be visited without overriding accept().
 
Methods inherited from class edu.washington.cs.supple.rep.SimpleValueTypeImpl
hasIndex, isPrimitiveType
 
Methods inherited from class edu.washington.cs.supple.rep.BaseType
accept, addLegalValue, addLegalValueHelper, addLegalValues, addLikelyValue, addLikelyValueHelper, bindLegalValues, bindLikelyValues, equals, getIndex, getLegalValues, getLikelyValues, getMaxNumLegalValues, getNumLikelyValues, getUniqueId, hashCode, hasSetLegalValues, isFinalLegalValues, orderValues, setFinalLegalValues, setLegalValues, setLikelyValues, setMaxNumLegalValues, setTypicalIndexLength, verifyCurrentValue
 
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, getIndex, getLegalValues, getLikelyValues, getMaxNumLegalValues, getNumLikelyValues, getUniqueId, hasIndex, hasSetLegalValues, isFinalLegalValues, isPrimitiveType, orderValues, verifyCurrentValue
 
Methods inherited from interface edu.washington.cs.supple.rep.SuppleBean
addPropertyChangeListener, removePropertyChangeListener
 

Field Detail

min

protected int min

max

protected int max

maxBinding

protected transient ValueBinding maxBinding

minBinding

protected transient ValueBinding minBinding

labels

protected java.lang.String[] labels

longestLegalIndex

protected java.lang.String longestLegalIndex

increment

protected int increment

exact

protected boolean exact
Constructor Detail

IntegerTypeImpl

public IntegerTypeImpl(int min,
                       int max,
                       int increment,
                       java.util.Collection likelyValues,
                       boolean exact)
Parameters:
min - the minimum value for this instance
max - the maximum value for this instance
increment - the increment
likelyValues - the set of most likely values (null or empty collection for none)
exact - indicates whether or not it matters for the application that the user should be able to set the value exactly

IntegerTypeImpl

public IntegerTypeImpl(int min,
                       int max,
                       java.util.Collection likelyValues,
                       boolean exact)
Parameters:
min - the minimum value for this instance
max - the maximum value for this instance
likelyValues - the set of most likely values (null or empty collection for none)
exact - indicates whether or not it matters for the application that the user should be able to set the value exactly

IntegerTypeImpl

public IntegerTypeImpl(boolean exact)
Parameters:
exact - indicates whether or not it matters for the application that the user should be able to set the value exactly
Method Detail

getMax

public int getMax()
Specified by:
getMax in interface IntegerType
Returns:
the max value

setMax

public void setMax(int newMax)

bindMax

public void bindMax(ValueBinding binding)
Set max value

Parameters:
binding -

getMin

public int getMin()
Specified by:
getMin in interface IntegerType
Returns:
the min value

setMin

public void setMin(int newMin)

bindMin

public void bindMin(ValueBinding binding)

getIncrement

public int getIncrement()
Specified by:
getIncrement in interface IntegerType
Returns:
the increment

verifyLegalValuesChangeable

protected boolean verifyLegalValuesChangeable(java.lang.String nameOfAttemptedOperation)

getNumLegalValues

public int getNumLegalValues()
Description copied from interface: SuppleType
For enumerable types, returns the number of legal values; throws UnsupportedOperationException otherwise

Specified by:
getNumLegalValues in interface SuppleType
Overrides:
getNumLegalValues in class BaseType
Returns:
returns the total number of values allowed

ensureLegalValues

protected void ensureLegalValues()
Description copied from class: BaseType
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.

Overrides:
ensureLegalValues in class BaseType

isEnumerable

public boolean isEnumerable()
We say that an Integer type is reasonably enumerable if it has fewer than a hundred legal values

Specified by:
isEnumerable in interface SuppleType
Specified by:
isEnumerable in class BaseType

toString

public java.lang.String toString()
Overrides:
toString in class BaseType

toPrettyString

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

isExact

public boolean isExact()
Specified by:
isExact in interface IntegerType
Returns:
true if this type expects exact values

isBounded

public boolean isBounded()
Description copied from interface: IntegerType
Checks if the type has both an upper and lower bound set

Specified by:
isBounded in interface IntegerType
Returns:
true if bounded (above and below); false otherwise

setExact

public void setExact(boolean b)
Parameters:
b - true if this type expects exact values, false otherwise

hasOrdering

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

Specified by:
hasOrdering in interface SuppleType
Overrides:
hasOrdering in class BaseType

getLongestLegalIndex

public java.lang.String getLongestLegalIndex()
Description copied from interface: SuppleType
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
Overrides:
getLongestLegalIndex in class BaseType
Returns:
the longest index of all legal values

setIndexLabels

public void setIndexLabels(java.lang.String[] labels)
For types with bounded legal values, sets index labels.

Parameters:
labels -
Returns:

getTypicalIndexLength

public int getTypicalIndexLength()
Description copied from interface: SuppleType
Returns the typical lenght of the index

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

getIndex

public java.lang.String getIndex(java.lang.Object value)
If labels are set, getIndex will return the labels instead of integers.

Specified by:
getIndex in interface SuppleType
Overrides:
getIndex in class SimpleValueTypeImpl

isWithinRange

protected boolean isWithinRange(int i)

isLegalValueClass

public boolean isLegalValueClass(java.lang.Class c)
Description copied from interface: SuppleType
Check if a class is legal for this type.

Specified by:
isLegalValueClass in interface SuppleType
Parameters:
c -
Returns:

getIntegerValue

public java.lang.Integer getIntegerValue(StateVar uiObject)
Specified by:
getIntegerValue in interface IntegerType

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
Overrides:
isLegalValue in class BaseType

valueChanged

public void valueChanged(ValueBinding binding,
                         java.lang.Object value)
Description copied from interface: ValueListener
Signals variable change.

Specified by:
valueChanged in interface ValueListener
Overrides:
valueChanged in class BaseType

visitBoundProperties

protected void visitBoundProperties(UiVisitor visitor)
Description copied from class: BaseType
Helper for accept() - allows subclasses to extend the bindings to be visited without overriding accept().

Overrides:
visitBoundProperties in class BaseType