View Javadoc

1   package se.citerus.dddsample.domain.shared;
2   
3   /**
4    * AND specification, used to create a new specifcation that is the AND of two other specifications.
5    */
6   public class AndSpecification<T> extends AbstractSpecification<T> {
7   
8     private Specification<T> spec1;
9     private Specification<T> spec2;
10  
11    /**
12     * Create a new AND specification based on two other spec.
13     *
14     * @param spec1 Specification one.
15     * @param spec2 Specification two.
16     */
17    public AndSpecification(final Specification<T> spec1, final Specification<T> spec2) {
18      this.spec1 = spec1;
19      this.spec2 = spec2;
20    }
21  
22    /**
23     * {@inheritDoc}
24     */
25    public boolean isSatisfiedBy(final T t) {
26      return spec1.isSatisfiedBy(t) && spec2.isSatisfiedBy(t);
27    }
28  }