db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c..@apache.org
Subject svn commit: r159434 - in incubator/jdo/trunk/api20: src/java/javax/jdo/ src/java/javax/jdo/identity/ test/java/javax/jdo/identity/
Date Tue, 29 Mar 2005 22:07:14 GMT
Author: clr
Date: Tue Mar 29 14:07:11 2005
New Revision: 159434

URL: http://svn.apache.org/viewcvs?view=rev&rev=159434
Log:
removed int convenience constructors; added toString() tests

Modified:
    incubator/jdo/trunk/api20/src/java/javax/jdo/Bundle.properties
    incubator/jdo/trunk/api20/src/java/javax/jdo/identity/ByteIdentity.java
    incubator/jdo/trunk/api20/src/java/javax/jdo/identity/CharIdentity.java
    incubator/jdo/trunk/api20/src/java/javax/jdo/identity/IntIdentity.java
    incubator/jdo/trunk/api20/src/java/javax/jdo/identity/LongIdentity.java
    incubator/jdo/trunk/api20/src/java/javax/jdo/identity/ShortIdentity.java
    incubator/jdo/trunk/api20/src/java/javax/jdo/identity/SingleFieldIdentity.java
    incubator/jdo/trunk/api20/src/java/javax/jdo/identity/StringIdentity.java
    incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ByteIdentityTest.java
    incubator/jdo/trunk/api20/test/java/javax/jdo/identity/CharIdentityTest.java
    incubator/jdo/trunk/api20/test/java/javax/jdo/identity/IntIdentityTest.java
    incubator/jdo/trunk/api20/test/java/javax/jdo/identity/LongIdentityTest.java
    incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ShortIdentityTest.java
    incubator/jdo/trunk/api20/test/java/javax/jdo/identity/StringIdentityTest.java

Modified: incubator/jdo/trunk/api20/src/java/javax/jdo/Bundle.properties
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/src/java/javax/jdo/Bundle.properties?view=diff&r1=159433&r2=159434
==============================================================================
--- incubator/jdo/trunk/api20/src/java/javax/jdo/Bundle.properties (original)
+++ incubator/jdo/trunk/api20/src/java/javax/jdo/Bundle.properties Tue Mar 29 14:07:11 2005
@@ -44,5 +44,5 @@
 EXC_NullJndiLoc: The JNDI location argument to this method cannot be null.
 EXC_NamingException: A NamingException was thrown while obtaining the \
 PersistenceManagerFactory at "{0}" from JNDI.
-EXC_StringWrongLength: There must be exactly one character in the input String for CharIdentity.
+EXC_StringWrongLength: There must be exactly one character in the id in the input String
for CharIdentity.
 EXC_IllegalEventType:The event type is outside the range of valid event types.

Modified: incubator/jdo/trunk/api20/src/java/javax/jdo/identity/ByteIdentity.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/src/java/javax/jdo/identity/ByteIdentity.java?view=diff&r1=159433&r2=159434
==============================================================================
--- incubator/jdo/trunk/api20/src/java/javax/jdo/identity/ByteIdentity.java (original)
+++ incubator/jdo/trunk/api20/src/java/javax/jdo/identity/ByteIdentity.java Tue Mar 29 14:07:11
2005
@@ -55,18 +55,10 @@
 
     /** Constructor with class and key.
      * @param pcClass the target class
-     * @param key the key
-     */
-    public ByteIdentity(Class pcClass, int key) {
-        this (pcClass, (byte)key);
-    }
-
-    /** Constructor with class and key.
-     * @param pcClass the target class
      * @param str the key
      */
     public ByteIdentity(Class pcClass, String str) {
-        this (pcClass, Byte.parseByte(str));
+        this (pcClass, Byte.parseByte(justTheId(str)));
     }
 
     /** Constructor only for Externalizable.
@@ -85,7 +77,7 @@
      * @return the key.
      */
     public String toString() {
-        return getTargetClassName() + " " + Byte.toString(key);
+        return getTargetClassName() + ":" + Byte.toString(key);
     }
 
     /** Determine if the other object represents the same object id.

Modified: incubator/jdo/trunk/api20/src/java/javax/jdo/identity/CharIdentity.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/src/java/javax/jdo/identity/CharIdentity.java?view=diff&r1=159433&r2=159434
==============================================================================
--- incubator/jdo/trunk/api20/src/java/javax/jdo/identity/CharIdentity.java (original)
+++ incubator/jdo/trunk/api20/src/java/javax/jdo/identity/CharIdentity.java Tue Mar 29 14:07:11
2005
@@ -59,14 +59,6 @@
         this (pcClass, key.charValue ());
     }
 
-    /** Constructor with class and key.
-     * @param pcClass the target class
-     * @param key the key
-     */
-    public CharIdentity (Class pcClass, int key) {
-        this (pcClass, (char)key);
-    }
-
     /** Constructor with class and key. The String must have exactly one
      * character.
      * @param pcClass the target class
@@ -74,9 +66,10 @@
      */
     public CharIdentity (Class pcClass, String str) {
         super(pcClass);
-        if (str.length() != 1) 
+        String justTheId = justTheId(str);
+        if (justTheId.length() != 1) 
             throw new IllegalArgumentException(msg.msg("EXC_StringWrongLength"));
-        this.key = str.charAt(0);
+        this.key = justTheId.charAt(0);
         computeHashCode();
     }
 
