Class next.util.keyValue

CLASS DESCRIPTION

Extends:
java.lang.Object

This class adds a form of "key-value coding" to objects that inherit from java.lang.Object (also see the documentation for the next.util.KeyValueCoding interface). Key-value coding allows you to access the properties of an object indirectly by name (or key), rather than directly through invocation of an accessor method or as instance variables. This allows you to access any object's state in a consistent manner.

The methods in this class first search the target object for a method with the same name as the key, invoking it if one is found. If no such method is found, the object is then searched for a field whose name matches the key. If an appropriately-named field is found, the content of the field is accessed. Otherwise, an exception is thrown.

The basic methods for accessing an enterprise object's values are getValue and setValue. These two methods are defined to use the accessor methods normally implemented by objects (or to access instance variables directly if need be). Similarly named methods allow access to floats, ints, and longs.

Objective-C programmers can think of this class as being similar in spirit to a category on java.lang.Object. Because this is a class, however, you use it as follows:

rather than The get... and set... methods in this class all throw exceptions if no key is found. If you are unsure about the existence of a given key, use hasKey(). The get... and set... methods also throw an exception if the key's type isn't compatible with the corresponding value.

CONSTRUCTORS

keyValue

public keyValue()

Allocates and initializes a keyValue object.


METHODS

getFloatValue

public static float getFloatValue(java.lang.Object anObject, java.lang.String key)

Returns the value for the property identified by key. This method throws an exception if the resulting value isn't a float.


getIntValue

public static int getIntValue(java.lang.Object anObject, java.lang.String key)

Returns the value for the property identified by key. This method throws an exception if the resulting value isn't an integer.


getLongValue

public static long getLongValue(java.lang.Object anObject, java.lang.String key)

Returns the value for the property identified by key. This method throws an exception if the resulting value isn't a long integer.


getValue

public static java.lang.Object getValue(java.lang.Object anObject, java.lang.String key)

Returns the value for the property identified by key. This method throws an exception if the resulting value isn't an Object.


hasKey

public static boolean hasKey(java.lang.Object anObject, java.lang.String key)

Returns true if the anObject either has a method or a field named key.


setFloatValue

public static void setFloatValue(java.lang.Object anObject, java.lang.String key, float aFloat)

Sets within anObject the value for the property identified by key to aFloat. This method throws an exception if the property within anObject doesn't accept a float.


setIntValue

public static void setIntValue(java.lang.Object anObject, java.lang.String key, int anInt)

Sets within anObject the value for the property identified by key to anInt. This method throws an exception if the property within anObject doesn't accept an integer.


setLongValue

public static void setLongValue(java.lang.Object anObject, java.lang.String key, long aLong)

Sets within anObject the value for the property identified by key to aLong. This method throws an exception if the property within anObject doesn't accept a long integer.


setValue

public static void setValue(java.lang.Object anObject, java.lang.String key, java.lang.Object aValue)

Sets within anObject the value for the property identified by key to aValue. This method throws an exception if the property within anObject doesn't accept an Object.