001    package org.nakedobjects.applib.spec;
002    
003    
004    
005    /**
006     * Adapter to make it easy to perform boolean algebra on {@link Specification}s.
007     * 
008     * <p>
009     * <p>
010     * Subclasses represent the logical inverse of a {@link Specification}s.  An 
011     * implementation should instantiate the {@link Specification}s to be satisfied 
012     * in its constructor.
013     * 
014     * <p>
015     * For example:
016     * <pre>
017     * public class NoSugarThanksSpec extends SpecificationNot {
018     *     public NoSugarThanksSpec() {
019     *         super(
020     *             new TwoLumpsOfSugarSpec(), 
021     *         );
022     *     }
023     * }
024     * </pre>
025     * 
026     * @see SpecificationAnd
027     * @see SpecificationOr
028     */
029    public abstract class SpecificationNot implements Specification {
030    
031        private final Specification specification;
032    
033        public SpecificationNot(Specification specification) {
034            this.specification = specification;
035        }
036     
037        public String satisfies(Object obj) {
038            String satisfies = specification.satisfies(obj);
039            return satisfies != null? null: "not satisfied";
040        }
041    }