Id is now a string.
authorErik Brakkee <erik@brakkee.org>
Sat, 13 Aug 2011 14:47:12 +0000 (16:47 +0200)
committerErik Brakkee <erik@brakkee.org>
Sat, 13 Aug 2011 14:47:12 +0000 (16:47 +0200)
Minor change to the site.

src/site/xdoc/developers.xml
support/general/src/main/java/org/wamblee/general/Id.java
support/general/src/test/java/org/wamblee/general/IdTest.java

index 5ef2fab620eb2e365cadcf2dce0299479b321be2..bcd2b4f6f9d2c062de7007fac9035e0e086570a3 100644 (file)
@@ -18,7 +18,7 @@
     <section name="GIT access">
       <p>Anonymous git access is at
           <code>https://wamblee.org/git/public/utils</code></p>
-      <p>More user-friendly access through a browser is at <a
+      <p>Browse the repository at <a
           href="https://wamblee.org/gitweb/utils">https://wamblee.org/gitweb/utils</a>
       </p>
     </section>
index 925732fd1c68fe2ee696f5532481fd712d145be5..c09f849a6e420fd3f81749597cc854e6906cbf62 100644 (file)
@@ -25,28 +25,33 @@ package org.wamblee.general;
  */
 public class Id<T> implements Comparable<Id<T>> {
 
-    private long id;
+    private String id;
 
     /**
      * Constructs the id.
      * 
      * @param aId
      *            Integer id.
+     * @throws NullPointerException
+     *             in case the id is null.
      */
-    public Id(long aId) {
+    public Id(String aId) {
+        if (aId == null) {
+            throw new NullPointerException("id is null");
+        }
         id = aId;
     }
 
     /**
      * @return The underlying id.
      */
-    public long getId() {
+    public String getId() {
         return id;
     }
 
     @Override
     public int hashCode() {
-        return ((Long) id).hashCode();
+        return id.hashCode();
     }
 
     @Override
@@ -57,16 +62,16 @@ public class Id<T> implements Comparable<Id<T>> {
         if (!(aObj instanceof Id)) {
             return false;
         }
-        return id == ((Id<T>) aObj).id;
+        return id.equals(((Id<T>) aObj).id);
     }
 
     @Override
     public String toString() {
-        return id + "";
+        return id;
     }
 
     @Override
-    public int compareTo(org.wamblee.general.Id<T> aId) {
-        return ((Long) id).compareTo((Long) aId.getId());
+    public int compareTo(Id<T> aId) {
+        return id.compareTo(aId.getId());
     }
 }
index 8a442cd522239e539f3447ae822e41545d320630..6b2b1255454b3771e6259f1d3abe823063f31dd8 100644 (file)
@@ -23,23 +23,28 @@ public class IdTest {
 
     @Test
     public void testGetSet() {
-        Id<IdTest> id = new Id<IdTest>(100L);
-        assertEquals(100L, id.getId());
+        Id<IdTest> id = new Id<IdTest>("hello");
+        assertEquals("hello", id.getId());
     }
 
     @Test
     public void testEqualsHashCodeCompare() {
-        Id<IdTest> id1 = new Id<IdTest>(100L);
-        Id<IdTest> id2 = new Id<IdTest>(200L);
-        Id<IdTest> id3 = new Id<IdTest>(100L);
+        Id<IdTest> id1 = new Id<IdTest>("a");
+        Id<IdTest> id2 = new Id<IdTest>("b");
+        Id<IdTest> id3 = new Id<IdTest>("a");
         assertEquals(id1, id3);
         assertFalse(id1.equals(id2));
         assertFalse(id1.equals(null));
-        assertFalse(id1.equals("hello"));
+        assertFalse(id1.equals("a"));
         assertEquals(id1.hashCode(), id3.hashCode());
 
         assertTrue(id1.compareTo(id2) < 0);
         assertTrue(id2.compareTo(id1) > 0);
         assertEquals(0, id1.compareTo(id3));
     }
+
+    @Test(expected = NullPointerException.class)
+    public void testNullNotAccepted() {
+        Id<IdTest> id = new Id<IdTest>(null);
+    }
 }