View Javadoc
1   package com.github.mygreen.cellformatter;
2   
3   
4   /**
5    * ユーザ定義の条件式を表現するクラス。
6    * 演算子の条件式{@literal <、>、>=、<=、<>}を表現する。
7    *
8    * @author T.TSUCHIE
9    *
10   */
11  public abstract class ConditionOperator {
12      
13      /**
14       * 全ての値に一致する条件。常にtrueを返す。
15       */
16      public static ConditionOperatorditionOperator.html#ConditionOperator">ConditionOperator ALL = new ConditionOperator() {
17          
18          @Override
19          public boolean isMatch(final double value) {
20              return true;
21          }
22          
23      };
24      
25      /**
26       * 正の値に一致する条件。{@literal (>0.0)}
27       */
28      public static ConditionOperator POSITIVE = new GreaterThan(0.0);
29      
30      /**
31       * 負の値に一致する条件{@literal (<0.0)}
32       */
33      public static ConditionOperator NEGATIVE = new LessThan(0.0);
34      
35      /**
36       * ゼロの値に一致する条件{@literal (=0.0)}
37       */
38      public static ConditionOperator ZERO = new Equal(0.0);
39      
40      /**
41       * ゼロ以上の値に一致する条件(非負の数){@literal (>= 0.0)}
42       */
43      public static ConditionOperator NON_NEGATIVE = new GreaterEqual(0.0);
44      
45      /**
46       * 指定した値が条件に一致するかどうか。
47       * @param value
48       * @return
49       */
50      public abstract boolean isMatch(double value);
51      
52      /**
53       * 等しい{@literal (=条件値)}かどうか。
54       */
55      public static class Equal extends ConditionOperator{
56          
57          private final double condition;
58          
59          public Equal(final double condition) {
60              this.condition = condition;
61          }
62          
63          @Override
64          public boolean isMatch(final double value) {
65              return value == condition;
66          }
67          
68          public double getConditionValue() {
69              return condition;
70          }
71          
72      }
73      
74      /**
75       * 等しいくない{@literal (<>条件値)}かどうか。
76       */
77      public static class NotEqual extends ConditionOperator{
78          
79          private final double condition;
80          
81          public NotEqual(final double condition) {
82              this.condition = condition;
83          }
84          
85          @Override
86          public boolean isMatch(final double value) {
87              return value != condition;
88          }
89          
90          public double getConditionValue() {
91              return condition;
92          }
93          
94      }
95      
96      /**
97       * より大きい{@literal (>条件値)}
98       */
99      public static class GreaterThan extends ConditionOperator{
100         
101         private final double condition;
102         
103         public GreaterThan(final double condition) {
104             this.condition = condition;
105         }
106         
107         @Override
108         public boolean isMatch(final double value) {
109             return value > condition;
110         }
111         
112         public double getConditionValue() {
113             return condition;
114         }
115         
116     }
117     
118     /**
119      * より小さい{@literal (<条件値)}
120      */
121     public static class LessThan extends ConditionOperator{
122         
123         private final double condition;
124         
125         public LessThan(final double condition) {
126             this.condition = condition;
127         }
128         
129         @Override
130         public boolean isMatch(final double value) {
131             return value < condition;
132         }
133         
134         public double getConditionValue() {
135             return condition;
136         }
137         
138     }
139     
140     /**
141      * 以上{@literal (>=条件値)}
142      */
143     public static class GreaterEqual extends ConditionOperator{
144         
145         private final double condition;
146         
147         public GreaterEqual(final double condition) {
148             this.condition = condition;
149         }
150         
151         @Override
152         public boolean isMatch(final double value) {
153             return value >= condition;
154         }
155         
156         public double getConditionValue() {
157             return condition;
158         }
159         
160     }
161     
162     /**
163      * 以下{@literal (<=条件値)}
164      */
165     public static class LessEqual extends ConditionOperator{
166         
167         private final double condition;
168         
169         public LessEqual(final double condition) {
170             this.condition = condition;
171         }
172         
173         @Override
174         public boolean isMatch(final double value) {
175             return value <= condition;
176         }
177         
178         public double getConditionValue() {
179             return condition;
180         }
181         
182     }
183     
184 }