Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 18294 invoked from network); 29 Jun 2002 18:42:28 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by 209.66.108.5 with SMTP; 29 Jun 2002 18:42:28 -0000 Received: (qmail 5826 invoked by uid 97); 29 Jun 2002 18:42:36 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 5752 invoked by uid 97); 29 Jun 2002 18:42:35 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 5729 invoked by uid 97); 29 Jun 2002 18:42:35 -0000 X-Antivirus: nagoya (v4198 created Apr 24 2002) Date: 29 Jun 2002 18:42:18 -0000 Message-ID: <20020629184218.50248.qmail@icarus.apache.org> From: scolebourne@apache.org To: jakarta-commons-sandbox-cvs@apache.org Subject: cvs commit: jakarta-commons-sandbox/pattern/src/java/org/apache/commons/pattern/identifier Identifiable.java Identifier.java IdentifierUtils.java IdentifierFactoryException.java X-Spam-Rating: 209.66.108.5 1.6.2 0/1000/N X-Spam-Rating: 209.66.108.5 1.6.2 0/1000/N 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 * . */ package org.apache.commons.pattern.identifier; /** * Identifiable 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. *
    *
  • The identifier must never be null *
  • The identifier must be immutable *
  • The identifier must have a toString() method that outputs the whole * identifier as a String *
  • The identifier must have equals() and hashCode() methods that * correctly compare the identifier to other identifiers *
  • If implementing your own identifier class, the Identifier * interface should be implemented *
* String and Long make good identifiers. * * @see org.apache.commons.pattern.immutable.Immutable * @author Stephen Colebourne * @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. *
    *
  • The identifier must never be null *
  • The identifier must be immutable *
  • The identifier must have a toString() method that outputs the whole * identifier as a String *
  • The identifier must have equals() and hashCode() methods that * correctly compare the identifier to other identifiers *
  • If implementing your own identifier class, the Identifier * interface should be implemented *
* * @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 * . */ package org.apache.commons.pattern.identifier; import org.apache.commons.pattern.immutable.Immutable; /** * Identifier defines an interface implemented by classes that * represent a unique identifier. *
    *
  • The class must be immutable (final, no set methods, etc.) *
  • The class must hold details only of the identifier and no other * state data *
* * @author Stephen Colebourne * @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. *

* 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 * java.lang.Object. * * @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. *

* 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 parse(String) method for * this purpose. *

* 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 * . */ package org.apache.commons.pattern.identifier; import org.apache.commons.pattern.factory.Factory; import org.apache.commons.pattern.identifier.factory.IncrementingLongIdentifierFactory; /** * IdentifierUtils provides reference implementations and utilities * for the Identifier and Identifiable pattern interfaces. * * @author Stephen Colebourne * @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 * . */ 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 Stephen Colebourne * @version $Id: IdentifierFactoryException.java,v 1.1 2002/06/29 18:42:17 scolebourne Exp $ */ public class IdentifierFactoryException extends FactoryException { /** * Constructs a new IdentifierException without specified * detail message. */ public IdentifierFactoryException() { super(); } /** * Constructs a new IdentifierException with specified * detail message. * * @param msg the error message. */ public IdentifierFactoryException(String msg) { super(msg); } /** * Constructs a new IdentifierException with specified * nested Throwable root cause. * * @param rootCause the exception or error that caused this exception * to be thrown. */ public IdentifierFactoryException(Throwable rootCause) { super(rootCause); } /** * Constructs a new IdentifierException with specified * detail message and nested Throwable 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: For additional commands, e-mail: