From: Aron Roberts Date: Wed, 24 Jun 2009 18:48:28 +0000 (+0000) Subject: CSPACE-235,CSPACE-237: Created initial object model for ID generators, parts, and... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=0c33ff77113dbfbbae3e6a69cde959929a2964d8;p=tmp%2Fjakarta-migration.git CSPACE-235,CSPACE-237: Created initial object model for ID generators, parts, and patterns. Created a set of four initial ID generators. --- diff --git a/sandbox/aron/id/src/main/java/org/collectionspace/services/id/AlphabeticIDGenerator.java b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/AlphabeticIDGenerator.java index b34ea4f43..21f268cc7 100644 --- a/sandbox/aron/id/src/main/java/org/collectionspace/services/id/AlphabeticIDGenerator.java +++ b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/AlphabeticIDGenerator.java @@ -170,11 +170,6 @@ public class AlphabeticIDGenerator implements IDGenerator { } - // Reset the current value to the initial value. - public synchronized void reset() { - Collections.copy(this.currentValue, this.initialValue); - } - // Returns the initial value. public synchronized String getInitialID() { return getIDString(this.initialValue); @@ -222,7 +217,14 @@ public class AlphabeticIDGenerator implements IDGenerator { // Set the current value. this.currentValue = new Vector(v); + } + + // Reset the current value to the initial value. + public synchronized void resetID() { + Collections.copy(this.currentValue, this.initialValue); + } + // Returns the next alphabetic ID in the sequence. // @@ -233,7 +235,7 @@ public class AlphabeticIDGenerator implements IDGenerator { // // See the TODOs at the top of this class for additional // functionality that needs to be implemented. - public synchronized String getNextID() { + public synchronized String nextID() { // Get next values for each character, from right to left // (least significant to most significant). @@ -279,7 +281,7 @@ public class AlphabeticIDGenerator implements IDGenerator { } // Returns a String representation of the ID, by appending - // the String values of each character in the Vector. + // the String values of each character. public synchronized String getIDString(Vector v) { StringBuffer sb = new StringBuffer(); for ( Character ch : v ) { diff --git a/sandbox/aron/id/src/main/java/org/collectionspace/services/id/IDGenerator.java b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/IDGenerator.java index 5b43709d2..0963894ee 100644 --- a/sandbox/aron/id/src/main/java/org/collectionspace/services/id/IDGenerator.java +++ b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/IDGenerator.java @@ -24,18 +24,27 @@ package org.collectionspace.services.id; public interface IDGenerator { - public void reset(); - + // Returns the initial value of the ID. public String getInitialID(); + // Gets the current value of an ID. public String getCurrentID(); + // Sets the current value of an ID. public void setCurrentID(String value); - public String getNextID(); + // Resets an ID to its initial value. + public void resetID(); + + // Returns the next ID in the sequence, and sets + // the current value to that ID. + public String nextID(); + // Validates an ID against a pattern of generated IDs. public boolean isValidID(String value); + // Returns a String representation of the regular expression ("regex") + // pattern used to validate instance values of generated IDs. public String getRegex(); } diff --git a/sandbox/aron/id/src/main/java/org/collectionspace/services/id/IDPart.java b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/IDPart.java index ffabe304c..a108c33d8 100644 --- a/sandbox/aron/id/src/main/java/org/collectionspace/services/id/IDPart.java +++ b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/IDPart.java @@ -40,33 +40,33 @@ public abstract class IDPart { this.generator = idGenerator; } - // Resets the ID to its initial value. - public synchronized void reset() { - generator.reset(); - } - - // Returns the initial value of this ID. + // Returns the initial value of the ID associated with this IDPart. public synchronized String getInitialID() { return generator.getInitialID(); } - // Returns the current value of this ID. + // Returns the current value of the ID associated with this IDPart. public synchronized String getCurrentID() { return generator.getCurrentID(); } - // Sets the current value of this ID. + // Sets the current value of the ID associated with this IDPart. public synchronized void setCurrentID(String value) { generator.setCurrentID(value); } - // Returns the next value of this ID. - public synchronized String getNextID() throws IllegalStateException { - return generator.getNextID(); + // Resets the ID associated with this IDPart to its initial value. + public synchronized void resetID() { + generator.resetID(); + } + + // Returns the next ID in the sequence, and sets the current value + // of the ID associated with this IDPart to that next ID. + public synchronized String nextID() throws IllegalStateException { + return generator.nextID(); } - // Validates an instance of the ID, to - // identify if it matches this IDPart's pattern. + // Validates a supplied ID against the pattern of this IDPart. // // Some IDParts may offer generic validation, // while others may offer per-instance valiadation @@ -76,7 +76,8 @@ public abstract class IDPart { return generator.isValidID(value); } - // Returns a regular expression pattern used for ID validation. + // Returns a String representation of the regular expression ("regex") + // pattern used to validate instance values of this IDPart. public synchronized String getRegex() { return generator.getRegex(); } diff --git a/sandbox/aron/id/src/main/java/org/collectionspace/services/id/IDPattern.java b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/IDPattern.java index 3df25ca94..7b848c1e7 100644 --- a/sandbox/aron/id/src/main/java/org/collectionspace/services/id/IDPattern.java +++ b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/IDPattern.java @@ -63,14 +63,22 @@ public class IDPattern { // Returns the current value of this ID, given a // supplied ID that partly matches the pattern. // - // This will result in an ID that matches - // the supplied ID, with an optional next ID component - // that reflects the initial ID of that component. - // (E.g. "2009.5." becomes "2009.5.1", if the next - // ID component is an incrementing numeric IDPart.) + // If the supplied ID fully matches the pattern, + // will return the supplied ID. // - // @TODO: Throws IllegalArgumentException - public synchronized String getCurrentID(String value) { + // However, if the supplied ID is a partial ID, which + // partly "stem-matches" the pattern but does not + // ully match the pattern, will return the partial ID with + // its next ID component appended. The next ID component + // will be set to its initial value. + // + // Examples: + // * 2009.5." becomes "2009.5.1", in a case where the + // next ID component is an incrementing numeric IDPart. + // * "E55-" becomes "E55-a", where the next ID component + // is an incrementing alphabetic IDPart. + public synchronized String getCurrentID(String value) + throws IllegalArgumentException { if (value == null) return value; @@ -101,59 +109,51 @@ public class IDPattern { } } - // If the supplied ID doesn't entirely match the pattern, - // return the supplied ID as the next ID. - // - // @TODO: We may wish to handle this differently, - // such as by throwing an Exception. + // If the supplied ID doesn't partly match the pattern, + // throw an Exception. if (matchedParts == 0) { - // return value; - return "foo1"; + throw new IllegalArgumentException("Supplied ID does not match this ID pattern."); } pattern = Pattern.compile(regex.toString()); matcher = pattern.matcher(value); - // If the supplied ID doesn't entirely match the pattern, - // return the supplied ID as the next ID. - // - // @TODO: We may wish to handle this differently, - // such as by throwing an Exception. + // If the supplied ID doesn't match the pattern built above, + // throw an Exception. (This error condition should likely + // never be reached, but it's here as a guard.) if (! matcher.matches()) { - // return value; - return "foo2"; + throw new IllegalArgumentException("Supplied ID does not match this ID pattern."); } - // Temporary for debugging - // return regex.toString(); - - // Otherwise, if the supplied ID partly matches the pattern, - // split the ID into its components and store those values in - // each of the pattern's IDParts. + // Otherwise, if the supplied ID matches the pattern, + // split the ID into its components and store those + // values in each of the pattern's IDParts. IDPart currentPart; for (int i = 1; i <= matchedParts; i++) { currentPart = this.parts.get(i - 1); currentPart.setCurrentID(matcher.group(i)); } - // Obtain the initial value of the next IDPart, - // and set the current value of that part to its initial value. + // Obtain the initial value of the next IDPart, and + // set the current value of that part to its initial value. // // If the supplied ID fully matches the pattern, there will - // be no 'next' IDPart, and an Exception will be thrown. + // be no 'next' IDPart, and we must catch that Exception below. int nextPartNum = matchedParts; try { String initial = this.parts.get(nextPartNum).getInitialID(); this.parts.get(nextPartNum).setCurrentID(initial); + // Increment the number of matched parts to reflect the + // addition of this next IDPart. matchedParts++; } catch (ArrayIndexOutOfBoundsException e ) { // Do nothing here; we simply won't increment - // the number of matched parts for the loop below. + // the number of matched parts, used in the loop below. } // Call the getCurrentID() method on each of the // supplied IDParts, as well as on the added IDPart - // whose current value was just obtained, if any. + // whose initial value was just obtained, if any. StringBuffer sb = new StringBuffer(); for (int i = 1; i <= matchedParts; i++) { sb.append(this.parts.get(i - 1).getCurrentID()); @@ -163,17 +163,15 @@ public class IDPattern { } - // Returns the next value of this ID. - // - // @TODO: Throws IllegalArgumentException - public synchronized String getNextID() { + // Returns the next value of this ID, and sets the current value to that ID. + public synchronized String nextID() throws IllegalStateException { // Obtain the last (least significant) IDPart, - // and call its getNextID() method, which will + // and call its nextID() method, which will // concurrently set the current value of that ID // to the next ID. int lastPartNum = this.parts.size() - 1; - this.parts.get(lastPartNum).getNextID(); + this.parts.get(lastPartNum).nextID(); // Then call the getCurrentID() method on all of the IDParts StringBuffer sb = new StringBuffer(MAX_ID_LENGTH); @@ -186,23 +184,22 @@ public class IDPattern { } // Returns the next value of this ID, given a - // supplied ID that entirely matches the pattern. - // - // @TODO: Throws IllegalArgumentException - public synchronized String getNextID(String value) { + // supplied ID that entirely matches the pattern, + // and sets the current value to that ID. + public synchronized String nextID(String value) + throws IllegalStateException, IllegalArgumentException { - if (value == null) return value; + if (value == null) { + throw new IllegalArgumentException("Supplied ID cannot be null."); + } Pattern pattern = Pattern.compile(getRegex()); Matcher matcher = pattern.matcher(value); // If the supplied ID doesn't entirely match the pattern, - // return the supplied ID as the next ID. - // - // @TODO: We may wish to handle this differently, - // such as by throwing an Exception. + // throw an Exception. if (! matcher.matches()) { - return value; + throw new IllegalArgumentException("Supplied ID does not match this ID pattern."); } // Otherwise, if the supplied ID entirely matches the pattern, @@ -215,14 +212,14 @@ public class IDPattern { } // Obtain the last (least significant) IDPart, - // and call its getNextID() method, which will + // and call its nextID() method, which will // concurrently set the current value of that ID // to the next ID. // - // @TODO: This code is duplicated in getNextID(), above, + // @TODO: This code is duplicated in nextID(), above, // and thus we may want to refactor this. int lastPartNum = this.parts.size() - 1; - this.parts.get(lastPartNum).getNextID(); + this.parts.get(lastPartNum).nextID(); // Then call the getCurrentID() method on all of the IDParts StringBuffer sb = new StringBuffer(); @@ -236,7 +233,8 @@ public class IDPattern { // Validates a provided ID against the pattern. // - // @TODO May potentially throw at least one pattern-related exception. + // @TODO May potentially throw at least one pattern-related exception; + // we'll need to catch and handle this. public synchronized boolean isValidID(String value) { if (value == null) return false; diff --git a/sandbox/aron/id/src/main/java/org/collectionspace/services/id/NumericIDGenerator.java b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/NumericIDGenerator.java index 69b12e2cf..4d4f7206b 100644 --- a/sandbox/aron/id/src/main/java/org/collectionspace/services/id/NumericIDGenerator.java +++ b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/NumericIDGenerator.java @@ -70,10 +70,6 @@ public class NumericIDGenerator implements IDGenerator { } - public synchronized void reset() { - this.currentValue = this.initialValue; - } - public synchronized String getInitialID() { return Long.toString(this.initialValue); } @@ -82,7 +78,7 @@ public class NumericIDGenerator implements IDGenerator { return Long.toString(this.currentValue); } - // Sets the current value. + // Sets the current value of the ID. public synchronized void setCurrentID(String value) throws IllegalArgumentException { // @TODO Much of this code is copied from the main constructor, @@ -105,7 +101,12 @@ public class NumericIDGenerator implements IDGenerator { this.maxLength = DEFAULT_MAX_LENGTH; } - public synchronized String getNextID() throws IllegalStateException { + public synchronized void resetID() { + this.currentValue = this.initialValue; + } + + // Returns the next ID in the sequence, and sets the current value to that ID. + public synchronized String nextID() throws IllegalStateException { this.currentValue++; String nextID = Long.toString(this.currentValue); if (nextID.length() > this.maxLength) { diff --git a/sandbox/aron/id/src/main/java/org/collectionspace/services/id/StringIDGenerator.java b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/StringIDGenerator.java index 04e8e64c6..e2c2a391e 100644 --- a/sandbox/aron/id/src/main/java/org/collectionspace/services/id/StringIDGenerator.java +++ b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/StringIDGenerator.java @@ -42,10 +42,6 @@ public class StringIDGenerator implements IDGenerator { } - public synchronized void reset() { - // Do nothing - } - public synchronized String getInitialID() { return this.initialValue; } @@ -61,7 +57,11 @@ public class StringIDGenerator implements IDGenerator { this.currentValue = value; } - public synchronized String getNextID() { + public synchronized void resetID() { + // Do nothing + } + + public synchronized String nextID() { return this.currentValue; } diff --git a/sandbox/aron/id/src/main/java/org/collectionspace/services/id/YearIDGenerator.java b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/YearIDGenerator.java index 41f07f2f5..915783511 100644 --- a/sandbox/aron/id/src/main/java/org/collectionspace/services/id/YearIDGenerator.java +++ b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/YearIDGenerator.java @@ -71,10 +71,6 @@ public class YearIDGenerator implements IDGenerator { } - public synchronized void reset() { - this.currentValue = this.initialValue; - } - public synchronized String getInitialID() { return this.initialValue; } @@ -100,12 +96,16 @@ public class YearIDGenerator implements IDGenerator { } + public synchronized void resetID() { + this.currentValue = this.initialValue; + } + // @TODO: We'll need to decide what a "next" ID means in the context of: // - An initially supplied value. // - A year value that has not changed from its previous value. // - A year value that has changed, as a result of a rollover // to a new instant in time. - public synchronized String getNextID() { + public synchronized String nextID() { return this.currentValue; } diff --git a/sandbox/aron/id/src/test/java/org/collectionspace/services/id/AlphabeticIDPartTest.java b/sandbox/aron/id/src/test/java/org/collectionspace/services/id/AlphabeticIDPartTest.java index bbd0aa63b..5b85ad55a 100644 --- a/sandbox/aron/id/src/test/java/org/collectionspace/services/id/AlphabeticIDPartTest.java +++ b/sandbox/aron/id/src/test/java/org/collectionspace/services/id/AlphabeticIDPartTest.java @@ -25,89 +25,89 @@ public class AlphabeticIDPartTest extends TestCase { IDPart part; - public void testGetNextIDLowercase() { + public void testnextIDLowercase() { part = new AlphabeticIDPart("a"); - assertEquals("b", part.getNextID()); - assertEquals("c", part.getNextID()); + assertEquals("b", part.nextID()); + assertEquals("c", part.nextID()); part = new AlphabeticIDPart("x"); - assertEquals("y", part.getNextID()); - assertEquals("z", part.getNextID()); + assertEquals("y", part.nextID()); + assertEquals("z", part.nextID()); } - public void testGetNextIDLowercase2Chars() { + public void testnextIDLowercase2Chars() { part = new AlphabeticIDPart("aa"); - assertEquals("ab", part.getNextID()); - assertEquals("ac", part.getNextID()); + assertEquals("ab", part.nextID()); + assertEquals("ac", part.nextID()); part = new AlphabeticIDPart("zx"); - assertEquals("zy", part.getNextID()); - assertEquals("zz", part.getNextID()); + assertEquals("zy", part.nextID()); + assertEquals("zz", part.nextID()); } - public void testGetNextIDLowercase2CharsRolloverFirst() { + public void testnextIDLowercase2CharsRolloverFirst() { part = new AlphabeticIDPart("ay"); - assertEquals("az", part.getNextID()); - assertEquals("ba", part.getNextID()); - assertEquals("bb", part.getNextID()); + assertEquals("az", part.nextID()); + assertEquals("ba", part.nextID()); + assertEquals("bb", part.nextID()); } - public void testGetNextIDUppercase() { + public void testnextIDUppercase() { part = new AlphabeticIDPart("A", "Z", "A"); - assertEquals("B", part.getNextID()); - assertEquals("C", part.getNextID()); + assertEquals("B", part.nextID()); + assertEquals("C", part.nextID()); part = new AlphabeticIDPart("A", "Z", "X"); - assertEquals("Y", part.getNextID()); - assertEquals("Z", part.getNextID()); + assertEquals("Y", part.nextID()); + assertEquals("Z", part.nextID()); } - public void testGetNextIDUppercase2Chars() { + public void testnextIDUppercase2Chars() { part = new AlphabeticIDPart("A", "Z", "AA"); - assertEquals("AB", part.getNextID()); - assertEquals("AC", part.getNextID()); + assertEquals("AB", part.nextID()); + assertEquals("AC", part.nextID()); part = new AlphabeticIDPart("A", "Z", "ZX"); - assertEquals("ZY", part.getNextID()); - assertEquals("ZZ", part.getNextID()); + assertEquals("ZY", part.nextID()); + assertEquals("ZZ", part.nextID()); } - public void testGetNextIDUppercase2CharsRolloverFirst() { + public void testnextIDUppercase2CharsRolloverFirst() { part = new AlphabeticIDPart("A", "Z", "AY"); - assertEquals("AZ", part.getNextID()); - assertEquals("BA", part.getNextID()); - assertEquals("BB", part.getNextID()); + assertEquals("AZ", part.nextID()); + assertEquals("BA", part.nextID()); + assertEquals("BB", part.nextID()); } - public void testResetLowercase() { + public void testresetIDLowercase() { part = new AlphabeticIDPart("zx"); - assertEquals("zy", part.getNextID()); - assertEquals("zz", part.getNextID()); - part.reset(); + assertEquals("zy", part.nextID()); + assertEquals("zz", part.nextID()); + part.resetID(); assertEquals("zx", part.getCurrentID()); } - public void testResetUppercase() { + public void testresetIDUppercase() { part = new AlphabeticIDPart("A", "Z", "RA"); - assertEquals("RB", part.getNextID()); - assertEquals("RC", part.getNextID()); - part.reset(); - assertEquals("RB", part.getNextID()); + assertEquals("RB", part.nextID()); + assertEquals("RC", part.nextID()); + part.resetID(); + assertEquals("RB", part.nextID()); } @@ -129,10 +129,10 @@ public class AlphabeticIDPartTest extends TestCase { part = new AlphabeticIDPart("aaa"); assertEquals("aaa", part.getCurrentID()); - assertEquals("aab", part.getNextID()); - assertEquals("aac", part.getNextID()); + assertEquals("aab", part.nextID()); + assertEquals("aac", part.nextID()); assertEquals("aac", part.getCurrentID()); - assertEquals("aad", part.getNextID()); + assertEquals("aad", part.nextID()); } @@ -140,28 +140,28 @@ public class AlphabeticIDPartTest extends TestCase { part = new AlphabeticIDPart("A", "Z", "A"); assertEquals("A", part.getCurrentID()); - assertEquals("B", part.getNextID()); - assertEquals("C", part.getNextID()); + assertEquals("B", part.nextID()); + assertEquals("C", part.nextID()); assertEquals("C", part.getCurrentID()); - assertEquals("D", part.getNextID()); + assertEquals("D", part.nextID()); } public void testOverflowLowercase() { part = new AlphabeticIDPart("zx"); - assertEquals("zy", part.getNextID()); - assertEquals("zz", part.getNextID()); - assertEquals("aaa", part.getNextID()); + assertEquals("zy", part.nextID()); + assertEquals("zz", part.nextID()); + assertEquals("aaa", part.nextID()); } public void testOverflowUppercase() { part = new AlphabeticIDPart("A", "Z", "X"); - assertEquals("Y", part.getNextID()); - assertEquals("Z", part.getNextID()); - assertEquals("AA", part.getNextID()); + assertEquals("Y", part.nextID()); + assertEquals("Z", part.nextID()); + assertEquals("AA", part.nextID()); } diff --git a/sandbox/aron/id/src/test/java/org/collectionspace/services/id/IDPatternTest.java b/sandbox/aron/id/src/test/java/org/collectionspace/services/id/IDPatternTest.java index bb89f25e0..e89653522 100644 --- a/sandbox/aron/id/src/test/java/org/collectionspace/services/id/IDPatternTest.java +++ b/sandbox/aron/id/src/test/java/org/collectionspace/services/id/IDPatternTest.java @@ -64,39 +64,39 @@ public class IDPatternTest extends TestCase { pattern.add(new StringIDPart("E")); pattern.add(new NumericIDPart("1")); assertEquals("E1", pattern.getCurrentID("E")); - assertEquals("E2", pattern.getNextID()); + assertEquals("E2", pattern.nextID()); pattern = new IDPattern(); pattern.add(new YearIDPart()); pattern.add(new StringIDPart(".")); assertEquals("2009.", pattern.getCurrentID("2009")); - assertEquals("2009.", pattern.getNextID()); + assertEquals("2009.", pattern.nextID()); assertEquals("2010.", pattern.getCurrentID("2010")); - assertEquals("2010.", pattern.getNextID()); + assertEquals("2010.", pattern.nextID()); pattern = new IDPattern(); pattern.add(new YearIDPart()); pattern.add(new StringIDPart(".")); pattern.add(new NumericIDPart("1")); assertEquals("2009.1", pattern.getCurrentID("2009.")); - assertEquals("2009.2", pattern.getNextID()); + assertEquals("2009.2", pattern.nextID()); pattern = new IDPattern(); pattern.add(new YearIDPart()); pattern.add(new StringIDPart(".")); pattern.add(new NumericIDPart("55")); assertEquals("2010.55", pattern.getCurrentID("2010.")); - assertEquals("2010.56", pattern.getNextID()); + assertEquals("2010.56", pattern.nextID()); pattern = new IDPattern(); pattern.add(new YearIDPart("2009")); pattern.add(new StringIDPart(".")); pattern.add(new NumericIDPart()); assertEquals("2009.1", pattern.getCurrentID("2009.")); - assertEquals("2009.2", pattern.getNextID()); + assertEquals("2009.2", pattern.nextID()); // Test a repeat of the last two operations. assertEquals("2009.1", pattern.getCurrentID("2009.")); - assertEquals("2009.2", pattern.getNextID()); + assertEquals("2009.2", pattern.nextID()); pattern = new IDPattern(); pattern.add(new YearIDPart("2009")); @@ -105,7 +105,7 @@ public class IDPatternTest extends TestCase { pattern.add(new StringIDPart("-")); pattern.add(new AlphabeticIDPart("a")); assertEquals("2009.1-a", pattern.getCurrentID("2009.1-")); - assertEquals("2009.1-b", pattern.getNextID()); + assertEquals("2009.1-b", pattern.nextID()); assertEquals("2009.3-a", pattern.getCurrentID("2009.3-")); } @@ -117,7 +117,7 @@ public class IDPatternTest extends TestCase { pattern.add(new StringIDPart(".")); pattern.add(new NumericIDPart("55")); assertEquals("2009.55", pattern.getCurrentID("2009.55")); - assertEquals("2009.56", pattern.getNextID()); + assertEquals("2009.56", pattern.nextID()); pattern = new IDPattern(); pattern.add(new YearIDPart("2009")); @@ -126,7 +126,7 @@ public class IDPatternTest extends TestCase { pattern.add(new StringIDPart("-")); pattern.add(new AlphabeticIDPart("a")); assertEquals("2009.1-a", pattern.getCurrentID("2009.1-a")); - assertEquals("2009.1-b", pattern.getNextID()); + assertEquals("2009.1-b", pattern.nextID()); } @@ -136,8 +136,8 @@ public class IDPatternTest extends TestCase { pattern.add(new YearIDPart("2009")); pattern.add(new StringIDPart(".")); pattern.add(new NumericIDPart("1")); - assertEquals("2009.2", pattern.getNextID()); - assertEquals("2009.3", pattern.getNextID()); + assertEquals("2009.2", pattern.nextID()); + assertEquals("2009.3", pattern.nextID()); pattern = new IDPattern(); pattern.add(new YearIDPart("2009")); @@ -145,14 +145,14 @@ public class IDPatternTest extends TestCase { pattern.add(new NumericIDPart("1")); pattern.add(new StringIDPart("-")); pattern.add(new AlphabeticIDPart("a")); - assertEquals("2009.1-b", pattern.getNextID()); - assertEquals("2009.1-c", pattern.getNextID()); + assertEquals("2009.1-b", pattern.nextID()); + assertEquals("2009.1-c", pattern.nextID()); pattern = new IDPattern(); pattern.add(new StringIDPart("T")); pattern.add(new NumericIDPart("1005")); - assertEquals("T1006", pattern.getNextID()); - assertEquals("T1007", pattern.getNextID()); + assertEquals("T1006", pattern.nextID()); + assertEquals("T1007", pattern.nextID()); } @@ -163,8 +163,8 @@ public class IDPatternTest extends TestCase { pattern.add(new StringIDPart(".")); pattern.add(new NumericIDPart("1")); pattern.add(new StringIDPart("-")); - assertEquals("2009.1-", pattern.getNextID()); - assertEquals("2009.1-", pattern.getNextID()); + assertEquals("2009.1-", pattern.nextID()); + assertEquals("2009.1-", pattern.nextID()); } @@ -174,8 +174,8 @@ public class IDPatternTest extends TestCase { pattern.add(new YearIDPart("2009")); pattern.add(new StringIDPart(".")); pattern.add(new NumericIDPart("1")); - assertEquals("2009.2", pattern.getNextID("2009.1")); - assertEquals("2009.3", pattern.getNextID("2009.2")); + assertEquals("2009.2", pattern.nextID("2009.1")); + assertEquals("2009.3", pattern.nextID("2009.2")); pattern = new IDPattern(); pattern.add(new YearIDPart("2009")); @@ -183,8 +183,8 @@ public class IDPatternTest extends TestCase { pattern.add(new NumericIDPart("1")); pattern.add(new StringIDPart("-")); pattern.add(new AlphabeticIDPart("a")); - assertEquals("2009.1-b", pattern.getNextID("2009.1-a")); - assertEquals("2009.3-c", pattern.getNextID("2009.3-b")); + assertEquals("2009.1-b", pattern.nextID("2009.1-a")); + assertEquals("2009.3-c", pattern.nextID("2009.3-b")); } diff --git a/sandbox/aron/id/src/test/java/org/collectionspace/services/id/NumericIDPartTest.java b/sandbox/aron/id/src/test/java/org/collectionspace/services/id/NumericIDPartTest.java index 1f3d0cc12..0708300bb 100644 --- a/sandbox/aron/id/src/test/java/org/collectionspace/services/id/NumericIDPartTest.java +++ b/sandbox/aron/id/src/test/java/org/collectionspace/services/id/NumericIDPartTest.java @@ -28,14 +28,14 @@ public class NumericIDPartTest extends TestCase { public void testNextID() { part = new NumericIDPart("0"); - assertEquals("1", part.getNextID()); - assertEquals("2", part.getNextID()); - assertEquals("3", part.getNextID()); + assertEquals("1", part.nextID()); + assertEquals("2", part.nextID()); + assertEquals("3", part.nextID()); part = new NumericIDPart("25"); - assertEquals("26", part.getNextID()); - assertEquals("27", part.getNextID()); - assertEquals("28", part.getNextID()); + assertEquals("26", part.nextID()); + assertEquals("27", part.nextID()); + assertEquals("28", part.nextID()); } @@ -43,9 +43,9 @@ public class NumericIDPartTest extends TestCase { try { part = new NumericIDPart("997", "3"); - assertEquals("998", part.getNextID()); - assertEquals("999", part.getNextID()); - assertEquals("1000", part.getNextID()); + assertEquals("998", part.nextID()); + assertEquals("999", part.nextID()); + assertEquals("1000", part.nextID()); fail("Should have thrown IllegalStateException here"); } catch (IllegalStateException expected) { // This Exception should be thrown, and thus the test should pass. @@ -54,9 +54,9 @@ public class NumericIDPartTest extends TestCase { // Tests default MAX_LENGTH value of 6 decimal places try { part = new NumericIDPart("999997"); - assertEquals("999998", part.getNextID()); - assertEquals("999999", part.getNextID()); - assertEquals("1000000", part.getNextID()); + assertEquals("999998", part.nextID()); + assertEquals("999999", part.nextID()); + assertEquals("1000000", part.nextID()); fail("Should have thrown IllegalStateException here"); } catch (IllegalStateException expected) { // This Exception should be thrown, and thus the test should pass. @@ -64,14 +64,14 @@ public class NumericIDPartTest extends TestCase { } - public void testReset() { + public void testresetID() { part = new NumericIDPart("25"); - assertEquals("26", part.getNextID()); - assertEquals("27", part.getNextID()); - assertEquals("28", part.getNextID()); - part.reset(); - assertEquals("26", part.getNextID()); + assertEquals("26", part.nextID()); + assertEquals("27", part.nextID()); + assertEquals("28", part.nextID()); + part.resetID(); + assertEquals("26", part.nextID()); } @@ -89,10 +89,10 @@ public class NumericIDPartTest extends TestCase { part = new NumericIDPart("0"); assertEquals("0", part.getCurrentID()); - assertEquals("1", part.getNextID()); - assertEquals("2", part.getNextID()); + assertEquals("1", part.nextID()); + assertEquals("2", part.nextID()); assertEquals("2", part.getCurrentID()); - assertEquals("3", part.getNextID()); + assertEquals("3", part.nextID()); part = new NumericIDPart("25"); assertEquals("25", part.getCurrentID()); diff --git a/sandbox/aron/id/src/test/java/org/collectionspace/services/id/StringIDPartTest.java b/sandbox/aron/id/src/test/java/org/collectionspace/services/id/StringIDPartTest.java index d0e40f697..dd3a7a928 100644 --- a/sandbox/aron/id/src/test/java/org/collectionspace/services/id/StringIDPartTest.java +++ b/sandbox/aron/id/src/test/java/org/collectionspace/services/id/StringIDPartTest.java @@ -27,15 +27,15 @@ public class StringIDPartTest extends TestCase { public void testNextID() { part = new StringIDPart("XYZ"); - assertEquals("XYZ", part.getNextID()); + assertEquals("XYZ", part.nextID()); } - public void testReset() { + public void testresetID() { part = new StringIDPart("."); - assertEquals(".", part.getNextID()); - part.reset(); - assertEquals(".", part.getNextID()); + assertEquals(".", part.nextID()); + part.resetID(); + assertEquals(".", part.nextID()); } diff --git a/sandbox/aron/id/src/test/java/org/collectionspace/services/id/YearIDPartTest.java b/sandbox/aron/id/src/test/java/org/collectionspace/services/id/YearIDPartTest.java index 2dee61c79..12b5d85f3 100644 --- a/sandbox/aron/id/src/test/java/org/collectionspace/services/id/YearIDPartTest.java +++ b/sandbox/aron/id/src/test/java/org/collectionspace/services/id/YearIDPartTest.java @@ -48,15 +48,15 @@ public class YearIDPartTest extends TestCase { /* public void testNextID() { part = new YearIDPart("XYZ"); - assertEquals("XYZ", part.getNextID()); + assertEquals("XYZ", part.nextID()); } - public void testReset() { + public void testresetID() { part = new YearIDPart("."); - assertEquals(".", part.getNextID()); - part.reset(); - assertEquals(".", part.getNextID()); + assertEquals(".", part.nextID()); + part.resetID(); + assertEquals(".", part.nextID()); }