001    // Copyright 2010 Waterken Inc. under the terms of the MIT X license
002    // found at http://www.opensource.org/licenses/mit-license.html
003    package org.ref_send.brand;
004    
005    import java.io.Serializable;
006    
007    import org.joe_e.Powerless;
008    
009    /**
010     * An opaque, globally unique identifier.
011     * @param <T> purpose of this brand
012     */
013    public class
014    Brand<T> implements Powerless, Serializable {
015        static private final long serialVersionUID = 1L;
016        
017        protected Brand() {}
018        
019        /**
020         * Constructs an instance.
021         * @param <T> purpose of this brand
022         */
023        static public <T> Brand<T>
024        make() { return new Brand<T>(); }
025        
026        /**
027         * Is one object {@link Object#equals equal} to another?
028         * @param <P>   compared object type
029         * @param a object compared against
030         * @param b object compared to 
031         * @return {@code true} if {@code a} claims {@code b} is
032         *         {@link Object#equals equal}, else {@code false}
033         */
034        static public <P> boolean
035        equal(final P a, final P b) { return null != a ? a.equals(b) : null == b; }
036        
037        /**
038         * Requires that one brand is the same as another.
039         * @param <T> purpose of this brand
040         * @param expected  brand compared against
041         * @param actual    brand compared to 
042         * @throws WrongBrand   {@code actual} is not {@code expected}
043         */
044        static public <T> void
045        require(final Brand<T> expected, final Brand<T> actual) throws WrongBrand {
046            if (!equal(expected, actual)) { throw new WrongBrand(expected,actual); }
047        }
048    }