com.metamatrix.common.object
Class PropertiedObjectImpl

java.lang.Object
  extended by com.metamatrix.common.object.PropertiedObjectImpl
All Implemented Interfaces:
PropertiedObject, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable

public class PropertiedObjectImpl
extends java.lang.Object
implements PropertiedObject, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable

This class provides an implementation of a PropertiedObject, including basic management of properties and property definitions. However, the compareTo and equals assumes that the values either implement the Comparable interface or they are comparable after toString() is called on each value.

See Also:
Serialized Form

Constructor Summary
  PropertiedObjectImpl(java.util.List propertyDefns)
          Create an instance of the PropertiedObject, specifying the list of PropertyDefinition instances to be used.
protected PropertiedObjectImpl(PropertiedObjectImpl original)
           
 
Method Summary
 java.lang.Object clone()
           
protected  int compare(PropertiedObjectImpl that)
           
 int compareTo(java.lang.Object obj)
          Compares this object to another.
protected  int computeHashCode()
          Return a new hash code value for this instance.
 boolean containsAllRequiredValues()
           
 boolean equals(java.lang.Object obj)
          Returns true if the specified object is semantically equal to this instance.
protected  java.util.Properties getPropertiesObject()
           
 java.util.List getPropertyDefinitions()
          Obtain the list of PropertyDefinitions that apply to the specified object's type.
 java.lang.Object getValue(PropertyDefinition def)
          Obtain from the specified PropertiedObject the property value that corresponds to the specified PropertyDefinition.
 boolean isValidValue(PropertyDefinition def, java.lang.Object value)
          Return whether the specified value is considered valid.
 void load(java.io.InputStream in)
          Reads the properties and values from the input stream according to the Properties.load() method.
protected  void setPropertyDefinitions(java.util.List propertyDefns)
          Set the list of PropertyDefinition instances that this object is to use.
 void setValue(PropertyDefinition def, java.lang.Object value)
          Set on the specified PropertiedObject the value defined by the specified PropertyDefinition.
 void store(java.io.OutputStream out, java.lang.String header)
          Writes this property list (key and element pairs) in this Properties table to the output stream in a format suitable for loading into a Properties table using the load method.
protected  void updateHashCode()
          Update the currently cached hash code value with a newly computed one.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertiedObjectImpl

public PropertiedObjectImpl(java.util.List propertyDefns)
Create an instance of the PropertiedObject, specifying the list of PropertyDefinition instances to be used.

Parameters:
propertyDefns - the list of PropertyDefinition instances; the list is assumed to be immutable, and may never be null

PropertiedObjectImpl

protected PropertiedObjectImpl(PropertiedObjectImpl original)
Method Detail

updateHashCode

protected final void updateHashCode()
Update the currently cached hash code value with a newly computed one. This method should be called in any subclass method that updates any field. This includes constructors.

The implementation of this method invokes the computeHashCode method, which is likely overridden in subclasses.


computeHashCode

protected int computeHashCode()
Return a new hash code value for this instance. If subclasses provide additional and non-transient fields, they should override this method using the following template:
 protected int computeHashCode() {
      int result = super.computeHashCode();
      result = HashCodeUtil.hashCode(result, ... );
      result = HashCodeUtil.hashCode(result, ... );
      return result;
 }
 
Any specialized implementation must not rely upon the hashCode method.

Note that this method does not and cannot actually update the hash code value. Rather, this method is called by the updateHashCode method.

Returns:
the new hash code for this instance.

compareTo

public int compareTo(java.lang.Object obj)

Compares this object to another. If the specified object is an instance of the IODescriptor class, then this method compares the instances; otherwise, it throws a ClassCastException (as instances are comparable only to instances of the same class).

Note: this method is consistent with equals(), meaning that (compare(x, y)==0) == (x.equals(y)).

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
obj - the object that this instance is to be compared to.
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object, respectively.
Throws:
java.lang.IllegalArgumentException - if the specified object reference is null
java.lang.ClassCastException - if the specified object's type prevents it from being compared to this instance.

