From: Erik Brakkee Date: Sat, 13 Aug 2011 14:47:12 +0000 (+0200) Subject: Id is now a string. X-Git-Tag: wamblee-utils-0.7~5 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=e5f859aa0fcab5a3e4a754e5ebce475faa88a6d3;p=utils Id is now a string. Minor change to the site. --- diff --git a/src/site/xdoc/developers.xml b/src/site/xdoc/developers.xml index 5ef2fab6..bcd2b4f6 100644 --- a/src/site/xdoc/developers.xml +++ b/src/site/xdoc/developers.xml @@ -18,7 +18,7 @@

Anonymous git access is at https://wamblee.org/git/public/utils

-

More user-friendly access through a browser is at Browse the repository at https://wamblee.org/gitweb/utils

diff --git a/support/general/src/main/java/org/wamblee/general/Id.java b/support/general/src/main/java/org/wamblee/general/Id.java index 925732fd..c09f849a 100644 --- a/support/general/src/main/java/org/wamblee/general/Id.java +++ b/support/general/src/main/java/org/wamblee/general/Id.java @@ -25,28 +25,33 @@ package org.wamblee.general; */ public class Id implements Comparable> { - 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 implements Comparable> { if (!(aObj instanceof Id)) { return false; } - return id == ((Id) aObj).id; + return id.equals(((Id) aObj).id); } @Override public String toString() { - return id + ""; + return id; } @Override - public int compareTo(org.wamblee.general.Id aId) { - return ((Long) id).compareTo((Long) aId.getId()); + public int compareTo(Id aId) { + return id.compareTo(aId.getId()); } } diff --git a/support/general/src/test/java/org/wamblee/general/IdTest.java b/support/general/src/test/java/org/wamblee/general/IdTest.java index 8a442cd5..6b2b1255 100644 --- a/support/general/src/test/java/org/wamblee/general/IdTest.java +++ b/support/general/src/test/java/org/wamblee/general/IdTest.java @@ -23,23 +23,28 @@ public class IdTest { @Test public void testGetSet() { - Id id = new Id(100L); - assertEquals(100L, id.getId()); + Id id = new Id("hello"); + assertEquals("hello", id.getId()); } @Test public void testEqualsHashCodeCompare() { - Id id1 = new Id(100L); - Id id2 = new Id(200L); - Id id3 = new Id(100L); + Id id1 = new Id("a"); + Id id2 = new Id("b"); + Id id3 = new Id("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 id = new Id(null); + } }