incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From danhayw...@apache.org
Subject svn commit: r1375284 - in /incubator/isis/trunk/framework/core/metamodel/src: main/java/org/apache/isis/core/metamodel/adapter/oid/ test/java/org/apache/isis/core/metamodel/adapter/oid/
Date Mon, 20 Aug 2012 22:27:03 GMT
Author: danhaywood
Date: Mon Aug 20 22:27:02 2012
New Revision: 1375284

URL: http://svn.apache.org/viewvc?rev=1375284&view=rev
Log:
ISIS-14: adding RootOid#compareAgainst

... to allow RootOid to comparisons itself against other, taking into account any version
info.

Added:
    incubator/isis/trunk/framework/core/metamodel/src/test/java/org/apache/isis/core/metamodel/adapter/oid/OidMarshallerTest_roundtripping.java
      - copied, changed from r1373642, incubator/isis/trunk/framework/core/metamodel/src/test/java/org/apache/isis/core/metamodel/adapter/oid/OidMarshaller_roundtripping.java
    incubator/isis/trunk/framework/core/metamodel/src/test/java/org/apache/isis/core/metamodel/adapter/oid/RootOidDefaultTest_compareAgainst.java
    incubator/isis/trunk/framework/core/metamodel/src/test/java/org/apache/isis/core/metamodel/adapter/oid/RootOidDefaultTest_create.java
      - copied, changed from r1373642, incubator/isis/trunk/framework/core/metamodel/src/test/java/org/apache/isis/core/metamodel/adapter/oid/RootOidTest_create.java
Removed:
    incubator/isis/trunk/framework/core/metamodel/src/test/java/org/apache/isis/core/metamodel/adapter/oid/OidMarshaller_roundtripping.java
    incubator/isis/trunk/framework/core/metamodel/src/test/java/org/apache/isis/core/metamodel/adapter/oid/RootOidTest_create.java
Modified:
    incubator/isis/trunk/framework/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/oid/RootOid.java
    incubator/isis/trunk/framework/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/oid/RootOidDefault.java

Modified: incubator/isis/trunk/framework/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/oid/RootOid.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/oid/RootOid.java?rev=1375284&r1=1375283&r2=1375284&view=diff
==============================================================================
--- incubator/isis/trunk/framework/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/oid/RootOid.java
(original)
+++ incubator/isis/trunk/framework/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/oid/RootOid.java
Mon Aug 20 22:27:02 2012
@@ -51,4 +51,40 @@ public interface RootOid extends TypedOi
      */
     RootOid asPersistent(String identifier);
 
+    /**
+     * The result of performing a {@link #compareTo(Comparison) comparison.}
+     */
+    public static enum Comparison {
+        /**
+         * The two {@link RootOid oid}s identify the same domain object,
+         * (meaning {@link RootOid#equals(Object) equals} method returns <tt>true</tt>)
+         * and the {@link RootOid#getVersion() version information} held within the 
+         * oid is the same.
+         */
+        EQUIVALENT_AND_UNCHANGED,
+        /**
+         * The two {@link RootOid oid}s identify the same domain object,
+         * (meaning {@link RootOid#equals(Object) equals} method returns <tt>true</tt>)
+         * but the {@link RootOid#getVersion() version information} held within the 
+         * oid is the different.
+         */
+        EQUIVALENT_BUT_CHANGED,
+        /**
+         * The two {@link RootOid oid}s identify the same domain object,
+         * (meaning {@link RootOid#equals(Object) equals} method returns <tt>true</tt>)
+         * but there is no {@link RootOid#getVersion() version information} so 
+         * cannot determine whether the domain object has changed.
+         */
+        EQUIVALENT_BUT_NO_VERSION_INFO,
+        /**
+         * The two {@link RootOid oid}s identify the different domain objects,
+         * (meaning {@link RootOid#equals(Object) equals} method returns <tt>false</tt>).
+         * 
+         * <p>
+         */
+        NOT_EQUIVALENT,
+    }
+    
+    Comparison compareAgainst(RootOid oid2);
+
 }

Modified: incubator/isis/trunk/framework/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/oid/RootOidDefault.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/oid/RootOidDefault.java?rev=1375284&r1=1375283&r2=1375284&view=diff
==============================================================================
--- incubator/isis/trunk/framework/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/oid/RootOidDefault.java
(original)
+++ incubator/isis/trunk/framework/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/oid/RootOidDefault.java
Mon Aug 20 22:27:02 2012
@@ -181,6 +181,19 @@ public final class RootOidDefault implem
 		return version;
 	}
 
