org.eigenbase.util.property
Class IntegerProperty

java.lang.Object
  extended by org.eigenbase.util.property.Property
      extended by org.eigenbase.util.property.IntegerProperty

public class IntegerProperty
extends Property

Definition and accessor for an integer property.

Since:
May 4, 2004
Version:
$Id: //open/dev/farrago/src/org/eigenbase/util/property/IntegerProperty.java#13 $
Author:
jhyde

Field Summary
private  int maxValue
           
private  int minValue
           
 
Fields inherited from class org.eigenbase.util.property.Property
properties
 
Constructor Summary
IntegerProperty(Properties properties, String path)
          Creates an Integer property which has no default value.
IntegerProperty(Properties properties, String path, int defaultValue)
          Creates an Integer property.
IntegerProperty(Properties properties, String path, int minValue, int maxValue)
          Creates an Integer property with fixed minimum and maximum values.
IntegerProperty(Properties properties, String path, int defaultValue, int minValue, int maxValue)
          Creates an Integer property with a default value and fixed minimum and maximum values.
 
Method Summary
 int get()
          Retrieves the value of this integer property according to these rules.
 int get(int defaultValue)
          Retrieves the value of this integer property.
private  int limit(int value)
          Returns value limited to the range [minValue, maxValue].
private  int noValue()
          Returns 0 if that value is in the range [minValue, maxValue].
 int set(int value)
          Sets the value of this integer property.
 
Methods inherited from class org.eigenbase.util.property.Property
addTrigger, booleanValue, getDefaultValue, getInternal, getPath, getString, isSet, onChange, removeTrigger, setString, stringValue, toBoolean
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

minValue

private final int minValue

maxValue

private final int maxValue
Constructor Detail

IntegerProperty

public IntegerProperty(Properties properties,
                       String path,
                       int defaultValue)
Creates an Integer property. Minimum and maximum values are set to Integer.MIN_VALUE and Integer.MAX_VALUE.

Parameters:
properties - Properties object which holds values for this property.
path - Name by which this property is serialized to a properties file, for example "com.acme.trace.Verbosity".
defaultValue - Default value.

IntegerProperty

public IntegerProperty(Properties properties,
                       String path)
Creates an Integer property which has no default value. Minimum and maximum values are set to Integer.MIN_VALUE and Integer.MAX_VALUE.

Parameters:
properties - Properties object which holds values for this property.
path - Name by which this property is serialized to a properties file, for example "com.acme.trace.Verbosity".

IntegerProperty

public IntegerProperty(Properties properties,
                       String path,
                       int defaultValue,
                       int minValue,
                       int maxValue)
Creates an Integer property with a default value and fixed minimum and maximum values.

Parameters:
properties - Properties object which holds values for this property.
path - Name by which this property is serialized to a properties file, for example "com.acme.trace.Verbosity".
defaultValue - Default value.
minValue - the minimum value of this property (inclusive)
maxValue - the maximum value of this property (inclusive)
Throws:
IllegalArgumentException - if defaultValue is not in the range [minValue, maxValue].

IntegerProperty

public IntegerProperty(Properties properties,
                       String path,
                       int minValue,
                       int maxValue)
Creates an Integer property with fixed minimum and maximum values.

Parameters:
properties - Properties object which holds values for this property.
path - Name by which this property is serialized to a properties file, for example "com.acme.trace.Verbosity".
minValue - the minimum value of this property (inclusive)
maxValue - the maximum value of this property (inclusive)
Method Detail

get

public int get()
Retrieves the value of this integer property according to these rules.


get

public int get(int defaultValue)
Retrieves the value of this integer property. If the property has no value, returns the default value. If there is no default value, returns the given default value. In all cases, the returned value is limited to the min/max value range given during construction.


set

public int set(int value)
Sets the value of this integer property. The value is limited to the min/max range given during construction.

Returns:
the previous value, or if not set: the default value. If no default value exists, 0 if that value is in the range [minValue, maxValue], or minValue if 0 is not in the range

limit

private int limit(int value)
Returns value limited to the range [minValue, maxValue].

Parameters:
value - the value to limit
Returns:
value limited to the range [minValue, maxValue].

noValue

private int noValue()
Returns 0 if that value is in the range [minValue, maxValue]. Otherwise, returns minValue.