sim.util
Class Properties

java.lang.Object
  extended by sim.util.Properties
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
CollectionProperties, SimpleProperties

public abstract class Properties
extends java.lang.Object
implements java.io.Serializable

The abstract superclass of Property inspectors. Such a beast inspects an object and returns a list of variables for which there are get and possibly set methods.

There are two such inspectors: SimpleProperties (inspects objects for their slots) and CollectionProperties (inspects Collections, Maps, and arrays for their contents). The easiest way to get an appropriate Properties subclass instance is to simply call the static method Properties.getProperties(object to inspect, .... ). See the SimpleProperties and CollectionProperties classes for specifics about how they define what a Property is. SimpleProperties in particular will beinteresting..

Property inspectors enumerate the Properties in their provided object. SimpleProperties will enumerate each of the slots; and CollectionProperties will enumerate the elements in the corresponding array, Map, Collection, etc. You get the number of Properties with numProperties(). Properties have the following features:

See Also:
Serialized Form

Field Summary
protected  java.lang.Object object
           
 
Constructor Summary
Properties()
           
 
Method Summary
protected abstract  java.lang.Object _setValue(int index, java.lang.Object value)
           
 java.lang.String betterToString(java.lang.Object obj)
          Call this to get a prettier print-name for an object -- converting arrays to a nicer format, for example.
 java.lang.Object getDomain(int index)
          Returns the domain of the property at the given index.
abstract  java.lang.String getName(int index)
          Returns the name of the property at the given index.
 java.lang.Object getObject()
          Returns the original object from which the properties are extracted
static Properties getProperties(java.lang.Object object, boolean expandCollections, boolean includeSuperclasses, boolean includeGetClass)
          Returns a Properties object for the given object.
static Properties getProperties(java.lang.Object object, boolean expandCollections, boolean includeSuperclasses, boolean includeGetClass, boolean includeDomains)
          Returns a Properties object for the given object.
abstract  java.lang.Class getType(int index)
          Returns the Class (or for primitive objects, the primitive TYPE) of the property at the given index.
protected  java.lang.Class getTypeConversion(java.lang.Class type)
           
abstract  java.lang.Object getValue(int index)
          Returns the value of the property at the given index.
 boolean isComposite(int index)
          Returns true if the property at the given index is a "Composite" object, meaning it's not a primitive type (double, int, etc.) nor a String.
abstract  boolean isReadWrite(int index)
          Returns true if the property at the given index is both readable and writable (as opposed to read-only).
abstract  boolean isVolatile()
          Returns true if the number or order of properties could change at any time
abstract  int numProperties()
          Returns the number of properties discovered in the object.
 java.lang.Object setValue(int index, java.lang.Object value)
          Sets the current value of the property.
 java.lang.Object setValue(int index, java.lang.String value)
          Sets the current value of the property to the value parsed from the given string.
protected  java.lang.String typeToName(java.lang.Class type)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

object

protected java.lang.Object object
Constructor Detail

Properties

public Properties()
Method Detail

getProperties

public static Properties getProperties(java.lang.Object object,
                                       boolean expandCollections,
                                       boolean includeSuperclasses,
                                       boolean includeGetClass)
Returns a Properties object for the given object. If expandCollections is true, then if object is a Map, Indexed, or Collection, then it will be treated using CollectionProperties. Otherwise it will be treated using SimpleProperties. Arrays are always treated using CollectionProperties. If includeSuperclasses is true, then any SimpleProperties will include superclasses. If includeGetClass is true, then the Class property will be included. No finite domains will be produced (that is, getDomain(index) will return null for all properties).


getProperties

public static Properties getProperties(java.lang.Object object,
                                       boolean expandCollections,
                                       boolean includeSuperclasses,
                                       boolean includeGetClass,
                                       boolean includeDomains)
Returns a Properties object for the given object. If expandCollections is true, then if object is a Map, Indexed, or Collection, then it will be treated using CollectionProperties. Otherwise it will be treated using SimpleProperties. Arrays are always treated using CollectionProperties. If includeSuperclasses is true, then any SimpleProperties will include superclasses. If includeGetClass is true, then the Class property will be included. If includeDomains is true (which requires a CollectionProperties), then domains will be produced for properties according to the rules in the comments in getDomain(index) below. Otherwise all objects will return a null (infinite) domain.


getObject

public java.lang.Object getObject()
Returns the original object from which the properties are extracted


isVolatile

public abstract boolean isVolatile()
Returns true if the number or order of properties could change at any time


numProperties

public abstract int numProperties()
Returns the number of properties discovered in the object.


getValue

public abstract java.lang.Object getValue(int index)
Returns the value of the property at the given index.


getDomain

public java.lang.Object getDomain(int index)
Returns the domain of the property at the given index. Domains are defined by methods of the form public Object domProperty() and should generally take one of three forms:
null
no domain (domain is infinite).
An array of elements
the domain consists solely of those elements.
A sim.util.Interval
the domain is an inclusive (closed) numerical range defined by the Interval. If the Interval returns Longs, then the domain is considered to be integral; else it is considered to be real-valued.


isReadWrite

public abstract boolean isReadWrite(int index)
Returns true if the property at the given index is both readable and writable (as opposed to read-only).


isComposite

public boolean isComposite(int index)
Returns true if the property at the given index is a "Composite" object, meaning it's not a primitive type (double, int, etc.) nor a String.


getName

public abstract java.lang.String getName(int index)
Returns the name of the property at the given index.


getType

public abstract java.lang.Class getType(int index)
Returns the Class (or for primitive objects, the primitive TYPE) of the property at the given index.


_setValue

protected abstract java.lang.Object _setValue(int index,
                                              java.lang.Object value)

setValue

public java.lang.Object setValue(int index,
                                 java.lang.Object value)
Sets the current value of the property. Simple values (byte, int, etc.) must be boxed (into Byte, Integer, etc.). Then returns the current (hopefully changed) value of the property. Returns null if an error occurs or if the index is out of the range [0 ... numProperties() - 1 ]


setValue

public java.lang.Object setValue(int index,
                                 java.lang.String value)
Sets the current value of the property to the value parsed from the given string. Then returns the current (hopefully changed) value of the property. Returns null if an error occurs or if the index is out of the range [0 ... numProperties() - 1 ]


getTypeConversion

protected java.lang.Class getTypeConversion(java.lang.Class type)

betterToString

public java.lang.String betterToString(java.lang.Object obj)
Call this to get a prettier print-name for an object -- converting arrays to a nicer format, for example.


typeToName

protected java.lang.String typeToName(java.lang.Class type)