+    @Override
+    public Comparison compareAgainst(RootOid other) {
+        if(!equals(other)) {
+            return Comparison.NOT_EQUIVALENT;
+        }
+        if(getVersion() == null || other.getVersion() == null) {
+            return Comparison.EQUIVALENT_BUT_NO_VERSION_INFO;
+        }
+        return getVersion().equals(other.getVersion()) 
+                ? Comparison.EQUIVALENT_AND_UNCHANGED
+                : Comparison.EQUIVALENT_BUT_CHANGED;
+    }
+
     
     // ////////////////////////////////////////////
     // equals, hashCode
@@ -204,11 +217,11 @@ public final class RootOidDefault implem
         if (getClass() != other.getClass()) {
             return false;
         }
-        return equals((RootOidDefault) other);
+        return equals((RootOid) other);
     }
 
-    public boolean equals(final RootOidDefault other) {
-        return Objects.equal(objectSpecId, other.objectSpecId) && Objects.equal(identifier,
other.identifier) && Objects.equal(state, other.state);
+    public boolean equals(final RootOid other) {
+        return Objects.equal(objectSpecId, other.getObjectSpecId()) && Objects.equal(identifier,
other.getIdentifier()) && Objects.equal(isTransient(), other.isTransient());
     }
 
     @Override
@@ -221,6 +234,7 @@ public final class RootOidDefault implem
         return enString(new OidMarshaller());
     }
 
+    
 
 
 }

Copied: incubator/isis/trunk/framework/core/metamodel/src/test/java/org/apache/isis/core/metamodel/adapter/oid/OidMarshallerTest_roundtripping.java
(from r1373642, incubator/isis/trunk/framework/core/metamodel/src/test/java/org/apache/isis/core/metamodel/adapter/oid/OidMarshaller_roundtripping.java)
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/core/metamodel/src/test/java/org/apache/isis/core/metamodel/adapter/oid/OidMarshallerTest_roundtripping.java?p2=incubator/isis/trunk/framework/core/metamodel/src/test/java/org/apache/isis/core/metamodel/adapter/oid/OidMarshallerTest_roundtripping.java&p1=incubator/isis/trunk/framework/core/metamodel/src/test/java/org/apache/isis/core/metamodel/adapter/oid/OidMarshaller_roundtripping.java&r1=1373642&r2=1375284&rev=1375284&view=diff
==============================================================================
--- incubator/isis/trunk/framework/core/metamodel/src/test/java/org/apache/isis/core/metamodel/adapter/oid/OidMarshaller_roundtripping.java
(original)
+++ incubator/isis/trunk/framework/core/metamodel/src/test/java/org/apache/isis/core/metamodel/adapter/oid/OidMarshallerTest_roundtripping.java
Mon Aug 20 22:27:02 2012
@@ -25,7 +25,7 @@ import static org.junit.Assert.assertTha
 import org.apache.isis.core.metamodel.spec.ObjectSpecId;
 import org.junit.Test;
 
