From: Aron Roberts
Date: Sun, 21 Jun 2009 15:46:15 +0000 (+0000)
Subject: NOJIRA Added additional ID Parts and new methods in IDPart, removed dependencies...
X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=5e64b769d83036b6fcfd913fa92efd335c6a9d0b;p=tmp%2Fjakarta-migration.git
NOJIRA Added additional ID Parts and new methods in IDPart, removed dependencies on Apache Commons Id, added rudimentary ID Pattern.
---
diff --git a/sandbox/aron/id/pom.xml b/sandbox/aron/id/pom.xml
index 60292caa1..1fde68d0c 100644
--- a/sandbox/aron/id/pom.xml
+++ b/sandbox/aron/id/pom.xml
@@ -7,7 +7,11 @@
0.1-SNAPSHOT
id
http://maven.apache.org
-
+
+
+ UTF-8
+
+
org.apache.maven.plugins
@@ -20,11 +24,6 @@
-
- org.apache.commons
- commons-id
- 1.0-SNAPSHOT
-
junit
junit
diff --git a/sandbox/aron/id/src/main/java/org/collectionspace/services/id/AlphabeticGenerator.java b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/AlphabeticGenerator.java
deleted file mode 100644
index 0633ff100..000000000
--- a/sandbox/aron/id/src/main/java/org/collectionspace/services/id/AlphabeticGenerator.java
+++ /dev/null
@@ -1,212 +0,0 @@
- /*
- * AlphabeticGenerator
- *
- * An identifier generator that generates an incrementing ID from any composite
- * of the USASCII character sequences 'A-Z' and 'a-z', as a String object.
- *
- * The wrap property determines whether or not the sequence wraps
- * when it reaches the largest value that can be represented in size.
- * If wrap is false and the the maximum representable
- * value is exceeded, an IllegalStateException is thrown
- *
- * Copyright 2009 Regents of the University of California
- *
- * Licensed under the Educational Community License (ECL), Version 2.0.
- * You may not use this file except in compliance with this License.
- *
- * You may obtain a copy of the ECL 2.0 License at
- * https://source.collectionspace.org/collection-space/LICENSE.txt
- *
- * @author $Author$
- * @version $Revision$
- * $Date$
- */
-
-// @TODO: The initial value determines the fixed number of characters.
-// We may also need to model cases where the number of characters
-// increases as values roll over, up to a specified maximum number of
-// characters; e.g. "z" becomes "aa", and "ZZ" becomes "AAA".
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.collectionspace.services.id;
-
-import org.apache.commons.id.AbstractStringIdentifierGenerator;
-import java.io.Serializable;
-
-public class AlphabeticGenerator extends AbstractStringIdentifierGenerator
- implements Serializable {
-
- /**
- * serialVersionUID is the serializable UID for the binary version of the class.
- */
- // private static final long serialVersionUID = 20060120L; // @TODO ReplaceMe!
-
- /**
- * Should the counter wrap.
- */
- private boolean wrapping = true;
-
- /**
- * The counter.
- */
- private char[] count = null;
- private char[] initialcount = null;
-
- /**
- * 'Z' and 'z' chars
- */
- private static final char LOWERCASE_Z_CHAR = 'z';
- private static final char UPPERCASE_Z_CHAR = 'Z';
-
- /**
- * Constructor with a default size for the alphanumeric identifier.
- *
- * @param wrap should the factory wrap when it reaches the maximum
- * value (or throw an exception)
- */
- public AlphabeticGenerator(boolean wrap) {
- this(wrap, DEFAULT_ALPHANUMERIC_IDENTIFIER_SIZE);
- }
-
- /**
- * Constructor.
- *
- * @param wrap should the factory wrap when it reaches the maximum
- * value (or throw an exception)
- * @param size the size of the identifier
- */
- public AlphabeticGenerator(boolean wrap, int size) {
- super();
- this.wrapping = wrap;
- if (size < 1) {
- throw new IllegalArgumentException("The size must be at least one");
- }
- this.count = new char[size];
-
- // Initialize the contents of the identifier's character array
- for (int i = 0; i < size; i++) {
- count[i] = ' '; // space
- }
- }
-
- /**
- * Construct with a counter, that will start at the specified
- * alphanumeric value.
- *
- * @param wrap should the factory wrap when it reaches the maximum
- * value (or throw an exception)
- * @param initialValue the initial value to start at
- */
- public AlphabeticGenerator(boolean wrap, String initialValue) {
- super();
- this.wrapping = wrap;
-
- if ( initialValue == null ) {
- throw new IllegalArgumentException("Initial value must not be null");
- }
-
- if ( initialValue == "" ) {
- throw new IllegalArgumentException("Initial value must not be empty");
- }
-
- this.count = initialValue.toCharArray();
-
- // Validate each of the characters in the initial value
- // against ranges of valid values.
- for (int i = 0; i < this.count.length; i++) {
- char ch = this.count[i];
- if (ch >= 'A' && ch <= 'Z') continue;
- if (ch >= 'a' && ch <= 'z') continue;
-
- throw new IllegalArgumentException(
- "character " + this.count[i] + " is not valid");
- }
-
- // Store the initial character array
- this.initialcount = this.count;
- }
-
- public long maxLength() {
- return this.count.length;
- }
-
- public long minLength() {
- return this.count.length;
- }
-
- /**
- * Getter for property wrap.
- *
- * @return true if this generator is set up to wrap.
- *
- */
- public boolean isWrap() {
- return wrapping;
- }
-
- /**
- * Sets the wrap property.
- *
- * @param wrap value for the wrap property
- *
- */
- public void setWrap(boolean wrap) {
- this.wrapping = wrap;
- }
-
- /**
- * Returns the (constant) size of the strings generated by this generator.
- *
- * @return the size of generated identifiers
- */
- public int getSize() {
- return this.count.length;
- }
-
- public synchronized String nextStringIdentifier() {
-
- // Get next values for each character from right to left
- for (int i = count.length - 1; i >= 0; i--) {
- switch (count[i]) {
-
- case LOWERCASE_Z_CHAR: // z
- if (i == 0 && !wrapping) {
- throw new IllegalStateException
- ("The maximum number of identifiers has been reached");
- }
- count[i] = 'a';
- break;
-
- case UPPERCASE_Z_CHAR: // Z
- if (i == 0 && !wrapping) {
- throw new IllegalStateException
- ("The maximum number of identifiers has been reached");
- }
- count[i] = 'A';
- break;
-
- default:
- count[i]++;
- i = -1;
- break;
- }
- }
- return new String(count);
- }
-}
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
new file mode 100644
index 000000000..cd7f105ce
--- /dev/null
+++ b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/AlphabeticIDGenerator.java
@@ -0,0 +1,178 @@
+/*
+ * AlphabeticIDGenerator
+ *
+ * An identifier generator that generates an incrementing ID from any composite
+ * of the USASCII character sequences 'A-Z' and 'a-z', as a String object.
+ *
+ * The wrap property determines whether or not the sequence wraps
+ * when it reaches the largest value that can be represented in size.
+ * If wrap is false and the the maximum representable
+ * value is exceeded, an IllegalStateException is thrown
+ *
+ * Copyright 2009 Regents of the University of California
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ *
+ * @author $Author: aron $
+ * @version $Revision: 267 $
+ * $Date: 2009-06-19 19:03:38 -0700 (Fri, 19 Jun 2009) $
+ */
+
+// @TODO: Add Javadoc comments
+
+// @TODO: The initial value determines the fixed number of characters.
+// We may also need to model cases where the number of characters
+// increases as values roll over, up to a specified maximum number of
+// characters; e.g. "z" becomes "aa", and "ZZ" becomes "AAA". When
+// doing so, we'll also need to set a maximum length to which the
+// generated IDs can grow.
+
+// @TODO: This class is hard-coded to use two series within the
+// USASCII character set.
+//
+// With some minor refactoring, we could draw upon minimum and maximum
+// character values for a wide range of arbitrary character sets.
+
+// Some code and algorithms in the current iteration of this class
+// were adapted from the org.apache.commons.Id package, and thus
+// the relevant licensing terms are included here:
+
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License. You may obtain
+ * a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+package org.collectionspace.services.id;
+
+public class AlphabeticIDGenerator implements IDGenerator {
+
+ private static final char LOWERCASE_Z_CHAR = 'z';
+ private static final char UPPERCASE_Z_CHAR = 'Z';
+
+ private char[] initialValue = null;
+ private char[] currentValue = null;
+
+ public AlphabeticIDGenerator(String initialValue) throws IllegalArgumentException {
+
+ if ( initialValue == null ) {
+ throw new IllegalArgumentException("Initial value must not be null");
+ }
+
+ if ( initialValue == "" ) {
+ throw new IllegalArgumentException("Initial value must not be empty");
+ }
+
+ char[] charsToValidate = initialValue.toCharArray();
+
+ // Validate each of the characters in the initial value
+ // against ranges of valid values.
+ for (int i = 0; i < charsToValidate.length; i++) {
+
+ char ch = charsToValidate[i];
+
+ // If the value of the current character matches a character
+ // in the uppercase ('A-Z') or lowercase ('a-z') series
+ // in the USASCII character set, that character has a valid value,
+ // so we can skip to checking the next character.
+ if (ch >= 'A' && ch <= 'Z') continue;
+ if (ch >= 'a' && ch <= 'z') continue;
+
+ // Otherwise, we've detected a character not in those series.
+ throw new IllegalArgumentException(
+ "character " + charsToValidate[i] + " is not valid");
+
+ } // end 'for' loop
+
+ // Store the initial character array
+ this.initialValue = charsToValidate;
+ this.currentValue = charsToValidate;
+
+ }
+
+ public synchronized void reset() {
+ try {
+ // TODO: Investigate using different methods to perform this copying,
+ // such as clone. See "Java Practices - Copy an Array"
+ //
+ // char [] copy = (char []) initialValue.clone();
+ // this.currentValue = copy;
+ // System.arraycopy(
+ // this.initialValue, 0, this.currentValue, 0, this.initialValue.length );
+ for ( int i = 0; i < this.initialValue.length; ++i ) {
+ this.currentValue[i] = this.initialValue[i];
+ }
+ // If copying would cause access of data outside array bounds.
+ } catch (IndexOutOfBoundsException iobe) {
+ // For experimentation - do nothing here at this time.
+ // If an element in the source array could not be stored into
+ // the destination array because of a type mismatch.
+ } catch (ArrayStoreException ase) {
+ // For experimentation - do nothing here at this time.
+ // If either source or destination is null.
+ } catch (NullPointerException npe) {
+ // For experimentation - do nothing here at this time.
+ }
+ }
+
+ public synchronized String getInitialID() {
+ return new String(this.initialValue);
+ }
+
+ public synchronized String getCurrentID() {
+ return new String(this.currentValue);
+ }
+
+ public synchronized String getNextID() {
+
+ // Get next values for each character, from right to left
+ // (least significant to most significant).
+ //
+ // When reaching the maximum value for any character position,
+ // 'roll over' to the minimum value for that position.
+ for (int i = (this.currentValue.length - 1); i >= 0; i--) {
+
+ switch (this.currentValue[i]) {
+
+ case LOWERCASE_Z_CHAR: // z
+ if (i == 0) {
+ throw new IllegalStateException(
+ "The maximum number of IDs has been reached");
+ }
+ this.currentValue[i] = 'a';
+ break;
+
+ case UPPERCASE_Z_CHAR: // Z
+ if (i == 0) {
+ throw new IllegalStateException(
+ "The maximum number of IDs has been reached");
+ }
+ this.currentValue[i] = 'A';
+ break;
+
+ default:
+ this.currentValue[i]++;
+ i = -1;
+ break;
+
+ } // end switch
+
+ } // end 'for' loop
+
+ return new String(currentValue);
+
+ }
+
+}
diff --git a/sandbox/aron/id/src/main/java/org/collectionspace/services/id/AlphabeticIDPart.java b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/AlphabeticIDPart.java
new file mode 100644
index 000000000..8f97a2687
--- /dev/null
+++ b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/AlphabeticIDPart.java
@@ -0,0 +1,29 @@
+ /*
+ * AlphabeticIDPart
+ *
+ * Models a part of an identifier (ID) whose values are an alphabetic series.
+ *
+ * Copyright 2009 Regents of the University of California
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ *
+ * @author $Author: aron $
+ * @version $Revision: 267 $
+ * $Date: 2009-06-19 19:03:38 -0700 (Fri, 19 Jun 2009) $
+ */
+
+// @TODO: Add Javadoc comments
+
+package org.collectionspace.services.id;
+
+public class AlphabeticIDPart extends IDPart {
+
+ public AlphabeticIDPart(String baseVal) {
+ super(new AlphabeticIDGenerator(baseVal));
+ };
+
+}
diff --git a/sandbox/aron/id/src/main/java/org/collectionspace/services/id/AlphabeticSeriesIDPart.java b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/AlphabeticSeriesIDPart.java
deleted file mode 100644
index 26e32a4f1..000000000
--- a/sandbox/aron/id/src/main/java/org/collectionspace/services/id/AlphabeticSeriesIDPart.java
+++ /dev/null
@@ -1,33 +0,0 @@
- /*
- * AlphabeticSeriesIDPart
- *
- * Models a part of an identifier (ID) whose value is alphabetic,
- * and increments within a series of uppercase and/or lowercase values
- * in the USASCII character sequence.
- *
- * Copyright 2009 Regents of the University of California
- *
- * Licensed under the Educational Community License (ECL), Version 2.0.
- * You may not use this file except in compliance with this License.
- *
- * You may obtain a copy of the ECL 2.0 License at
- * https://source.collectionspace.org/collection-space/LICENSE.txt
- *
- * @author $Author$
- * @version $Revision$
- * $Date$
- */
-
-package org.collectionspace.services.id;
-
-import org.apache.commons.id.StringIdentifierGenerator;
-
-public class AlphabeticSeriesIDPart extends SeriesIDPart {
-
- public AlphabeticSeriesIDPart(String baseVal) {
- // Store the appropriate Alphabetic ID generator and the base value for this part
- // Value 'false' refers to the NO_WRAP behavior of the StringIdentifierGenerator.
- super(new AlphabeticGenerator(false, baseVal), baseVal);
- };
-
-}
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
new file mode 100644
index 000000000..e114592fa
--- /dev/null
+++ b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/IDGenerator.java
@@ -0,0 +1,31 @@
+ /*
+ * IDGenerator
+ *
+ * Interface for a generator class that returns IDs.
+ *
+ * Copyright 2009 Regents of the University of California
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ *
+ * @author $Author: aron $
+ * @version $Revision: 267 $
+ * $Date: 2009-06-19 19:03:38 -0700 (Fri, 19 Jun 2009) $
+ */
+
+package org.collectionspace.services.id;
+
+public interface IDGenerator {
+
+ public void reset();
+
+ public String getInitialID();
+
+ public String getCurrentID();
+
+ public String getNextID();
+
+}
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 90ac7a45b..32bcb7511 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
@@ -1,8 +1,16 @@
/*
* IDPart
*
- * Models a part of an identifier (ID), such as (for instance) an incrementing
- * numeric or alphabetic value, a date value, or a static separator.
+ * Models a part of an identifier (ID).
+ *
+ * Some representative examples of data that can be
+ * managed within IDParts include:
+ *
+ *
+ * - Incrementing numeric or alphabetic values
+ * - Date values
+ * - Static separators
+ *
*
* Copyright 2009 Regents of the University of California
*
@@ -16,39 +24,45 @@
* @version $Revision$
* $Date$
*/
-
-package org.collectionspace.services.id;
-import org.apache.commons.id.StringIdentifierGenerator;
+// @TODO: Add Javadoc comments
+
+package org.collectionspace.services.id;
public abstract class IDPart {
- // Flags to identify whether series-based identifiers
- // wrap to their initial values, after the last value
- // in the series is reached.
- final boolean WRAP = true;
- final boolean NO_WRAP = false;
-
- // An identifier generator
- protected StringIdentifierGenerator generator;
+ // A generator for the types of IDs that are generated by this part.
+ // This generator is passed in at construction time.
+ protected IDGenerator generator;
// Constructor
- public IDPart(StringIdentifierGenerator idGenerator) {
- setGenerator(idGenerator);
+ public IDPart(IDGenerator idGenerator) {
+ this.generator = idGenerator;
}
- // Sets the identifier generator
- protected void setGenerator(StringIdentifierGenerator idGenerator) {
- if (idGenerator != null) {
- generator = idGenerator;
- }
+ // Resets the ID to its initial value.
+ public synchronized void reset() {
+ generator.reset();
+ }
+
+ // Returns the initial value of this ID.
+ public synchronized String getInitialID() {
+ return generator.getInitialID();
}
- // Gets the next identifier
- public String nextIdentifier() {
- // @TODO: Add Exception-handling here ...
- return generator.nextStringIdentifier();
- };
+ // Returns the current value of this ID.
+ public synchronized String getCurrentID() {
+ return generator.getCurrentID();
+ }
+
+ // Returns the next value of this ID.
+ public synchronized String getNextID() {
+ try {
+ return generator.getNextID();
+ } catch (IllegalStateException e) {
+ throw e;
+ }
+ }
// public boolean validate() {};
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
new file mode 100644
index 000000000..e94df2786
--- /dev/null
+++ b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/IDPattern.java
@@ -0,0 +1,68 @@
+ /*
+ * IDPattern
+ *
+ * Models an identifier (ID), which consists of multiple IDParts.
+ *
+ * Copyright 2009 Regents of the University of California
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ *
+ * @author $Author: aron $
+ * @version $Revision: 267 $
+ * $Date: 2009-06-19 19:03:38 -0700 (Fri, 19 Jun 2009) $
+ */
+
+// @TODO: Add Javadoc comments
+
+package org.collectionspace.services.id;
+
+import java.util.Vector;
+
+public class IDPattern {
+
+ final static int MAX_ID_LENGTH = 30;
+
+ private Vector parts = new Vector();
+
+ // Constructor
+ public IDPattern() {
+ }
+
+ // Constructor
+ public IDPattern(Vector partsList) {
+ if (partsList != null) {
+ this.parts = partsList;
+ }
+ }
+
+ public void add(IDPart part) {
+ if (part != null) {
+ this.parts.add(part);
+ }
+ }
+
+ // Returns the current value of this ID.
+ public synchronized String getCurrentID() {
+ StringBuffer sb = new StringBuffer(MAX_ID_LENGTH);
+ for (IDPart part : this.parts) {
+ sb.append(part.getCurrentID());
+ }
+ return sb.toString();
+ }
+
+ // Returns the next value of this ID.
+ public synchronized String getNextID() {
+ StringBuffer sb = new StringBuffer(MAX_ID_LENGTH);
+ for (IDPart part : this.parts) {
+ sb.append(part.getCurrentID());
+ }
+ return sb.toString();
+ }
+
+ // public boolean validate() {};
+
+}
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
new file mode 100644
index 000000000..88dbfbca2
--- /dev/null
+++ b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/NumericIDGenerator.java
@@ -0,0 +1,63 @@
+/*
+ * NumericIDGenerator
+ *
+ * An identifier generator that generates an incrementing ID as a
+ * series of numeric values, beginning from an initial value.
+ *
+ * Copyright 2009 Regents of the University of California
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ *
+ * @author $Author: aron $
+ * @version $Revision: 267 $
+ * $Date: 2009-06-19 19:03:38 -0700 (Fri, 19 Jun 2009) $
+ */
+
+// @TODO: Add Javadoc comments
+
+// @TODO: Need to set and enforce maximum value.
+
+package org.collectionspace.services.id;
+
+public class NumericIDGenerator implements IDGenerator {
+
+ private long initialValue = 0;
+ private long currentValue = 0;
+
+ public NumericIDGenerator(String initialValue) throws IllegalArgumentException {
+ try {
+ long l = Long.parseLong(initialValue.trim());
+ if ( l < 0 ) {
+ throw new IllegalArgumentException("Initial value should be zero (0) or greater");
+ }
+ this.currentValue = l;
+ this.initialValue = l;
+ } catch (NullPointerException e) {
+ throw new IllegalArgumentException("Initial value should not be null");
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException("Initial value must be parseable as a number");
+ }
+ }
+
+ public synchronized void reset() {
+ this.currentValue = this.initialValue;
+ }
+
+ public synchronized String getInitialID() {
+ return Long.toString(this.initialValue);
+ }
+
+ public synchronized String getCurrentID() {
+ return Long.toString(this.currentValue);
+ }
+
+ public synchronized String getNextID() {
+ this.currentValue++;
+ return Long.toString(this.currentValue);
+ }
+
+}
diff --git a/sandbox/aron/id/src/main/java/org/collectionspace/services/id/NumericIDPart.java b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/NumericIDPart.java
new file mode 100644
index 000000000..5d68030fc
--- /dev/null
+++ b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/NumericIDPart.java
@@ -0,0 +1,36 @@
+ /*
+ * NumericIDPart
+ *
+ * Models a part of an identifier (ID) whose values come from an
+ * incrementing numeric series, with those values represented as
+ * String objects.
+ *
+ * Copyright 2009 Regents of the University of California
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ *
+ * @author $Author: aron $
+ * @version $Revision: 267 $
+ * $Date: 2009-06-19 19:03:38 -0700 (Fri, 19 Jun 2009) $
+ */
+
+// @TODO: Add Javadoc comments
+
+package org.collectionspace.services.id;
+
+public class NumericIDPart extends IDPart {
+
+ public NumericIDPart(String baseVal) {
+ // Store the appropriate Numeric ID generator and the base value for this part.
+
+ // @TODO: Determine how to handle the NumberFormatException that will be thrown
+ // from parseLong "if the string does not contain a parsable long." We may
+ // need a shim to perform this conversion prior to setting up the generator.
+ super(new NumericIDGenerator(baseVal));
+ };
+
+}
diff --git a/sandbox/aron/id/src/main/java/org/collectionspace/services/id/SeriesIDPart.java b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/SeriesIDPart.java
deleted file mode 100644
index 9c92f6c1d..000000000
--- a/sandbox/aron/id/src/main/java/org/collectionspace/services/id/SeriesIDPart.java
+++ /dev/null
@@ -1,71 +0,0 @@
- /*
- * SeriesIDPart
- *
- * Models a part of an identifier (ID) whose values are part of a series,
- * such as (for instance) an incrementing numeric or alphabetic value.
- * Values begin at an initial (base) value
- *
- * Copyright 2009 Regents of the University of California
- *
- * Licensed under the Educational Community License (ECL), Version 2.0.
- * You may not use this file except in compliance with this License.
- *
- * You may obtain a copy of the ECL 2.0 License at
- * https://source.collectionspace.org/collection-space/LICENSE.txt
- *
- * @author $Author$
- * @version $Revision$
- * $Date$
- */
-
- package org.collectionspace.services.id;
-
-import org.apache.commons.id.StringIdentifierGenerator;
-
-public abstract class SeriesIDPart extends IDPart {
-
- protected String baseValue = "";
- protected String lastIdGenerated = null;
-
- public SeriesIDPart(StringIdentifierGenerator idGenerator, String baseVal) {
- // Store the identifier generator and base value,
- // and set the current value to the base value
- super(idGenerator);
- setBaseValue(baseVal);
- }
-
- // Store the base value
- protected void setBaseValue(String baseVal) {
- // @TODO: Throw an Exception if the base value is null.
- if (baseVal != null) {
- baseValue = baseVal;
- }
- };
-
- // Get the base value
- public String getBaseValue() {
- return baseValue;
- };
-
- // Get the next identifier in series
- public String nextIdentifier() {
- // @TODO: Add Exception-handling here ...
- // If no identifier has ever been generated,
- // or if the value of the last identifier was reset,
- // return the base value.
- if (lastIdGenerated == null) {
- lastIdGenerated = baseValue;
- return lastIdGenerated;
- // Otherwise, return the next value in the series.
- } else {
- lastIdGenerated = generator.nextStringIdentifier();
- return lastIdGenerated;
- }
- }
-
- // Reset the value of the last identifier generated.
- public void reset() {
- lastIdGenerated = null;
- };
-
-}
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
new file mode 100644
index 000000000..d9e548449
--- /dev/null
+++ b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/StringIDGenerator.java
@@ -0,0 +1,61 @@
+/*
+ * StringIDGenerator
+ *
+ * An identifier generator that stores and returns a static String.
+ *
+ * Copyright 2009 Regents of the University of California
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ *
+ * @author $Author: aron $
+ * @version $Revision: 267 $
+ * $Date: 2009-06-19 19:03:38 -0700 (Fri, 19 Jun 2009) $
+ */
+
+// @TODO: Add Javadoc comments
+
+// @TODO: Need to set and enforce maximum String length.
+
+package org.collectionspace.services.id;
+
+public class StringIDGenerator implements IDGenerator {
+
+ private String initialValue = null;
+ private String currentValue = null;
+
+ public StringIDGenerator(String initialValue) throws IllegalArgumentException {
+
+ if ( initialValue == null ) {
+ throw new IllegalArgumentException("Initial value must not be null");
+ }
+
+ if ( initialValue == "" ) {
+ throw new IllegalArgumentException("Initial value must not be empty");
+ }
+
+ this.initialValue = initialValue;
+ this.currentValue = initialValue;
+
+ }
+
+ public synchronized void reset() {
+ // Do nothing
+ }
+
+ public synchronized String getInitialID() {
+ return this.initialValue;
+ }
+
+ public synchronized String getCurrentID() {
+ return this.currentValue;
+ }
+
+ public synchronized String getNextID() {
+ return this.currentValue;
+ }
+
+}
diff --git a/sandbox/aron/id/src/main/java/org/collectionspace/services/id/StringIDPart.java b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/StringIDPart.java
new file mode 100644
index 000000000..16ae17420
--- /dev/null
+++ b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/StringIDPart.java
@@ -0,0 +1,29 @@
+ /*
+ * StringIDGenerator
+ *
+ * Models a part of an identifier (ID) whose values are an alphabetic series.
+ *
+ * Copyright 2009 Regents of the University of California
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ *
+ * @author $Author: aron $
+ * @version $Revision: 267 $
+ * $Date: 2009-06-19 19:03:38 -0700 (Fri, 19 Jun 2009) $
+ */
+
+// @TODO: Add Javadoc comments
+
+package org.collectionspace.services.id;
+
+public class StringIDPart extends IDPart {
+
+ public StringIDPart(String baseVal) {
+ super(new StringIDGenerator(baseVal));
+ };
+
+}
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
new file mode 100644
index 000000000..0e09bf4ec
--- /dev/null
+++ b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/YearIDGenerator.java
@@ -0,0 +1,82 @@
+/*
+ * YearIDGenerator
+ *
+ * An identifier generator that stores and returns the current year
+ * as a String object.
+ *
+ * Copyright 2009 Regents of the University of California
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ *
+ * @author $Author: aron $
+ * @version $Revision: 267 $
+ * $Date: 2009-06-19 19:03:38 -0700 (Fri, 19 Jun 2009) $
+ */
+
+// @TODO: Add Javadoc comments
+
+// @TODO: Need to understand and reflect time zone issues.
+
+package org.collectionspace.services.id;
+
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+
+public class YearIDGenerator implements IDGenerator {
+
+ private String initialValue = null;
+ private String currentValue = null;
+
+ public YearIDGenerator() throws IllegalArgumentException {
+
+ String currentYear = getCurrentYear();
+ this.initialValue = currentYear;
+ this.currentValue = currentYear;
+
+ }
+
+ public YearIDGenerator(String initialValue) throws IllegalArgumentException {
+
+ if ( initialValue == null ) {
+ throw new IllegalArgumentException("Initial value must not be null");
+ }
+
+ if ( initialValue == "" ) {
+ throw new IllegalArgumentException("Initial value must not be empty");
+ }
+
+ // @TODO: Add regex-based validation here, by calling a
+ // to-be-added validate() method
+
+ this.initialValue = initialValue;
+ this.currentValue = initialValue;
+
+ }
+
+ public synchronized void reset() {
+ this.currentValue = this.initialValue;
+ }
+
+ public synchronized String getInitialID() {
+ return this.initialValue;
+ }
+
+ public synchronized String getCurrentID() {
+ return this.currentValue;
+ }
+
+ public synchronized String getNextID() {
+ return this.currentValue;
+ }
+
+ public String getCurrentYear() {
+ Calendar cal = GregorianCalendar.getInstance();
+ int y = cal.get(Calendar.YEAR);
+ return Integer.toString(y);
+ }
+
+}
diff --git a/sandbox/aron/id/src/main/java/org/collectionspace/services/id/YearIDPart.java b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/YearIDPart.java
new file mode 100644
index 000000000..f0d7ede9d
--- /dev/null
+++ b/sandbox/aron/id/src/main/java/org/collectionspace/services/id/YearIDPart.java
@@ -0,0 +1,34 @@
+ /*
+ * YearIDGenerator
+ *
+ * Models a part of an identifier (ID) whose value is the current year
+ * or a supplied year.
+ *
+ * Copyright 2009 Regents of the University of California
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ *
+ * @author $Author: aron $
+ * @version $Revision: 267 $
+ * $Date: 2009-06-19 19:03:38 -0700 (Fri, 19 Jun 2009) $
+ */
+
+// @TODO: Add Javadoc comments
+
+package org.collectionspace.services.id;
+
+public class YearIDPart extends IDPart {
+
+ public YearIDPart() {
+ super(new YearIDGenerator());
+ };
+
+ public YearIDPart(String baseVal) {
+ super(new YearIDGenerator(baseVal));
+ };
+
+}
diff --git a/sandbox/aron/id/src/test/java/org/collectionspace/services/id/AlphabeticGeneratorTest.java b/sandbox/aron/id/src/test/java/org/collectionspace/services/id/AlphabeticGeneratorTest.java
deleted file mode 100644
index 34d297fb1..000000000
--- a/sandbox/aron/id/src/test/java/org/collectionspace/services/id/AlphabeticGeneratorTest.java
+++ /dev/null
@@ -1,198 +0,0 @@
- /*
- * AlphabeticGeneratorTest
- *
- * Test class for AlphabeticGenerator.
- *
- * Copyright 2009 Regents of the University of California
- *
- * Licensed under the Educational Community License (ECL), Version 2.0.
- * You may not use this file except in compliance with this License.
- *
- * You may obtain a copy of the ECL 2.0 License at
- * https://source.collectionspace.org/collection-space/LICENSE.txt
- *
- * @author $Author$
- * @version $Revision$
- * $Date$
- */
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-// See
-// for Exception handling in JUnit.
-
-package org.collectionspace.services.id;
-
-import org.apache.commons.id.StringIdentifierGenerator;
-import static org.junit.Assert.fail;
-import junit.framework.TestCase;
-
-public class AlphabeticGeneratorTest extends TestCase {
-
- final boolean NO_WRAP = false;
- final boolean WRAP = true;
- StringIdentifierGenerator generator;
-
- public void testNoWrapAndInitialValue() {
-
- // @TODO: Split this test into more focused individual tests
-
- // All lowercase initial values
-
- generator = new AlphabeticGenerator(NO_WRAP, "a");
- assertEquals("b", generator.nextStringIdentifier());
- assertEquals("c", generator.nextStringIdentifier());
-
- generator = new AlphabeticGenerator(NO_WRAP, "x");
- assertEquals("y", generator.nextStringIdentifier());
- assertEquals("z", generator.nextStringIdentifier());
-
- generator = new AlphabeticGenerator(NO_WRAP, "aa");
- assertEquals("ab", generator.nextStringIdentifier());
- assertEquals("ac", generator.nextStringIdentifier());
-
- generator = new AlphabeticGenerator(NO_WRAP, "ay");
- assertEquals("az", generator.nextStringIdentifier());
- assertEquals("ba", generator.nextStringIdentifier());
- assertEquals("bb", generator.nextStringIdentifier());
-
- generator = new AlphabeticGenerator(NO_WRAP, "zx");
- assertEquals("zy", generator.nextStringIdentifier());
- assertEquals("zz", generator.nextStringIdentifier());
-
- // All uppercase initial values
-
- generator = new AlphabeticGenerator(NO_WRAP, "A");
- assertEquals("B", generator.nextStringIdentifier());
- assertEquals("C", generator.nextStringIdentifier());
-
- generator = new AlphabeticGenerator(NO_WRAP, "X");
- assertEquals("Y", generator.nextStringIdentifier());
- assertEquals("Z", generator.nextStringIdentifier());
-
- generator = new AlphabeticGenerator(NO_WRAP, "AA");
- assertEquals("AB", generator.nextStringIdentifier());
- assertEquals("AC", generator.nextStringIdentifier());
-
- generator = new AlphabeticGenerator(NO_WRAP, "AY");
- assertEquals("AZ", generator.nextStringIdentifier());
- assertEquals("BA", generator.nextStringIdentifier());
- assertEquals("BB", generator.nextStringIdentifier());
-
- generator = new AlphabeticGenerator(NO_WRAP, "ZX");
- assertEquals("ZY", generator.nextStringIdentifier());
- assertEquals("ZZ", generator.nextStringIdentifier());
-
- }
-
- public void testWrapAndInitialLowercaseValue() {
-
- generator = new AlphabeticGenerator(WRAP, "x");
- assertEquals("y", generator.nextStringIdentifier());
- assertEquals("z", generator.nextStringIdentifier());
- assertEquals("a", generator.nextStringIdentifier());
-
- generator = new AlphabeticGenerator(WRAP, "zx");
- assertEquals("zy", generator.nextStringIdentifier());
- assertEquals("zz", generator.nextStringIdentifier());
- assertEquals("aa", generator.nextStringIdentifier());
-
- }
-
- public void testOverflowWithNoWrapAndInitialLowercaseValue()
- throws Exception {
-
- try {
- generator = new AlphabeticGenerator(NO_WRAP, "zx");
- assertEquals("zy", generator.nextStringIdentifier());
- assertEquals("zz", generator.nextStringIdentifier());
- // Should throw IllegalStateException
- assertNotNull(generator.nextStringIdentifier());
- fail("Should have thrown IllegalStateException here");
- } catch (IllegalStateException expected) {
- // This Exception should be thrown, and thus the test should pass.
- }
-
- }
-
- public void testWrapAndInitialUppercaseValue() {
-
- generator = new AlphabeticGenerator(WRAP, "X");
- assertEquals("Y", generator.nextStringIdentifier());
- assertEquals("Z", generator.nextStringIdentifier());
- assertEquals("A", generator.nextStringIdentifier());
-
- generator = new AlphabeticGenerator(WRAP, "ZX");
- assertEquals("ZY", generator.nextStringIdentifier());
- assertEquals("ZZ", generator.nextStringIdentifier());
- assertEquals("AA", generator.nextStringIdentifier());
-
- }
-
- public void testOverflowWithNoWrapAndInitialUppercaseValue() {
-
- try {
- generator = new AlphabeticGenerator(NO_WRAP, "ZX");
- assertEquals("ZY", generator.nextStringIdentifier());
- assertEquals("ZZ", generator.nextStringIdentifier());
- // Should throw IllegalStateException
- assertNotNull(generator.nextStringIdentifier());
- fail("Should have thrown IllegalStateException here");
- } catch (IllegalStateException expected) {
- // This Exception should be thrown, and thus the test should pass.
- }
-
- }
-
- public void testNonAlphabeticInitialValue() {
- try {
- generator = new AlphabeticGenerator(NO_WRAP, "&*432");
- fail("Should have thrown IllegalArgumentException here");
- } catch (IllegalArgumentException expected) {
- // This Exception should be thrown, and thus the test should pass.
- }
- }
-
- public void testNullInitialValue() {
- try {
- generator = new AlphabeticGenerator(NO_WRAP, null);
- fail("Should have thrown IllegalArgumentException here");
- } catch (IllegalArgumentException expected) {
- // This Exception should be thrown, and thus the test should pass.
- }
- }
-
- public void testEmptyStringInitialValue() {
- try {
- generator = new AlphabeticGenerator(NO_WRAP, "");
- fail("Should have thrown IllegalArgumentException here");
- } catch (IllegalArgumentException expected) {
- // This Exception should be thrown, and thus the test should pass.
- }
- }
-
- public void testAllSpaceCharsInitialValue() {
- try {
- generator = new AlphabeticGenerator(NO_WRAP, " ");
- fail("Should have thrown IllegalArgumentException here");
- } catch (IllegalArgumentException expected) {
- // This Exception should be thrown, and thus the test should pass.
- }
- }
-
-}
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
new file mode 100644
index 000000000..7599f9f29
--- /dev/null
+++ b/sandbox/aron/id/src/test/java/org/collectionspace/services/id/AlphabeticIDPartTest.java
@@ -0,0 +1,202 @@
+/*
+ * AlphabeticIDPartTest
+ *
+ * Test class for AlphabeticIDPart.
+ *
+ * Copyright 2009 Regents of the University of California
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ *
+ * @author $Author: aron $
+ * @version $Revision: 267 $
+ * $Date: 2009-06-19 19:03:38 -0700 (Fri, 19 Jun 2009) $
+ */
+
+package org.collectionspace.services.id;
+
+import static org.junit.Assert.fail;
+import junit.framework.TestCase;
+
+public class AlphabeticIDPartTest extends TestCase {
+
+ IDPart part;
+
+ public void testGetNextIDLowercase() {
+
+ part = new AlphabeticIDPart("a");
+ assertEquals("b", part.getNextID());
+ assertEquals("c", part.getNextID());
+
+ part = new AlphabeticIDPart("x");
+ assertEquals("y", part.getNextID());
+ assertEquals("z", part.getNextID());
+
+ part = new AlphabeticIDPart("aa");
+ assertEquals("ab", part.getNextID());
+ assertEquals("ac", part.getNextID());
+
+ part = new AlphabeticIDPart("ay");
+ assertEquals("az", part.getNextID());
+ assertEquals("ba", part.getNextID());
+ assertEquals("bb", part.getNextID());
+
+ part = new AlphabeticIDPart("zx");
+ assertEquals("zy", part.getNextID());
+ assertEquals("zz", part.getNextID());
+
+ }
+
+ public void testGetNextIDUppercase() {
+
+ part = new AlphabeticIDPart("A");
+ assertEquals("B", part.getNextID());
+ assertEquals("C", part.getNextID());
+
+ part = new AlphabeticIDPart("X");
+ assertEquals("Y", part.getNextID());
+ assertEquals("Z", part.getNextID());
+
+ part = new AlphabeticIDPart("AA");
+ assertEquals("AB", part.getNextID());
+ assertEquals("AC", part.getNextID());
+
+ part = new AlphabeticIDPart("AY");
+ assertEquals("AZ", part.getNextID());
+ assertEquals("BA", part.getNextID());
+ assertEquals("BB", part.getNextID());
+
+ part = new AlphabeticIDPart("ZX");
+ assertEquals("ZY", part.getNextID());
+ assertEquals("ZZ", part.getNextID());
+
+ }
+
+ public void testResetLowercase() {
+
+ part = new AlphabeticIDPart("zx");
+ assertEquals("zy", part.getNextID());
+ assertEquals("zz", part.getNextID());
+ part.reset();
+ assertEquals("zx", part.getCurrentID());
+
+ }
+
+ public void testResetUppercase() {
+
+ part = new AlphabeticIDPart("RA");
+ assertEquals("RB", part.getNextID());
+ assertEquals("RC", part.getNextID());
+ part.reset();
+ assertEquals("RB", part.getNextID());
+
+ }
+
+ public void testInitialLowercase() {
+
+ part = new AlphabeticIDPart("aaa");
+ assertEquals("aaa", part.getInitialID());
+
+ }
+
+ public void testInitialUppercase() {
+
+ part = new AlphabeticIDPart("AZ");
+ assertEquals("AZ", part.getInitialID());
+
+ }
+
+ public void testCurrentLowercase() {
+
+ part = new AlphabeticIDPart("aaa");
+ assertEquals("aaa", part.getCurrentID());
+ assertEquals("aab", part.getNextID());
+ assertEquals("aac", part.getNextID());
+ assertEquals("aac", part.getCurrentID());
+ assertEquals("aad", part.getNextID());
+
+ }
+
+ public void testCurrentUppercase() {
+
+ part = new AlphabeticIDPart("A");
+ assertEquals("A", part.getCurrentID());
+ assertEquals("B", part.getNextID());
+ assertEquals("C", part.getNextID());
+ assertEquals("C", part.getCurrentID());
+ assertEquals("D", part.getNextID());
+
+ }
+
+ public void testOverflowLowercase() {
+
+ try {
+ part = new AlphabeticIDPart("zx");
+ assertEquals("zy", part.getNextID());
+ assertEquals("zz", part.getNextID());
+ // Should throw IllegalStateException
+ assertNotNull(part.getNextID());
+ fail("Should have thrown IllegalStateException here");
+ } catch (IllegalStateException expected) {
+ // This Exception should be thrown, and thus the test should pass.
+ }
+
+ }
+
+ public void testOverflowUppercase() {
+
+ try {
+ part = new AlphabeticIDPart("X");
+ assertEquals("Y", part.getNextID());
+ assertEquals("Z", part.getNextID());
+ // Should throw IllegalStateException
+ assertNotNull(part.getNextID());
+ fail("Should have thrown IllegalStateException here");
+ } catch (IllegalStateException expected) {
+ // This Exception should be thrown, and thus the test should pass.
+ }
+
+ }
+
+ public void testNonAlphabeticInitialValue() {
+ try {
+ part = new AlphabeticIDPart("&*432");
+ fail("Should have thrown IllegalArgumentException here");
+ } catch (IllegalArgumentException expected) {
+ // This Exception should be thrown, and thus the test should pass.
+ }
+ }
+
+ public void testNullInitialValue() {
+ try {
+ part = new AlphabeticIDPart(null);
+ fail("Should have thrown IllegalArgumentException here");
+ } catch (IllegalArgumentException expected) {
+ // This Exception should be thrown, and thus the test should pass.
+ }
+ }
+
+ public void testEmptyStringInitialValue() {
+ try {
+ part = new AlphabeticIDPart("");
+ fail("Should have thrown IllegalArgumentException here");
+ } catch (IllegalArgumentException expected) {
+ // This Exception should be thrown, and thus the test should pass.
+ }
+ }
+
+ public void testAllSpaceCharsInitialValue() {
+ try {
+ part = new AlphabeticIDPart(" ");
+ fail("Should have thrown IllegalArgumentException here");
+ } catch (IllegalArgumentException expected) {
+ // This Exception should be thrown, and thus the test should pass.
+ }
+ }
+
+ // @TODO: Add more tests of boundary conditions, exceptions ...
+
+}
diff --git a/sandbox/aron/id/src/test/java/org/collectionspace/services/id/AlphabeticSeriesIDPartTest.java b/sandbox/aron/id/src/test/java/org/collectionspace/services/id/AlphabeticSeriesIDPartTest.java
deleted file mode 100644
index 4237ebad5..000000000
--- a/sandbox/aron/id/src/test/java/org/collectionspace/services/id/AlphabeticSeriesIDPartTest.java
+++ /dev/null
@@ -1,44 +0,0 @@
- /*
- * AlphabeticSeriesIDPartTest
- *
- * Test class for AlphabeticSeriesIDPart.
- *
- * Copyright 2009 Regents of the University of California
- *
- * Licensed under the Educational Community License (ECL), Version 2.0.
- * You may not use this file except in compliance with this License.
- *
- * You may obtain a copy of the ECL 2.0 License at
- * https://source.collectionspace.org/collection-space/LICENSE.txt
- *
- * @author $Author$
- * @version $Revision$
- * $Date$
- */
-
-package org.collectionspace.services.id;
-
-import junit.framework.TestCase;
-
-public class AlphabeticSeriesIDPartTest extends TestCase {
-
- AlphabeticSeriesIDPart part;
-
- public void testInitialValue() {
-
- part = new AlphabeticSeriesIDPart("a");
- assertEquals("a", part.nextIdentifier());
- assertEquals("b", part.nextIdentifier());
-
- part = new AlphabeticSeriesIDPart("x");
- assertEquals("x", part.nextIdentifier());
- assertEquals("y", part.nextIdentifier());
- assertEquals("z", part.nextIdentifier());
- part.reset();
- assertEquals("x", part.nextIdentifier());
-
- }
-
- // Add tests of boundary conditions, exceptions ...
-
-}
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
new file mode 100644
index 000000000..07a352c5e
--- /dev/null
+++ b/sandbox/aron/id/src/test/java/org/collectionspace/services/id/IDPatternTest.java
@@ -0,0 +1,62 @@
+/*
+ * IDPatternTest
+ *
+ * Test class for IDPattern.
+ *
+ * Copyright 2009 Regents of the University of California
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ *
+ * @author $Author: aron $
+ * @version $Revision: 267 $
+ * $Date: 2009-06-19 19:03:38 -0700 (Fri, 19 Jun 2009) $
+ */
+
+package org.collectionspace.services.id;
+
+import static org.junit.Assert.fail;
+import java.util.Vector;
+import junit.framework.TestCase;
+
+public class IDPatternTest extends TestCase {
+
+ IDPattern pattern;
+ IDPart part;
+
+ public void testCurrentID() {
+
+ Vector parts = new Vector();
+ parts.add(new YearIDPart("2009"));
+ parts.add(new StringIDPart("."));
+ parts.add(new NumericIDPart("1"));
+ pattern = new IDPattern(parts);
+
+ assertEquals("2009.1", pattern.getCurrentID());
+
+ }
+
+ public void testAddCurrentID() {
+
+ pattern = new IDPattern();
+ pattern.add(new YearIDPart("2009"));
+ pattern.add(new StringIDPart("."));
+ pattern.add(new NumericIDPart("1"));
+
+ assertEquals("2009.1", pattern.getCurrentID());
+
+ }
+
+ public void testEmptyPartsListCurrentID() {
+
+ pattern = new IDPattern();
+ assertEquals("", pattern.getCurrentID());
+
+ }
+
+ // @TODO: Add more tests of boundary conditions, exceptions ...
+
+}
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
new file mode 100644
index 000000000..51a5ba61f
--- /dev/null
+++ b/sandbox/aron/id/src/test/java/org/collectionspace/services/id/NumericIDPartTest.java
@@ -0,0 +1,101 @@
+/*
+ * NumericIDPartTest
+ *
+ * Test class for NumericIDPart.
+ *
+ * Copyright 2009 Regents of the University of California
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ *
+ * @author $Author: aron $
+ * @version $Revision: 267 $
+ * $Date: 2009-06-19 19:03:38 -0700 (Fri, 19 Jun 2009) $
+ */
+
+package org.collectionspace.services.id;
+
+import static org.junit.Assert.fail;
+import junit.framework.TestCase;
+
+public class NumericIDPartTest extends TestCase {
+
+ IDPart part;
+
+ public void testNextID() {
+
+ part = new NumericIDPart("0");
+ assertEquals("1", part.getNextID());
+ assertEquals("2", part.getNextID());
+ assertEquals("3", part.getNextID());
+
+ part = new NumericIDPart("25");
+ assertEquals("26", part.getNextID());
+ assertEquals("27", part.getNextID());
+ assertEquals("28", part.getNextID());
+
+ }
+
+ public void testReset() {
+
+ part = new NumericIDPart("25");
+ assertEquals("26", part.getNextID());
+ assertEquals("27", part.getNextID());
+ assertEquals("28", part.getNextID());
+ part.reset();
+ assertEquals("26", part.getNextID());
+
+ }
+
+ public void testInitialID() {
+
+ part = new NumericIDPart("0");
+ assertEquals("0", part.getInitialID());
+
+ part = new NumericIDPart("25");
+ assertEquals("25", part.getInitialID());
+
+ }
+
+ public void testCurrentID() {
+
+ part = new NumericIDPart("0");
+ assertEquals("0", part.getCurrentID());
+ assertEquals("1", part.getNextID());
+ assertEquals("2", part.getNextID());
+ assertEquals("2", part.getCurrentID());
+ assertEquals("3", part.getNextID());
+
+ part = new NumericIDPart("25");
+ assertEquals("25", part.getCurrentID());
+
+ }
+
+ public void testNullInitialValue() {
+
+ try {
+ part = new NumericIDPart(null);
+ fail("Should have thrown IllegalArgumentException here");
+ } catch (IllegalArgumentException expected) {
+ // This Exception should be thrown, and thus the test should pass.
+ }
+
+ }
+
+ public void testNonLongParseableInitialValue() {
+
+ try {
+ part = new NumericIDPart("not a long parseable value");
+ fail("Should have thrown IllegalArgumentException here");
+ } catch (IllegalArgumentException expected) {
+ // This Exception should be thrown, and thus the test should pass.
+ }
+
+ }
+
+ // @TODO: Add more tests of boundary conditions, exceptions ...
+
+}
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
new file mode 100644
index 000000000..4c0af39a0
--- /dev/null
+++ b/sandbox/aron/id/src/test/java/org/collectionspace/services/id/StringIDPartTest.java
@@ -0,0 +1,76 @@
+/*
+ * StringIDPartTest
+ *
+ * Test class for StringIDPart.
+ *
+ * Copyright 2009 Regents of the University of California
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ *
+ * @author $Author: aron $
+ * @version $Revision: 267 $
+ * $Date: 2009-06-19 19:03:38 -0700 (Fri, 19 Jun 2009) $
+ */
+
+package org.collectionspace.services.id;
+
+import static org.junit.Assert.fail;
+import junit.framework.TestCase;
+
+public class StringIDPartTest extends TestCase {
+
+ IDPart part;
+
+ public void testNextID() {
+ part = new StringIDPart("XYZ");
+ assertEquals("XYZ", part.getNextID());
+ }
+
+ public void testReset() {
+
+ part = new StringIDPart(".");
+ assertEquals(".", part.getNextID());
+ part.reset();
+ assertEquals(".", part.getNextID());
+
+ }
+
+ public void testInitialID() {
+ part = new StringIDPart("-");
+ assertEquals("-", part.getInitialID());
+ }
+
+ public void testCurrentID() {
+ part = new StringIDPart("- -");
+ assertEquals("- -", part.getCurrentID());
+ }
+
+ public void testNullInitialValue() {
+
+ try {
+ part = new StringIDPart(null);
+ fail("Should have thrown IllegalArgumentException here");
+ } catch (IllegalArgumentException expected) {
+ // This Exception should be thrown, and thus the test should pass.
+ }
+
+ }
+
+ public void testEmptyInitialValue() {
+
+ try {
+ part = new StringIDPart("");
+ fail("Should have thrown IllegalArgumentException here");
+ } catch (IllegalArgumentException expected) {
+ // This Exception should be thrown, and thus the test should pass.
+ }
+
+ }
+
+ // @TODO: Add more tests of boundary conditions, exceptions ...
+
+}
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
new file mode 100644
index 000000000..132eae4e9
--- /dev/null
+++ b/sandbox/aron/id/src/test/java/org/collectionspace/services/id/YearIDPartTest.java
@@ -0,0 +1,94 @@
+/*
+ * YearIDPartTest
+ *
+ * Test class for YearIDPart.
+ *
+ * Copyright 2009 Regents of the University of California
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ *
+ * @author $Author: aron $
+ * @version $Revision: 267 $
+ * $Date: 2009-06-19 19:03:38 -0700 (Fri, 19 Jun 2009) $
+ */
+
+package org.collectionspace.services.id;
+
+import static org.junit.Assert.fail;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import junit.framework.TestCase;
+
+public class YearIDPartTest extends TestCase {
+
+ IDPart part;
+ String year = "1999";
+
+ public String getCurrentYear() {
+ Calendar cal = GregorianCalendar.getInstance();
+ int y = cal.get(Calendar.YEAR);
+ return Integer.toString(y);
+ }
+
+ public void testCurrentID() {
+
+ part = new YearIDPart();
+ assertEquals(getCurrentYear(), part.getCurrentID());
+
+ part = new YearIDPart(year);
+ assertEquals(year, part.getCurrentID());
+
+ }
+
+
+/*
+ public void testNextID() {
+ part = new YearIDPart("XYZ");
+ assertEquals("XYZ", part.getNextID());
+ }
+
+ public void testReset() {
+
+ part = new YearIDPart(".");
+ assertEquals(".", part.getNextID());
+ part.reset();
+ assertEquals(".", part.getNextID());
+
+ }
+
+ public void testInitialID() {
+ part = new YearIDPart("-");
+ assertEquals("-", part.getInitialID());
+ }
+
+*/
+
+ public void testNullInitialValue() {
+
+ try {
+ part = new YearIDPart(null);
+ fail("Should have thrown IllegalArgumentException here");
+ } catch (IllegalArgumentException expected) {
+ // This Exception should be thrown, and thus the test should pass.
+ }
+
+ }
+
+ public void testEmptyInitialValue() {
+
+ try {
+ part = new YearIDPart("");
+ fail("Should have thrown IllegalArgumentException here");
+ } catch (IllegalArgumentException expected) {
+ // This Exception should be thrown, and thus the test should pass.
+ }
+
+ }
+
+ // @TODO: Add more tests of boundary conditions, exceptions ...
+
+}
diff --git a/sandbox/aron/id/third-party/commons-id-1.0-SNAPSHOT.jar b/sandbox/aron/id/third-party/commons-id-1.0-SNAPSHOT.jar
deleted file mode 100644
index f60f41a06..000000000
Binary files a/sandbox/aron/id/third-party/commons-id-1.0-SNAPSHOT.jar and /dev/null differ
diff --git a/sandbox/aron/id/third-party/install-third-party.sh b/sandbox/aron/id/third-party/install-third-party.sh
deleted file mode 100644
index 4eca6cc11..000000000
--- a/sandbox/aron/id/third-party/install-third-party.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-#! /bin/sh
-
-mvn install:install-file \
- -Dfile=./commons-id-1.0-SNAPSHOT.jar \
- -DgroupId=org.apache.commons \
- -DartifactId=commons-id \
- -Dversion=1.0-SNAPSHOT \
- -Dpackaging=jar