You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2002/06/29 20:42:18 UTC

cvs commit: jakarta-commons-sandbox/pattern/src/java/org/apache/commons/pattern/identifier Identifiable.java Identifier.java IdentifierUtils.java IdentifierFactoryException.java

scolebourne    2002/06/29 11:42:18

  Added:       pattern/src/java/org/apache/commons/pattern/identifier
                        Identifiable.java Identifier.java
                        IdentifierUtils.java
                        IdentifierFactoryException.java
  Log:
  Initial checkin
  
  Revision  Changes    Path
  1.1                  jakarta-commons-sandbox/pattern/src/java/org/apache/commons/pattern/identifier/Identifiable.java
  
  Index: Identifiable.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.pattern.identifier;
  
  /**
   * <code>Identifiable</code> defines an interface implemented by classes that
   * have a unique identifier. The identifier may either be a simple Java class
   * such as String or Long, or an implementation of the Identifier interface.
   * <ul>
   * <li>The identifier must never be null
   * <li>The identifier must be immutable
   * <li>The identifier must have a toString() method that outputs the whole
   *  identifier as a String
   * <li>The identifier must have equals() and hashCode() methods that
   *  correctly compare the identifier to other identifiers
   * <li>If implementing your own identifier class, the <code>Identifier</code>
   *  interface should be implemented
   * </ul>
   * <code>String</code> and <code>Long</code> make good identifiers.
   * 
   * @see org.apache.commons.pattern.immutable.Immutable
   * @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
   * @version $Id: Identifiable.java,v 1.1 2002/06/29 18:42:17 scolebourne Exp $
   */
  public interface Identifiable {
      
      /**
       * Get the identifier for this object. The identifier may either be a 
       * simple Java class such as String or Long, or an implementation of
       * the Identifier interface.
       * <ul>
       * <li>The identifier must never be null
       * <li>The identifier must be immutable
       * <li>The identifier must have a toString() method that outputs the whole
       *  identifier as a String
       * <li>The identifier must have equals() and hashCode() methods that
       *  correctly compare the identifier to other identifiers
       * <li>If implementing your own identifier class, the <code>Identifier</code>
       *  interface should be implemented
       * </ul>
       *
       * @return the identifier
       */
      public Object getIdentifier();
      
  }
  
  
  
  1.1                  jakarta-commons-sandbox/pattern/src/java/org/apache/commons/pattern/identifier/Identifier.java
  
  Index: Identifier.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.pattern.identifier;
  
  import org.apache.commons.pattern.immutable.Immutable;
  /**
   * <code>Identifier</code> defines an interface implemented by classes that
   * represent a unique identifier.
   * <ul>
   * <li>The class must be immutable (final, no set methods, etc.)
   * <li>The class must hold details only of the identifier and no other
   *  state data
   * </ul>
   * 
   * @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
   * @version $Id: Identifier.java,v 1.1 2002/06/29 18:42:17 scolebourne Exp $
   */
  public interface Identifier extends Immutable {
      
      /**
       * Compare this object to another, based on all the state of the identifier.
       * <p>
       * This may return true only if the identifiers are equal. They must be the
       * same class and have the same state data.
       *
       * @see java.lang.Object#equals()
       * @return true if this identifier equals the passed in identifier
       */
      public boolean equals(Object object);
      
      /**
       * Get a hash code that complies with the normal rules laid out in
       * <code>java.lang.Object</code>.
       *
       * @see java.lang.Object#hashCode()
       * @return an integer hashcode for the identifier
       */
      public int hashCode();
      
      /**
       * Return the entire information about the identifier as a String.
       * <p>
       * The method may not return null. The format of the String should
       * be such that it can be parsed back to recreate the object. Normally,
       * the class will have a static <code>parse(String)</code> method for
       * this purpose.
       * <p>
       * This method is not a debugging method, and thus StringBuffer
       * should be used to append Strings, not the + operator for
       * performance reasons.
       *
       * @return a string representing the entire state of the identifier
       */
      public String toString();
      
  }
  
  
  
  1.1                  jakarta-commons-sandbox/pattern/src/java/org/apache/commons/pattern/identifier/IdentifierUtils.java
  
  Index: IdentifierUtils.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.pattern.identifier;
  
  import org.apache.commons.pattern.factory.Factory;
  import org.apache.commons.pattern.identifier.factory.IncrementingLongIdentifierFactory;
  /**
   * <code>IdentifierUtils</code> provides reference implementations and utilities
   * for the Identifier and Identifiable pattern interfaces.
   *
   * @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
   * @version $Id: IdentifierUtils.java,v 1.1 2002/06/29 18:42:17 scolebourne Exp $
   */
  public class IdentifierUtils {
  
      /**
       * JVM shared default identifier factory
       */
      public static Factory cDefault = new IncrementingLongIdentifierFactory(false);
  
      /**
       * Restructive constructor
       */
      private IdentifierUtils() {
          super();
      }
  
      /**
       * Gets the default Identifier Factory.
       * 
       * @return the default Identifier Factory
       */
      public static Factory getDefaultIdentifierFactory() {
          return cDefault;
      }
  
  
      /**
       * Sets the default Identifier Factory. This method is shared across the
       * JVM, thus should usually only be called during initialisation.
       * 
       * @param defaultFactory  the new fectory to set as the default
       * @throws IllegalArgumentException if the factory specified is null
       */
      public static void setDefaultIdentifierFactory(Factory defaultFactory) {
          if (defaultFactory == null) {
              throw new IllegalArgumentException("The Identifier Factory must not be null");
          }
          cDefault = defaultFactory;
      }
  
      /**
       * Gets the next identifier using the default Identifier Factory.
       * This is suitable for small programs where you can guarantee control
       * of the default identifier.
       * 
       * @return a new identifier
       */
      public static Object nextIdentifier() {
          return cDefault.create();
      }
  
      /**
       * Gets the next identifier using the specified Identifier Factory.
       * There is no requirement to use this method to get an identifier, as it
       * simply forwards the call to the create method on the factory specified.
       * 
       * @return a new identifier
       * @throws IllegalArgumentException if the factory specified is null
       */
      public static Object nextIdentifier(Factory identifierFactory) {
          if (identifierFactory == null) {
              throw new IllegalArgumentException("The Identifier Factory must not be null");
          }
          return identifierFactory.create();
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/pattern/src/java/org/apache/commons/pattern/identifier/IdentifierFactoryException.java
  
  Index: IdentifierFactoryException.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.pattern.identifier;
  
  import org.apache.commons.pattern.factory.FactoryException;
  /**
   * Exception thrown when the a method encounters a problem when creating
   * an Identifier in a Factory. If required, a root cause error can be
   * wrapped within this one.
   *
   * @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
   * @version $Id: IdentifierFactoryException.java,v 1.1 2002/06/29 18:42:17 scolebourne Exp $
   */
  public class IdentifierFactoryException extends FactoryException {
  
      /**
       * Constructs a new <code>IdentifierException</code> without specified
       * detail message.
       */
      public IdentifierFactoryException() {
          super();
      }
  
      /**
       * Constructs a new <code>IdentifierException</code> with specified
       * detail message.
       *
       * @param msg  the error message.
       */
      public IdentifierFactoryException(String msg) {
          super(msg);
      }
  
      /**
       * Constructs a new <code>IdentifierException</code> with specified
       * nested <code>Throwable</code> root cause.
       *
       * @param rootCause  the exception or error that caused this exception
       *                   to be thrown.
       */
      public IdentifierFactoryException(Throwable rootCause) {
          super(rootCause);
      }
  
      /**
       * Constructs a new <code>IdentifierException</code> with specified
       * detail message and nested <code>Throwable</code> root cause.
       *
       * @param msg        the error message.
       * @param rootCause  the exception or error that caused this exception
       *                   to be thrown.
       */
      public IdentifierFactoryException(String msg, Throwable rootCause) {
          super(msg, rootCause);
      }
  
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>