compare

protected int compare(PropertiedObjectImpl that)

equals

public boolean equals(java.lang.Object obj)
Returns true if the specified object is semantically equal to this instance. Note: this method is consistent with compareTo().

Overrides:
equals in class java.lang.Object
Parameters:
obj - the object that this instance is to be compared to.
Returns:
whether the object is equal to this object.

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

getPropertyDefinitions

public java.util.List getPropertyDefinitions()
Obtain the list of PropertyDefinitions that apply to the specified object's type.

Returns:
an unmodifiable list of the PropertyDefinition objects that define the properties for the object; never null but possibly empty
Throws:
java.lang.AssertionError - if obj is null

setPropertyDefinitions

protected void setPropertyDefinitions(java.util.List propertyDefns)
Set the list of PropertyDefinition instances that this object is to use.

Parameters:
propertyDefns - the list of PropertyDefinition instances; the list is assumed to be immutable, and may never be null

getValue

public java.lang.Object getValue(PropertyDefinition def)
Obtain from the specified PropertiedObject the property value that corresponds to the specified PropertyDefinition. The return type and cardinality (including whether the value may be null) depend upon the PropertyDefinition.

Parameters:
def - the reference to the PropertyDefinition describing the property whose value is to be returned; may not be null
Returns:
the value for the property, which may be an empty collection if the property is multi-valued, or may be null if the multiplicity includes "0", or the NO_VALUE reference if the specified object does not contain the specified PropertyDefinition
Throws:
java.lang.AssertionError - if def is null

isValidValue

public boolean isValidValue(PropertyDefinition def,
                            java.lang.Object value)
Return whether the specified value is considered valid. The value is not valid if the propertied object does not have the specified property definition, or if it does but the value is inconsistent with the requirements of the property definition.

Parameters:
def - the reference to the PropertyDefinition describing the property whose value is to be validated; may not be null
value - the proposed value for the property, which may be a collection if the property is multi-valued, or may be null if the multiplicity includes "0"
Returns:
true if the value is considered valid, or false otherwise.
Throws:
java.lang.AssertionError - if either of def is null, or if the property is multi-valued and the value is not an instance of Object[].

setValue

public void setValue(PropertyDefinition def,
                     java.lang.Object value)
Set on the specified PropertiedObject the value defined by the specified PropertyDefinition.

Parameters:
def - the reference to the PropertyDefinition describing the property whose value is to be changed; may not be null
value - the new value for the property; the cardinality and type must conform PropertyDefinition
Throws:
java.lang.IllegalArgumentException - if the value does not correspond to the PropertyDefinition requirements.
java.lang.AssertionError - if either of def is null or if the property is multi-valued and the value is not an instance of Object[].

load

public void load(java.io.InputStream in)
          throws java.io.IOException
Reads the properties and values from the input stream according to the Properties.load() method. Only those properties that have corresponding property definitions in this object are loaded. Note: this implementation is only able to load properties for PropertyDefinitions that have a PropertyType that is represented as String.

Parameters:
in - the input stream, which is not closed by this method; may not be null
Throws:
java.lang.AssertionError - if the InputStream reference is null
java.io.IOException - if an error occurred when reading from the input stream

store

public void store(java.io.OutputStream out,
                  java.lang.String header)
           throws java.io.IOException

Writes this property list (key and element pairs) in this Properties table to the output stream in a format suitable for loading into a Properties table using the load method.

If the header argument is not null, then an ASCII # character, the header string, and a line separator are first written to the output stream. Thus, the header can serve as an identifying comment.

Parameters:
out - an output stream; may not be null
header - a description of the property list, which is not closed by this method; may be null or zero-length
Throws:
java.lang.AssertionError - if the InputStream reference is null
java.io.IOException - if an error occurred when reading from the input stream

getPropertiesObject

protected java.util.Properties getPropertiesObject()

containsAllRequiredValues

public boolean containsAllRequiredValues()


Copyright © 2009. All Rights Reserved.