com.marringtons.object
Class POJO

java.lang.Object
  extended bycom.marringtons.object.POJO
All Implemented Interfaces:
Comparable

public class POJO
extends Object
implements Comparable

By inheriting from POJO instead of Object, classes get working deep copy(), equals(), hashCode(), toString() and Comparable methods. Tje toString() method provides a readable XML representation rather than just an address. The only downside is that if the POJO is transmitted to a remote system (RMI, SOAP, etc), that system will need to have marringtons.library.jar on the classpath.

Author:
Paul Marrington
See Also:
DAO, ObjectXML, ObjectScraper

Constructor Summary
POJO()
           
 
Method Summary
 int compareTo(Object that)
          DO a deep compare of the objects down to their component primatives and strings.
 POJO copy()
          Return a deep copy of a POJO.
 boolean equals(Object that)
          This is a deep equals - all component classes are compared recursively.
 int hashCode()
          This is a deep hashCode.
 String toString()
          The String representation of an object is in XML.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

POJO

public POJO()
Method Detail

copy

public POJO copy()
Return a deep copy of a POJO. While this will work with most data types, it is possible to make them too complex.

Returns:
a deep copy of the POJO as a new object.

equals

public boolean equals(Object that)
This is a deep equals - all component classes are compared recursively. Only primatives and Strings are compared, everything else is broken down to them.

Parameters:
that - to compare against.
Returns:
True if they are logically the same information.
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
This is a deep hashCode. The object is recursively broken down to primatives and Strings and their hashCodes are combined for the result. Note that this is a non-trivial operation. Hashcodes should be stored not recalculated. It is not possible to do this here since the data comprising the code may change.

Returns:
unique code for this item - use the record number.
See Also:
Object.hashCode()

compareTo

public int compareTo(Object that)
DO a deep compare of the objects down to their component primatives and strings.

Specified by:
compareTo in interface Comparable
Parameters:
that - to compare to.
Returns:
-1, 0 or 1.
See Also:
Comparable.compareTo(java.lang.Object)

toString

public String toString()
The String representation of an object is in XML.

Returns:
XML representation of the object.
See Also:
Object.toString()


Copyright © 2005 Paul Marrington http://library.marringtons.com