1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sourceforge.domian.specification;
17
18
19 import org.apache.commons.lang.NotImplementedException;
20 import org.apache.commons.lang.Validate;
21
22 import static java.lang.Boolean.FALSE;
23 import static java.lang.Boolean.TRUE;
24 import static net.sourceforge.domian.util.ReflectionUtils.canCastAtLeastOneWay;
25
26
27
28
29
30
31
32
33
34
35
36
37 final class EqualIgnoreCaseStringSpecification extends AbstractValueBoundSpecification<String> {
38
39 EqualIgnoreCaseStringSpecification(final String value) {
40 super(value);
41 }
42
43 @Override
44 protected RelationalOperator getBinaryRelation(final Boolean negated) {
45 throw new NotImplementedException();
46 }
47
48 @Override
49 protected Boolean getDisjointDecision(final RelationalOperator candidateRelationalOperator, final String candidateOperandValue) {
50 throw new NotImplementedException();
51 }
52
53 @Override
54 public Boolean isSatisfiedBy(final String candidate) {
55 return candidate != null && this.value.equalsIgnoreCase(candidate);
56 }
57
58 @Override
59 public Boolean isDisjointWith(final Specification<?> specification) {
60 Validate.notNull(specification, "Specification parameter cannot be null");
61
62 if (this == specification || this.equals(specification)) {
63 return FALSE;
64 }
65
66 if (!canCastAtLeastOneWay(this.getType(), specification.getType())) {
67 return TRUE;
68 }
69 if (specification instanceof EqualSpecification) {
70 if ((((EqualSpecification) specification).getType().equals(String.class))) {
71 return !this.value.equalsIgnoreCase((String) ((EqualSpecification) specification).getValue());
72 }
73 }
74 if (specification instanceof EqualIgnoreCaseStringSpecification) {
75 return !this.value.equalsIgnoreCase(((EqualIgnoreCaseStringSpecification) specification).getValue());
76 }
77 if (specification instanceof WildcardExpressionMatcherStringSpecification) {
78 WildcardExpressionMatcherIgnoreCaseStringSpecification ignoreCaseSpecificationVersion =
79 new WildcardExpressionMatcherIgnoreCaseStringSpecification(((WildcardExpressionMatcherStringSpecification) specification).originalWildcardExpression);
80 return !ignoreCaseSpecificationVersion.isSatisfiedBy(this.value);
81 }
82 return TRUE;
83 }
84 }