001    package org.nakedobjects.applib.annotation;
002    
003    import java.lang.annotation.ElementType;
004    import java.lang.annotation.Inherited;
005    import java.lang.annotation.Retention;
006    import java.lang.annotation.RetentionPolicy;
007    import java.lang.annotation.Target;
008    import java.math.BigDecimal;
009    import java.util.Date;
010    import java.util.HashMap;
011    
012    
013    /**
014     * Indicates that the class follows the equal-by-content contract, usually associated with {@link Value value}
015     * types.
016     * 
017     * <p>
018     * If a class claims to be equal-by-content then its {@link #equals(Object)} should return <tt>true</tt> if
019     * its content (as opposed to identity) is the same. For example, {@link String}, {@link BigDecimal} and
020     * {@link Date} follow this contract.
021     * 
022     * <p>
023     * Note also that the Java Language Specification requires that two objects that are
024     * {@link #equals(Object) equal} must return the same value from {@link #hashCode()}. Failure to do this
025     * means that that the object will not behave correctly when used as a key into a hashing structure (eg a
026     * {@link HashMap}).
027     * 
028     * <p>
029     * By default any {@link Value value} types are assumed to follow the equal-by-content rule, though this can
030     * be overridden if required. Value types are usually also {@link Immutable immutable} (though there are some
031     * classic exceptions to this, such as {@link Date}).
032     * 
033     * @see Immutable
034     * @see Value
035     */
036    @Inherited
037    @Target( { ElementType.TYPE, ElementType.METHOD })
038    @Retention(RetentionPolicy.RUNTIME)
039    public @interface EqualByContent {
040        When value() default When.ALWAYS;
041    }
042    
043    // Copyright (c) Naked Objects Group Ltd.