public class SimpleProperties extends Properties implements java.io.Serializable
A property Foo exists in a class if there is a getFoo() or isFoo() method. ReadWrite properties are ones for which there is ALSO a setFoo(prop) method. If the property is a numerical one, you can also provide a domain in the form of a function called domFoo(), which returns either an array of Objects or a sim.util.Interval. If no domain function exists, or if the domain function returns null, then it is assumed the property has no domain (it can take on any value). You can also hide a property by creating a boolean method called hideFoo() which returns true.
A few classes have special hard-coded properties because they lack get() and set() methods. Notably: CharSequences (Strings, StringBuffers, StringBuilders, etc.) have toString() considered a property, integer Numbers have longValue() considered a property, other Numbers have doubleValue() considered a property, and Booleans have booleanValue() considered a property. In all cases the name of the property is simply "Value" and it is read-only.
The idea behind domains is to make it easy to create graphical interfaces (sliders, pop-up menus) for the user to set properties, where it's often convenient to know beforehand what values the property can be set to in order to construct the GUI widget appropriately. Here are the domain rules (other than null).
This class allows you to set and get properties on the object via boxing the property (java.lang.Integer for int, for example). You can also pass in a String, and SimpleProperties will parse the appropriate value out of the string automatically without you having to bother checking the type.
If any errors arise from generating the properties, setting them, or getting their values, then the error is printed to the console, but is not thrown: instead typically null is returned.
If the object provided to SimpleProperties is sim.util.Proxiable, then SimpleProperties will call propertiesProxy() on that object to get the "true" object whose properties are to be inspected. This makes it possible for objects to create filter objects which only permit access to certain properties. Generally speaking, such proxies (and indeed any object whose properties will be inspected) should be public, non-anonymous classes. For example, imagine that you've got get/set methods on some property Foo, but you only want SimpleProperties to recognize the get method. Furthermore you have another property called Bar that you want hidden entirely. You can easily do this by making your class Proxiable and providing an inner-class proxy like this:
import sim.util.Proxiable; public class MyClass extends Proxiable { int foo; float bar; public int getFoo() { return foo; } public void setFoo(int val) { foo = val; } public float getBar() { return bar; } public void setBar(float val) { bar = val; } public class MyProxy { public int getFoo() { return foo; } } public Object propertiesProxy() { return new MyProxy(); } }
If the object provided to SimpleProperties is sim.util.Propertied, then SimpleProperties will not scan the object, but instead query the object for a Properties of its own, using the object's properties() method. All accesses to the SimpleProperties will simply get routed to that Properties object instead. This is another filter approach which enables dynamically changing properties, or properties based on features other than get... and set... methods.
object
Constructor and Description |
---|
SimpleProperties(java.lang.Object o)
Gathers all properties for the object, including ones defined in superclasses.
|
SimpleProperties(java.lang.Object o,
boolean allowProxy)
Gathers all properties for the object, including ones defined in superclasses.
|
SimpleProperties(java.lang.Object o,
boolean includeSuperclasses,
boolean includeGetClass)
Deprecated.
Use the full form
|
SimpleProperties(java.lang.Object o,
boolean includeSuperclasses,
boolean includeGetClass,
boolean includeExtensions)
Gathers all properties for the object, possibly including ones defined in superclasses.
|
SimpleProperties(java.lang.Object o,
boolean includeSuperclasses,
boolean includeGetClass,
boolean includeExtensions,
boolean allowProxy)
Gathers all properties for the object, possibly including ones defined in superclasses.
|
Modifier and Type | Method and Description |
---|---|
protected java.lang.Object |
_setValue(int index,
java.lang.Object value) |
java.lang.String |
getDescription(int index)
Returns the description of the property at the given index.
|
java.lang.Object |
getDomain(int index)
Returns the domain of the property at the given index.
|
java.lang.String |
getName(int index)
Returns the name of the given property.
|
SimpleProperties |
getPropertiesSubset(java.lang.String[] propertyNames,
boolean retain)
Produces a new SimpleProperties which is a strict subset of the
existing SimpleProperties where the properties found in propertyNamesToRetain
are retained and other properties are removed.
|
java.lang.Class |
getType(int index)
Returns the return type of the property (see the TYPE_...
|
java.lang.Object |
getValue(int index)
Returns the current value of the property.
|
boolean |
isHidden(int index)
Returns true if the class requested that this property be hidden from the user.
|
boolean |
isReadWrite(int index)
Returns whether or not the property can be written as well as read
Returns false if the index is out of the range [0 ...
|
boolean |
isVolatile()
Returns true if the number or order of properties could change at any time
|
java.util.Comparator |
makeAlphabeticalComparator() |
java.util.Comparator |
makeSimpleComparator(java.lang.String[] filter) |
int |
numProperties()
Returns the number of properties discovered
|
SimpleProperties |
sort(java.util.Comparator c)
Sorts the properties by the following comparator, which
takes two java.lang.reflect.Method objects: these are getMethods for two properties.
|
SimpleProperties |
sort(java.lang.String[] filter)
Sorts the properties by an Simple Comparator (provided by makeSimpleComparator()).
|
SimpleProperties |
sortAlphabetically()
Sorts the properties by an Alphabetical Comparator (provided by makeAlphabeticalComparator()).
|
void |
sortProperties(java.util.Comparator c)
Deprecated.
Use sort(...) instead.
|
java.lang.String |
toString() |
betterToString, getObject, getProperties, getProperties, getProperties, getProperties, getTypeConversion, isComposite, setValue, setValue, typeToName
public SimpleProperties(java.lang.Object o)
public SimpleProperties(java.lang.Object o, boolean allowProxy)
public SimpleProperties(java.lang.Object o, boolean includeSuperclasses, boolean includeGetClass)
public SimpleProperties(java.lang.Object o, boolean includeSuperclasses, boolean includeGetClass, boolean includeExtensions)
public SimpleProperties(java.lang.Object o, boolean includeSuperclasses, boolean includeGetClass, boolean includeExtensions, boolean allowProxy)
public java.util.Comparator makeAlphabeticalComparator()
public java.util.Comparator makeSimpleComparator(java.lang.String[] filter)
public SimpleProperties sortAlphabetically()
public SimpleProperties sort(java.lang.String[] filter)
public void sortProperties(java.util.Comparator c)
public SimpleProperties sort(java.util.Comparator c)
By default SimpleProperties sorts alphabetically by method name, breaking ties by number of arguments (fewer arguments appear earlier), and breaking ties further by lexicographic comparison of the output of each Method's toGenericString() method.
If the underlying object is Propertied, sorting has no effect.
Returns the original SimpleProperties, now sorted.
public boolean isVolatile()
Properties
isVolatile
in class Properties
public int numProperties()
numProperties
in class Properties
public java.lang.String getName(int index)
getName
in class Properties
public boolean isReadWrite(int index)
isReadWrite
in class Properties
public java.lang.Class getType(int index)
getType
in class Properties
public java.lang.Object getValue(int index)
getValue
in class Properties
protected java.lang.Object _setValue(int index, java.lang.Object value)
_setValue
in class Properties
public java.lang.String getDescription(int index)
Properties
getDescription
in class Properties
public java.lang.Object getDomain(int index)
Properties
getDomain
in class Properties
public boolean isHidden(int index)
Properties
isHidden
in class Properties
public SimpleProperties getPropertiesSubset(java.lang.String[] propertyNames, boolean retain)
public java.lang.String toString()
toString
in class java.lang.Object