You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ps...@apache.org on 2005/04/03 05:29:42 UTC

svn commit: r159874 - in jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id: DefaultIdentifierGeneratorFactory.java IdentifierGeneratorFactory.java

Author: psteitz
Date: Sat Apr  2 19:29:41 2005
New Revision: 159874

URL: http://svn.apache.org/viewcvs?view=rev&rev=159874
Log:
Added factory support for prefixed identifiers from BZ 34254.

Modified:
    jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/DefaultIdentifierGeneratorFactory.java
    jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/IdentifierGeneratorFactory.java

Modified: jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/DefaultIdentifierGeneratorFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/DefaultIdentifierGeneratorFactory.java?view=diff&r1=159873&r2=159874
==============================================================================
--- jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/DefaultIdentifierGeneratorFactory.java (original)
+++ jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/DefaultIdentifierGeneratorFactory.java Sat Apr  2 19:29:41 2005
@@ -21,6 +21,9 @@
 import org.apache.commons.id.serial.AlphanumericGenerator;
 import org.apache.commons.id.serial.LongGenerator;
 import org.apache.commons.id.serial.NumericGenerator;
+import org.apache.commons.id.serial.PrefixedAlphanumericGenerator;
+import org.apache.commons.id.serial.PrefixedNumericGenerator;
+import org.apache.commons.id.serial.PrefixedLeftPaddedNumericGenerator;
 import org.apache.commons.id.uuid.VersionFourGenerator;
 import org.apache.commons.id.uuid.VersionOneGenerator;
 import org.apache.commons.id.random.SessionIdGenerator;
@@ -172,5 +175,57 @@
      */
     public IdentifierGenerator uuidVersionFourGenerator() {
         return new VersionFourGenerator();
+    }
+    
+    /**
+     * <p>Gets a new {@link StringIdentifierGenerator} that generates an 
+     * incrementing number in base 36 with a prefix as a String object.</p>
+     *
+     * @param prefix prefix, must not be null
+     * @param wrap should the factory wrap when it reaches the maximum
+     *  value that can be represented in <code>size</code> base 36 digits
+     *  (or throw an exception)
+     * @param size the size of the identifier, including prefix length
+     * @throws IllegalArgumentException if prefix is null or size less prefix
+     * length is not at least one
+     */
+    public StringIdentifierGenerator prefixedAlphanumericGenerator(String prefix,
+        boolean wrap, int size) {
+        return new PrefixedAlphanumericGenerator(prefix, wrap, size);
+    }
+
+    /**
+     * <p>Gets a new {@link StringIdentifierGenerator} that generates a sequence
+     * of String objects representing numbers increasing in size, prefixed by
+     * an initial string and left-padded to make all strings the same length</p>
+     *
+     * @param prefix prefix, must not be null or empty
+     * @param wrap should the factory wrap when it reaches the maximum
+     *  value that can be represented in <code>size</code> base 10 digits
+     *  (or throw an exception)
+     * @param size the size of the identifier, including prefix length
+     * @throws IllegalArgumentException if prefix is null or size less prefix
+     * length is less than 1
+     */
+    public StringIdentifierGenerator prefixedLeftPaddedNumericGenerator(
+        String prefix, boolean wrap, int size) {
+        return new PrefixedLeftPaddedNumericGenerator(prefix, wrap, size);
+    }
+
+    /**
+     * <p>Gets a new {@link StringIdentifierGenerator} that generates a sequence
+     * of String objects representing numbers increasing in size, prefixed by
+     * an initial string.</p>
+     *
+     * @param prefix prefix, must not be null
+     * @param wrap should the sequence wrap when it reaches the maximum
+     *  long value (or throw an IllegalStateException)
+     * @param initialValue  the initial long value to start at
+     * @return a new StringIdentifierGenerator
+     *@throws IllegalArgumentException if prefix is null
+     */
+    public StringIdentifierGenerator prefixedNumericGenerator(
+        String prefix, boolean wrap, long initialValue) {
+        return new PrefixedNumericGenerator(prefix, wrap, initialValue);
     }
 }

Modified: jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/IdentifierGeneratorFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/IdentifierGeneratorFactory.java?view=diff&r1=159873&r2=159874
==============================================================================
--- jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/IdentifierGeneratorFactory.java (original)
+++ jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/IdentifierGeneratorFactory.java Sat Apr  2 19:29:41 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright 2003-2004 The Apache Software Foundation.
+ * Copyright 2003-2005 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -32,7 +32,7 @@
  * Documentation</a> for instructions on how to set up discovery for user-supplied
  * factories.</p>
  *
- * @author Commons-Uid team
+ * @author Commons-id team
  *
  * @version $Id$
  */
@@ -105,16 +105,63 @@
      * @return a new StringIdentifierGenerator
      */
     public abstract StringIdentifierGenerator numericGenerator(boolean wrap, long initialValue);
-
+    
+    /**
+     * <p>Gets a new {@link StringIdentifierGenerator} that generates a sequence
+     * of String objects representing numbers increasing in size, prefixed by
+     * an initial string.</p>
+     *
+     * @param prefix prefix, must not be null
+     * @param wrap should the sequence wrap when it reaches the maximum
+     *  long value (or throw an IllegalStateException)
+     * @param initialValue  the initial long value to start at
+     * @return a new StringIdentifierGenerator
+      *@throws IllegalArgumentException if prefix is null
+     */
+    public abstract StringIdentifierGenerator 
+        prefixedNumericGenerator(String prefix, boolean wrap, long initialValue);
+    
     /**
-     * <p>Gets a new {@link StringIdentifierGenerator} that generates a sequence of String objects
-     * representing numbers increasing in size in base-36.</p>
+     * <p>Gets a new {@link StringIdentifierGenerator} that generates a sequence
+     * of String objects representing numbers increasing in size, prefixed by
+     * an initial string and left-padded to make all strings the same length</p>
+     *
+    * @param prefix prefix, must not be null or empty
+     * @param wrap should the factory wrap when it reaches the maximum
+     *  value that can be represented in <code>size</code> base 10 digits
+     *  (or throw an exception)
+     * @param size the size of the identifier, including prefix length
+     * @throws IllegalArgumentException if prefix is null or size less prefix
+     * length is less than 1
+     */
+    public abstract StringIdentifierGenerator 
+    prefixedLeftPaddedNumericGenerator(String prefix, boolean wrap, int size);
+
+    /**
+     * <p>Gets a new {@link StringIdentifierGenerator} that generates a
+     * sequence of String objects representing numbers increasing in size
+     * in base-36.</p>
      *
      * <p>The sequence will wrap when the maximum size (15) is reached.</p>
      *
      * @return a new StringIdentifierGenerator
      */
     public abstract StringIdentifierGenerator alphanumericGenerator();
+    
+    /**
+     * <p>Gets a new {@link StringIdentifierGenerator} that generates an 
+     * incrementing number in base 36 with a prefix as a String object.</p>
+     *
+     * @param prefix prefix, must not be null
+     * @param wrap should the factory wrap when it reaches the maximum
+     *  value that can be represented in <code>size</code> base 36 digits
+     *  (or throw an exception)
+     * @param size the size of the identifier, including prefix length
+     * @throws IllegalArgumentException if prefix is null or size less prefix
+     * length is not at least one
+     */
+    public abstract StringIdentifierGenerator 
+    prefixedAlphanumericGenerator(String prefix, boolean wrap, int size);
 
     /**
      * <p>Gets a new {@link StringIdentifierGenerator} that generates a sequence of String objects



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org