@@ -96,7 +89,7 @@
      * @return the String form of the key
      */
     public String toString () {
-        return getTargetClassName() + " " + key;
+        return getTargetClassName() + ":" + key;
     }
 
     /** Determine if the other object represents the same object id.

Modified: incubator/jdo/trunk/api20/src/java/javax/jdo/identity/IntIdentity.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/src/java/javax/jdo/identity/IntIdentity.java?view=diff&r1=159433&r2=159434
==============================================================================
--- incubator/jdo/trunk/api20/src/java/javax/jdo/identity/IntIdentity.java (original)
+++ incubator/jdo/trunk/api20/src/java/javax/jdo/identity/IntIdentity.java Tue Mar 29 14:07:11
2005
@@ -56,7 +56,7 @@
      * @param str the key
      */
     public IntIdentity (Class pcClass, String str) {
-        this (pcClass, Integer.parseInt (str));
+        this (pcClass, Integer.parseInt (justTheId(str)));
     }
 
     /** Constructor only for Externalizable.
@@ -75,7 +75,7 @@
      * @return the String form of the key
      */
     public String toString () {
-        return getTargetClassName() + " " + key;
+        return getTargetClassName() + ":" + key;
     }
 
     /** Determine if the other object represents the same object id.

Modified: incubator/jdo/trunk/api20/src/java/javax/jdo/identity/LongIdentity.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/src/java/javax/jdo/identity/LongIdentity.java?view=diff&r1=159433&r2=159434
==============================================================================
--- incubator/jdo/trunk/api20/src/java/javax/jdo/identity/LongIdentity.java (original)
+++ incubator/jdo/trunk/api20/src/java/javax/jdo/identity/LongIdentity.java Tue Mar 29 14:07:11
2005
@@ -58,7 +58,7 @@
      * @param str the key
      */
     public LongIdentity (Class pcClass, String str) {
-        this (pcClass, Long.parseLong (str));
+        this (pcClass, Long.parseLong (justTheId(str)));
     }
 
     /** Constructor only for Externalizable.
@@ -77,7 +77,7 @@
      * @return the String form of the key
      */
     public String toString () {
-        return getTargetClassName() + " " + key;
+        return getTargetClassName() + ":" + key;
     }
 
     /** Determine if the other object represents the same object id.

Modified: incubator/jdo/trunk/api20/src/java/javax/jdo/identity/ShortIdentity.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/src/java/javax/jdo/identity/ShortIdentity.java?view=diff&r1=159433&r2=159434
==============================================================================
--- incubator/jdo/trunk/api20/src/java/javax/jdo/identity/ShortIdentity.java (original)
+++ incubator/jdo/trunk/api20/src/java/javax/jdo/identity/ShortIdentity.java Tue Mar 29 14:07:11
2005
@@ -55,18 +55,10 @@
 
     /** Constructor with class and key.
      * @param pcClass the class
-     * @param key the key
-     */
-    public ShortIdentity (Class pcClass, int key) {
-        this (pcClass, (short)key);
-    }
-
-    /** Constructor with class and key.
-     * @param pcClass the class
      * @param str the key
      */
     public ShortIdentity (Class pcClass, String str) {
-        this (pcClass, Short.parseShort (str));
+        this (pcClass, Short.parseShort (justTheId(str)));
     }
 
     /** Constructor only for Externalizable.
@@ -85,7 +77,7 @@
      * @return the String form of the key
      */
     public String toString () {
-        return getTargetClassName() + " " + key;
+        return getTargetClassName() + ":" + key;
     }
 
     /** Determine if the other object represents the same object id.

Modified: incubator/jdo/trunk/api20/src/java/javax/jdo/identity/SingleFieldIdentity.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/src/java/javax/jdo/identity/SingleFieldIdentity.java?view=diff&r1=159433&r2=159434
==============================================================================
--- incubator/jdo/trunk/api20/src/java/javax/jdo/identity/SingleFieldIdentity.java (original)
+++ incubator/jdo/trunk/api20/src/java/javax/jdo/identity/SingleFieldIdentity.java Tue Mar
29 14:07:11 2005
@@ -112,6 +112,14 @@
     public int hashCode() {
         return hashCode;
     }
+    
+    /** Convert the toString representation of a single field identity
+     * to remove the class name. The format of the toString is
+     * <targetClass name:id>.
+     */
+    protected static String justTheId(String str) {
+        return str.substring(str.indexOf(':') + 1);
+    }
 
     /** Write to the output stream.
      * @param out the stream

Modified: incubator/jdo/trunk/api20/src/java/javax/jdo/identity/StringIdentity.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/src/java/javax/jdo/identity/StringIdentity.java?view=diff&r1=159433&r2=159434
==============================================================================
--- incubator/jdo/trunk/api20/src/java/javax/jdo/identity/StringIdentity.java (original)
+++ incubator/jdo/trunk/api20/src/java/javax/jdo/identity/StringIdentity.java Tue Mar 29 14:07:11
2005
@@ -64,7 +64,7 @@
      * @return the String form of the key
      */
     public String toString () {
-        return getTargetClassName() + " " + key;
+        return key;
     }
 
     /** Determine if the other object represents the same object id.

Modified: incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ByteIdentityTest.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ByteIdentityTest.java?view=diff&r1=159433&r2=159434
==============================================================================
--- incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ByteIdentityTest.java (original)
+++ incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ByteIdentityTest.java Tue Mar 29
14:07:11 2005
@@ -55,12 +55,10 @@
         assertFalse ("Not equal ByteIdentity instances compare equal", c1.equals(c3));
     }
 
-    public void testIntConstructor() {
+    public void testToStringConstructor() {
         ByteIdentity c1 = new ByteIdentity(Object.class, (byte)1);
-        ByteIdentity c2 = new ByteIdentity(Object.class, 1);
-        ByteIdentity c3 = new ByteIdentity(Object.class, 2);
+        ByteIdentity c2 = new ByteIdentity(Object.class, c1.toString());
         assertEquals ("Equal ByteIdentity instances compare not equal.", c1, c2);
-        assertFalse ("Not equal ByteIdentity instances compare equal", c1.equals(c3));
     }
 
     public void testStringConstructor() {

Modified: incubator/jdo/trunk/api20/test/java/javax/jdo/identity/CharIdentityTest.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/test/java/javax/jdo/identity/CharIdentityTest.java?view=diff&r1=159433&r2=159434
==============================================================================
--- incubator/jdo/trunk/api20/test/java/javax/jdo/identity/CharIdentityTest.java (original)
+++ incubator/jdo/trunk/api20/test/java/javax/jdo/identity/CharIdentityTest.java Tue Mar 29
14:07:11 2005
@@ -45,15 +45,21 @@
         CharIdentity c2 = new CharIdentity(Object.class, 'a');
         CharIdentity c3 = new CharIdentity(Object.class, 'b');
         assertEquals("Equal CharIdentity instances compare not equal.", c1, c2);
-        assertFalse ("Not equal ByteIdentity instances compare equal", c1.equals(c3));
+        assertFalse ("Not equal CharIdentity instances compare equal", c1.equals(c3));
     }
     
-    public void testIntConstructor() {
+    public void testCharacterConstructor() {
         CharIdentity c1 = new CharIdentity(Object.class, 'a');
-        CharIdentity c2 = new CharIdentity(Object.class, 97);
-        CharIdentity c3 = new CharIdentity(Object.class, 98);
+        CharIdentity c2 = new CharIdentity(Object.class, new Character('a'));
+        CharIdentity c3 = new CharIdentity(Object.class, new Character('b'));
+        assertEquals("Equal CharIdentity instances compare not equal.", c1, c2);
+        assertFalse ("Not equal CharIdentity instances compare equal", c1.equals(c3));
+    }
+    
+    public void testToStringConstructor() {
+        CharIdentity c1 = new CharIdentity(Object.class, 'a');
+        CharIdentity c2 = new CharIdentity(Object.class, c1.toString());
         assertEquals ("Equal CharIdentity instances compare not equal.", c1, c2);
-        assertFalse ("Not equal ByteIdentity instances compare equal", c1.equals(c3));
     }
     
     public void testStringConstructor() {
@@ -61,7 +67,7 @@
         CharIdentity c2 = new CharIdentity(Object.class, "a");
         CharIdentity c3 = new CharIdentity(Object.class, "b");
         assertEquals ("Equal CharIdentity instances compare not equal.", c1, c2);
-        assertFalse ("Not equal ByteIdentity instances compare equal", c1.equals(c3));
+        assertFalse ("Not equal CharIdentity instances compare equal", c1.equals(c3));
     }
     
     public void testStringConstructorTooLong() {
@@ -80,14 +86,6 @@
             return; // good
         }
         fail ("No exception caught for String too short.");
-    }
-    
-    public void testCharacterConstructor() {
-        CharIdentity c1 = new CharIdentity(Object.class, 'a');
-        CharIdentity c2 = new CharIdentity(Object.class, new Character('a'));
-        CharIdentity c3 = new CharIdentity(Object.class, new Character('b'));
-        assertEquals ("Equal CharIdentity instances compare not equal.", c1, c2);
-        assertFalse ("Not equal ByteIdentity instances compare equal", c1.equals(c3));
     }
     
     public void testSerialized() {

Modified: incubator/jdo/trunk/api20/test/java/javax/jdo/identity/IntIdentityTest.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/test/java/javax/jdo/identity/IntIdentityTest.java?view=diff&r1=159433&r2=159434
==============================================================================
--- incubator/jdo/trunk/api20/test/java/javax/jdo/identity/IntIdentityTest.java (original)
+++ incubator/jdo/trunk/api20/test/java/javax/jdo/identity/IntIdentityTest.java Tue Mar 29
14:07:11 2005
@@ -44,15 +44,21 @@
         IntIdentity c2 = new IntIdentity(Object.class, (int)1);
         IntIdentity c3 = new IntIdentity(Object.class, (int)2);
         assertEquals("Equal IntIdentity instances compare not equal.", c1, c2);
-        assertFalse ("Not equal ByteIdentity instances compare equal", c1.equals(c3));
+        assertFalse ("Not equal IntIdentity instances compare equal", c1.equals(c3));
     }
 
-    public void testintConstructor() {
+    public void testIntegerConstructor() {
         IntIdentity c1 = new IntIdentity(Object.class, (int)1);
         IntIdentity c2 = new IntIdentity(Object.class, new Integer((int)1));
         IntIdentity c3 = new IntIdentity(Object.class, new Integer((int)2));
         assertEquals ("Equal intIdentity instances compare not equal.", c1, c2);
-        assertFalse ("Not equal ByteIdentity instances compare equal", c1.equals(c3));
+        assertFalse ("Not equal IntIdentity instances compare equal", c1.equals(c3));
+    }
+
+    public void testToStringConstructor() {
+        IntIdentity c1 = new IntIdentity(Object.class, (int)1);
+        IntIdentity c2 = new IntIdentity(Object.class, c1.toString());
+        assertEquals ("Equal IntIdentity instances compare not equal.", c1, c2);
     }
 
     public void testStringConstructor() {
@@ -60,7 +66,7 @@
         IntIdentity c2 = new IntIdentity(Object.class, "1");
         IntIdentity c3 = new IntIdentity(Object.class, "2");
         assertEquals ("Equal IntIdentity instances compare not equal.", c1, c2);
-        assertFalse ("Not equal ByteIdentity instances compare equal", c1.equals(c3));
+        assertFalse ("Not equal IntIdentity instances compare equal", c1.equals(c3));
     }
     
     public void testIllegalStringConstructor() {

Modified: incubator/jdo/trunk/api20/test/java/javax/jdo/identity/LongIdentityTest.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/test/java/javax/jdo/identity/LongIdentityTest.java?view=diff&r1=159433&r2=159434
==============================================================================
--- incubator/jdo/trunk/api20/test/java/javax/jdo/identity/LongIdentityTest.java (original)
+++ incubator/jdo/trunk/api20/test/java/javax/jdo/identity/LongIdentityTest.java Tue Mar 29
14:07:11 2005
@@ -44,7 +44,7 @@
         LongIdentity c2 = new LongIdentity(Object.class, 1);
         LongIdentity c3 = new LongIdentity(Object.class, 2);
         assertEquals("Equal LongIdentity instances compare not equal.", c1, c2);
-        assertFalse ("Not equal ByteIdentity instances compare equal", c1.equals(c3));
+        assertFalse ("Not equal LongIdentity instances compare equal", c1.equals(c3));
     }
 
     public void testLongConstructor() {
@@ -52,7 +52,13 @@
         LongIdentity c2 = new LongIdentity(Object.class, new Long(1));
         LongIdentity c3 = new LongIdentity(Object.class, new Long(2));
         assertEquals ("Equal LongIdentity instances compare not equal.", c1, c2);
-        assertFalse ("Not equal ByteIdentity instances compare equal", c1.equals(c3));
+        assertFalse ("Not equal LongIdentity instances compare equal", c1.equals(c3));
+    }
+
+    public void testToStringConstructor() {
+        LongIdentity c1 = new LongIdentity(Object.class, Long.MAX_VALUE);
+        LongIdentity c2 = new LongIdentity(Object.class, c1.toString());
+        assertEquals ("Equal LongIdentity instances compare not equal.", c1, c2);
     }
 
     public void testStringConstructor() {
@@ -60,7 +66,7 @@
         LongIdentity c2 = new LongIdentity(Object.class, "1");
         LongIdentity c3 = new LongIdentity(Object.class, "2");
         assertEquals ("Equal LongIdentity instances compare not equal.", c1, c2);
-        assertFalse ("Not equal ByteIdentity instances compare equal", c1.equals(c3));
+        assertFalse ("Not equal LongIdentity instances compare equal", c1.equals(c3));
     }
     
     public void testIllegalStringConstructor() {

Modified: incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ShortIdentityTest.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ShortIdentityTest.java?view=diff&r1=159433&r2=159434
==============================================================================
--- incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ShortIdentityTest.java (original)
+++ incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ShortIdentityTest.java Tue Mar
29 14:07:11 2005
@@ -44,7 +44,7 @@
         ShortIdentity c2 = new ShortIdentity(Object.class, (short)1);
         ShortIdentity c3 = new ShortIdentity(Object.class, (short)2);
         assertEquals("Equal ShortIdentity instances compare not equal.", c1, c2);
-        assertFalse ("Not equal ByteIdentity instances compare equal", c1.equals(c3));
+        assertFalse ("Not equal ShortIdentity instances compare equal", c1.equals(c3));
     }
 
     public void testShortConstructor() {
@@ -52,15 +52,13 @@
         ShortIdentity c2 = new ShortIdentity(Object.class, new Short((short)1));
         ShortIdentity c3 = new ShortIdentity(Object.class, new Short((short)2));
         assertEquals ("Equal ShortIdentity instances compare not equal.", c1, c2);
-        assertFalse ("Not equal ByteIdentity instances compare equal", c1.equals(c3));
+        assertFalse ("Not equal ShortIdentity instances compare equal", c1.equals(c3));
     }
 
-    public void testIntConstructor() {
-        ShortIdentity c1 = new ShortIdentity(Object.class, (short)1);
-        ShortIdentity c2 = new ShortIdentity(Object.class, 1);
-        ShortIdentity c3 = new ShortIdentity(Object.class, 2);
+    public void testToStringConstructor() {
+        ShortIdentity c1 = new ShortIdentity(Object.class, Short.MAX_VALUE);
+        ShortIdentity c2 = new ShortIdentity(Object.class, c1.toString());
         assertEquals ("Equal ShortIdentity instances compare not equal.", c1, c2);
-        assertFalse ("Not equal ByteIdentity instances compare equal", c1.equals(c3));
     }
 
     public void testStringConstructor() {
@@ -68,7 +66,7 @@
         ShortIdentity c2 = new ShortIdentity(Object.class, "1");
         ShortIdentity c3 = new ShortIdentity(Object.class, "2");
         assertEquals ("Equal ShortIdentity instances compare not equal.", c1, c2);
-        assertFalse ("Not equal ByteIdentity instances compare equal", c1.equals(c3));
+        assertFalse ("Not equal ShortIdentity instances compare equal", c1.equals(c3));
     }
     
     public void testIllegalStringConstructor() {

Modified: incubator/jdo/trunk/api20/test/java/javax/jdo/identity/StringIdentityTest.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/test/java/javax/jdo/identity/StringIdentityTest.java?view=diff&r1=159433&r2=159434
==============================================================================
--- incubator/jdo/trunk/api20/test/java/javax/jdo/identity/StringIdentityTest.java (original)
+++ incubator/jdo/trunk/api20/test/java/javax/jdo/identity/StringIdentityTest.java Tue Mar
29 14:07:11 2005
@@ -47,6 +47,12 @@
         assertFalse ("Not equal StringIdentity instances compare equal", c1.equals(c3));
     }
     
+    public void testToStringConstructor() {
+        StringIdentity c1 = new StringIdentity(Object.class, "Now who's talking!");
+        StringIdentity c2 = new StringIdentity(Object.class, c1.toString());
+        assertEquals ("Equal StringIdentity instances compare not equal.", c1, c2);
+    }
+
     public void testSerialized() {
         StringIdentity c1 = new StringIdentity(Object.class, "1");
         StringIdentity c2 = new StringIdentity(Object.class, "1");



Mime
View raw message