View Javadoc

1   /*
2    * Copyright 2006-2010 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.sourceforge.domian.specification;
17  
18  
19  import org.apache.commons.lang.Validate;
20  
21  import static java.lang.Boolean.FALSE;
22  import static java.lang.Boolean.TRUE;
23  
24  
25  /**
26   * Leaf specification, always giving a positive response.
27   * <p/>
28   * Also known as a <i>tautology</i>.
29   * <p/>
30   * This specification is raw/not type parameterized by design.
31   *
32   * @author Eirik Torske
33   * @since 0.4
34   */
35  final class AlwaysTrueSpecification extends AbstractSpecification implements LeafSpecification {
36  
37      public AlwaysTrueSpecification() {
38          super();
39      }
40  
41      @Override
42      public Boolean isSatisfiedBy(Object candidate) {
43          return TRUE;
44      }
45  
46      @Override
47      public Boolean isDisjointWith(final Specification specification) {
48          Validate.notNull(specification, "Specification parameter cannot be null");
49          if (specification instanceof AlwaysFalseSpecification) {
50              return TRUE;
51          }
52          if (specification instanceof JointDenialSpecification) {
53              return specification.isDisjointWith(this);
54          }
55          return FALSE;
56      }
57  
58      @Override
59      public final boolean equals(final Object otherObject) {
60          return this == otherObject || otherObject != null && otherObject instanceof AlwaysTrueSpecification;
61      }
62  }