-public class OidMarshaller_roundtripping {
+public class OidMarshallerTest_roundtripping {
 
     private OidMarshaller oidMarshaller = new OidMarshaller();
     

Added: incubator/isis/trunk/framework/core/metamodel/src/test/java/org/apache/isis/core/metamodel/adapter/oid/RootOidDefaultTest_compareAgainst.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/core/metamodel/src/test/java/org/apache/isis/core/metamodel/adapter/oid/RootOidDefaultTest_compareAgainst.java?rev=1375284&view=auto
==============================================================================
--- incubator/isis/trunk/framework/core/metamodel/src/test/java/org/apache/isis/core/metamodel/adapter/oid/RootOidDefaultTest_compareAgainst.java
(added)
+++ incubator/isis/trunk/framework/core/metamodel/src/test/java/org/apache/isis/core/metamodel/adapter/oid/RootOidDefaultTest_compareAgainst.java
Mon Aug 20 22:27:02 2012
@@ -0,0 +1,73 @@
+package org.apache.isis.core.metamodel.adapter.oid;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+import org.apache.isis.core.metamodel.spec.ObjectSpecId;
+import org.junit.Test;
+
+public class RootOidDefaultTest_compareAgainst  {
+
+    private ObjectSpecId cusObjectSpecId = ObjectSpecId.of("CUS");
+    private ObjectSpecId ordObjectSpecId = ObjectSpecId.of("ORD");
+    
+    private RootOid oid1, oid2;
+    
+    @Test
+    public void whenEquivalentAndSameVersion() throws Exception {
+        oid1 = RootOidDefault.create(cusObjectSpecId, "123", 90807L);
+        oid2 = RootOidDefault.create(cusObjectSpecId, "123", 90807L);
+        
+        assertThat(oid1, is(equalTo(oid2)));
+        assertThat(oid1.compareAgainst(oid2), is(RootOid.Comparison.EQUIVALENT_AND_UNCHANGED));
+    }
+    
+    @Test
+    public void whenEquivalentAndDifferentVersions() throws Exception {
+        oid1 = RootOidDefault.create(cusObjectSpecId, "123", 90807L);
+        oid2 = RootOidDefault.create(cusObjectSpecId, "123", 90808L);
+        
+        assertThat(oid1, is(equalTo(oid2)));
+        assertThat(oid1.compareAgainst(oid2), is(RootOid.Comparison.EQUIVALENT_BUT_CHANGED));
+    }
+
+    @Test
+    public void whenEquivalentAndNoVersionInfoForLeftHand() throws Exception {
+        oid1 = RootOidDefault.create(cusObjectSpecId, "123");
+        oid2 = RootOidDefault.create(cusObjectSpecId, "123", 90808L);
+        
+        assertThat(oid1, is(equalTo(oid2)));
+        assertThat(oid1.compareAgainst(oid2), is(RootOid.Comparison.EQUIVALENT_BUT_NO_VERSION_INFO));
+    }
+
+    @Test
+    public void whenEquivalentAndNoVersionInfoForRightHand() throws Exception {
+        oid1 = RootOidDefault.create(cusObjectSpecId, "123", 90807L);
+        oid2 = RootOidDefault.create(cusObjectSpecId, "123");
+        
+        assertThat(oid1, is(equalTo(oid2)));
+        assertThat(oid1.compareAgainst(oid2), is(RootOid.Comparison.EQUIVALENT_BUT_NO_VERSION_INFO));
+    }
+
+    @Test
+    public void whenEquivalentAndNoVersionInfoForEither() throws Exception {
+        oid1 = RootOidDefault.create(cusObjectSpecId, "123");
+        oid2 = RootOidDefault.create(cusObjectSpecId, "123");
+        
+        assertThat(oid1, is(equalTo(oid2)));
+        assertThat(oid1.compareAgainst(oid2), is(RootOid.Comparison.EQUIVALENT_BUT_NO_VERSION_INFO));
+    }
+
+    @Test
+    public void whenNotEquivalent() throws Exception {
+        oid1 = RootOidDefault.create(cusObjectSpecId, "123");
+        oid2 = RootOidDefault.create(cusObjectSpecId, "124");
+        
+        assertThat(oid1, is(not(equalTo(oid2))));
+        assertThat(oid1.compareAgainst(oid2), is(RootOid.Comparison.NOT_EQUIVALENT));
+    }
+
+
+}

Copied: incubator/isis/trunk/framework/core/metamodel/src/test/java/org/apache/isis/core/metamodel/adapter/oid/RootOidDefaultTest_create.java
(from r1373642, incubator/isis/trunk/framework/core/metamodel/src/test/java/org/apache/isis/core/metamodel/adapter/oid/RootOidTest_create.java)
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/core/metamodel/src/test/java/org/apache/isis/core/metamodel/adapter/oid/RootOidDefaultTest_create.java?p2=incubator/isis/trunk/framework/core/metamodel/src/test/java/org/apache/isis/core/metamodel/adapter/oid/RootOidDefaultTest_create.java&p1=incubator/isis/trunk/framework/core/metamodel/src/test/java/org/apache/isis/core/metamodel/adapter/oid/RootOidTest_create.java&r1=1373642&r2=1375284&rev=1375284&view=diff
==============================================================================
--- incubator/isis/trunk/framework/core/metamodel/src/test/java/org/apache/isis/core/metamodel/adapter/oid/RootOidTest_create.java
(original)
+++ incubator/isis/trunk/framework/core/metamodel/src/test/java/org/apache/isis/core/metamodel/adapter/oid/RootOidDefaultTest_create.java
Mon Aug 20 22:27:02 2012
@@ -7,7 +7,7 @@ import static org.junit.Assert.assertTha
 import org.apache.isis.core.metamodel.spec.ObjectSpecId;
 import org.junit.Test;
 
-public class RootOidTest_create  {
+public class RootOidDefaultTest_create  {
 
 
     @Test



Mime
View raw message