View Javadoc

1   /*******************************************************************************
2    * Copyright (c) 2007, 2014 Massimiliano Ziccardi
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 it.jnrpe.utils.thresholds;
17  
18  import java.math.BigDecimal;
19  
20  /**
21   * The threshold configuration. It is an interpretation of the threshold string.
22   * This object is populated by the threshold parser.
23   *
24   * @author Massimiliano Ziccardi
25   *
26   */
27  class RangeConfig {
28      /**
29       * Indicate if the threshold is negated.
30       */
31      private boolean negate = false;
32  
33      /**
34       * Indicate if the left boundary is inclusive.
35       */
36      private boolean leftInclusive = true;
37  
38      /**
39       * Indicate if the right boundary is inclusive.
40       */
41      private boolean rightInclusive = true;
42  
43      /**
44       * The left boundary. Must be <code>null</code> if {@link #negativeInfinity}
45       * is <code>true</code>
46       */
47      private BigDecimal startBoundary = null;
48  
49      /**
50       * The right boundary. Must be <code>null</code> if
51       * {@link #positiveInfinity} is <code>true</code>
52       */
53      private BigDecimal rightBoundary = null;
54  
55      /**
56       * <code>true</code> if the left boundary is the negative infinity.
57       */
58      private boolean negativeInfinity = false;
59  
60      /**
61       * <code>true</code> if the right boundary is the positive infinity.
62       */
63      private boolean positiveInfinity = false;
64  
65      /**
66       * Returns whether this threshold must be negated.
67       *
68       * @return whether this threshold must be negated.
69       */
70      public boolean isNegate() {
71          return negate;
72      }
73  
74      /**
75       * Sets if this threshold must be negated.
76       *
77       * @param negateThrehsold
78       *            <code>true</code> if must be negated
79       */
80      void setNegate(final boolean negateThrehsold) {
81          this.negate = negateThrehsold;
82      }
83  
84      /**
85       * Returns whether the left boundary is inclusive.
86       *
87       * @return whether the left boundary is inclusive.
88       */
89      public boolean isLeftInclusive() {
90          return leftInclusive;
91      }
92  
93      /**
94       * Returns whether the right boundary is inclusive.
95       *
96       * @return whether the right boundary is inclusive.
97       */
98      public boolean isRightInclusive() {
99          return rightInclusive;
100     }
101 
102     /**
103      * Sets if the left boundary must be inclusive.
104      *
105      * @param leftBoundaryInclusive
106      *            <code>true</code> if left boundary is inclusive
107      */
108     public void setLeftInclusive(final boolean leftBoundaryInclusive) {
109         this.leftInclusive = leftBoundaryInclusive;
110     }
111 
112     /**
113      * Sets the left boundary to negative infinity if <code>true</code>.
114      * @param negativeInf <code>true</code> to set negative infinity
115      */
116     public void setNegativeInfinity(final boolean negativeInf) {
117         negativeInfinity = negativeInf;
118     }
119 
120     @Override
121     public String toString() {
122         StringBuffer sb = new StringBuffer()
123                 .append("negate : " + negate)
124                 .append("\nnegativeInfinity : " + negativeInfinity)
125                 .append("\npositiveInfinity : " + positiveInfinity)
126                 .append("\nleftInclusive : " + leftInclusive)
127                 .append("\nrightInclusive : " + rightInclusive)
128                 .append("\nleftBoundary : " + startBoundary)
129                 .append("\nrightBoundary : " + rightBoundary);
130 
131         return sb.toString();
132     }
133 
134     /**
135      * Sets the left boundary (numeric).
136      * @param start The left boundary (numeric)
137      */
138     public void setLeftBoundary(final BigDecimal start) {
139         startBoundary = start;
140     }
141 
142     /**
143      * Sets the right boundary to positive infinity if <code>true</code>.
144      * @param positiveInf <code>true</code> to set positive infinity
145      */
146     public void setPositiveInfinity(final boolean positiveInf) {
147         positiveInfinity = positiveInf;
148     }
149 
150     /**
151      * Sets the right boundary (numeric).
152      * @param right The right boundary (numeric)
153      */
154     public void setRightBoundary(final BigDecimal right) {
155         rightBoundary = right;
156     }
157 
158     /**
159      * Sets if the right boundary must be inclusive.
160      *
161      * @param rightIncl
162      *            <code>true</code> if right boundary is inclusive
163      */
164     public void setRightInclusive(final boolean rightIncl) {
165         rightInclusive = rightIncl;
166     }
167 
168     /**
169      * @return The value of the left boundary. <code>null</code> if -inf.
170      */
171     protected BigDecimal getLeftBoundary() {
172         return startBoundary;
173     }
174 
175     /**
176      * @return The value of the right boundary. <code>null</code> if -inf.
177      */
178     protected BigDecimal getRightBoundary() {
179         return rightBoundary;
180     }
181 
182     /**
183      * @return <code>true</code> if the left boundary is -inf.
184      */
185     protected boolean isNegativeInfinity() {
186         return negativeInfinity;
187     }
188 
189     /**
190      * @return <code>true</code> if the right boundary is +inf.
191      */
192     protected boolean isPositiveInfinity() {
193         return positiveInfinity;
194     }
195 }