<version>0.1-SNAPSHOT</version>
<name>id</name>
<url>http://maven.apache.org</url>
- <build>
+ <properties>
+ <!-- See http://docs.codehaus.org/display/MAVENUSER/POM+Element+for+Source+File+Encoding -->
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
</plugins>
</build>
<dependencies>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-id</artifactId>
- <version>1.0-SNAPSHOT</version>
- </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
+++ /dev/null
- /*
- * AlphabeticGenerator
- *
- * <p>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.</p>
- *
- * <p>The <code>wrap</code> property determines whether or not the sequence wraps
- * when it reaches the largest value that can be represented in <code>size</code>.
- * If <code>wrap</code> is false and the the maximum representable
- * value is exceeded, an IllegalStateException is thrown</p>
- *
- * 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 {
-
- /**
- * <code>serialVersionUID</code> 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.</p>
- *
- * @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 <code>true</code> 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);
- }
-}
--- /dev/null
+/*
+ * AlphabeticIDGenerator
+ *
+ * <p>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.</p>
+ *
+ * <p>The <code>wrap</code> property determines whether or not the sequence wraps
+ * when it reaches the largest value that can be represented in <code>size</code>.
+ * If <code>wrap</code> is false and the the maximum representable
+ * value is exceeded, an IllegalStateException is thrown</p>
+ *
+ * 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"
+ // <http://www.javapractices.com/topic/TopicAction.do?Id=3>
+ // 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);
+
+ }
+
+}
--- /dev/null
+ /*
+ * 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));
+ };
+
+}
+++ /dev/null
- /*
- * 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);
- };
-
-}
--- /dev/null
+ /*
+ * 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();
+
+}
/*
* 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.
+ * <p>Models a part of an identifier (ID).</p>
+ *
+ * <p>Some representative examples of data that can be
+ * managed within IDParts include:</p>
+ *
+ * <ul>
+ * <li>Incrementing numeric or alphabetic values</li>
+ * <li>Date values</li>
+ * <li>Static separators</li>
+ * </ul>
*
* Copyright 2009 Regents of the University of California
*
* @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() {};
--- /dev/null
+ /*
+ * IDPattern
+ *
+ * <p>Models an identifier (ID), which consists of multiple IDParts.</p>
+ *
+ * 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<IDPart> parts = new Vector<IDPart>();
+
+ // Constructor
+ public IDPattern() {
+ }
+
+ // Constructor
+ public IDPattern(Vector<IDPart> 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() {};
+
+}
--- /dev/null
+/*
+ * NumericIDGenerator
+ *
+ * <p>An identifier generator that generates an incrementing ID as a
+ * series of numeric values, beginning from an initial value.</p>
+ *
+ * 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);
+ }
+
+}
--- /dev/null
+ /*
+ * 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));
+ };
+
+}
+++ /dev/null
- /*
- * 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;
- };
-
-}
--- /dev/null
+/*
+ * StringIDGenerator
+ *
+ * <p>An identifier generator that stores and returns a static String.</p>
+ *
+ * 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;
+ }
+
+}
--- /dev/null
+ /*
+ * 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));
+ };
+
+}
--- /dev/null
+/*
+ * YearIDGenerator
+ *
+ * <p>An identifier generator that stores and returns the current year
+ * as a String object.</p>
+ *
+ * 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);
+ }
+
+}
--- /dev/null
+ /*
+ * 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));
+ };
+
+}
+++ /dev/null
- /*
- * 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 <http://radio.javaranch.com/lasse/2007/05/17/1179405760728.html>
-// 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.
- }
- }
-
-}
--- /dev/null
+/*
+ * 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 ...
+
+}
+++ /dev/null
- /*
- * 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 ...
-
-}
--- /dev/null
+/*
+ * 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 ...
+
+}
--- /dev/null
+/*
+ * 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 ...
+
+}
--- /dev/null
+/*
+ * 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 ...
+
+}
--- /dev/null
+/*
+ * 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 ...
+
+}
+++ /dev/null
-#! /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