db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdo-comm...@db.apache.org
Subject [Apache JDO Wiki] Updated: XMLMetadata
Date Thu, 13 Jan 2005 22:29:50 GMT
   Date: 2005-01-13T14:29:50
   Editor: MichelleCaisse
   Wiki: Apache JDO Wiki
   Page: XMLMetadata
   URL: http://wiki.apache.org/jdo/XMLMetadata

   Added email "Comparing objects in Company package"

Change Log:

------------------------------------------------------------------------------
@@ -88,7 +88,54 @@
 
 This will be the last meeting this year, as the following Friday is Christmas Eve.
 
-Craig 
+Craig
+
+December 16
+
+Hi,
+
+Michael is experimenting with a BeanFactory package available as part of the springframework
[sic]. It allows you to define a graph of JavaBeans via an external xml file.
+
+We're considering using this package as part of the TCK, as we discussed, to implement the
Chapter 18 Completeness Test. The idea is to construct a graph of objects, persist them, and
then make sure they are stored and retrieved correctly. Using a tool like BeanFactory will
simplify the test.
+
+In order to exploit this package, we need to make some adjustments to the Company model that
we have discussed as part of the tck. These changes allow us to implement a graph compare
function that verifies that the object graph created and committed is able to be retrieved
correctly.
+
+We need to define an interface DeepEquality in org.apache.jdo.tck.util that is implemented
by all the classes in the company model that defines a method called deepEquals that does
a deep comparison of "Collection of another DeepEquality". The signature of the methods are
boolean deepEquals(DeepEquality other). We also want a convenience method that "deepEquals"
two collections of DeepEquality.
+
+The model for this pattern is interface Comparable that defines a method int compareTo(Object
other).
+
+The idea is that to compare deep collections, the deepEquals method does:
+
+boolean deepEquals(DeepEquality other) {
+Company c = (Company) other;
+this.name.equals(other.name);
+...
+DeepEqualityHelper.deepEquals(this.depts, other.depts);
+...
+}
+
+class DeepEqualityHelper  {
+boolean deepEquals(Collection mine, Collection other) {
+List myList = new ArrayList(mine);
+Collections.sort(myList);
+List otherList = new ArrayList(other);
+Collections.sort(otherList);
+for (i = 0; i < myList.size()) {
+ if (!(DeepEquality)myList.get(i).deepEquals(otherlist.get(i)) return false;
+}
+return true;
+}
+
+boolean shallowEquals(Collection mine, Collection other) {
+List myList = new ArrayList(mine);
+Collections.sort(myList);
+List otherList = new ArrayList(other);
+Collections.sort(otherList);
+return myList.equals(otherList);
+}
+All classes in Company must define equals to delegate to compare and must implement Comparable
and DeepEquality.
+
+Craig Russell 
 
 December 17:
 

Mime
View raw message