View Javadoc
1   /*
2    * Licensed under the Apache License, Version 2.0 (the "License");
3    * you may not use this file except in compliance with the License.
4    * You may obtain a copy of the License at
5    *
6    * http://www.apache.org/licenses/LICENSE-2.0
7    *
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an "AS IS" BASIS,
10   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11   * See the License for the specific language governing permissions and
12   * limitations under the License.
13   */
14  
15  package org.basepom.mojo.propertyhelper.beans;
16  
17  import static com.google.common.base.Preconditions.checkState;
18  
19  import com.google.common.annotations.VisibleForTesting;
20  
21  public class NumberDefinition
22          extends AbstractDefinition<NumberDefinition> {
23  
24      public static final String INITIAL_VALUE = "0";
25  
26      /**
27       * If a multi-number, which field to increment. Field injected by Maven.
28       */
29      int fieldNumber = 0;
30  
31      /**
32       * Increment of the property when changing it. Field injected by Maven.
33       */
34      int increment = 1;
35  
36      public NumberDefinition() {
37          super();
38          setInitialValue(INITIAL_VALUE);
39      }
40  
41      public int getFieldNumber() {
42          return fieldNumber;
43      }
44  
45      @VisibleForTesting
46      public NumberDefinition setFieldNumber(final int fieldNumber) {
47          this.fieldNumber = fieldNumber;
48          return this;
49      }
50  
51      public int getIncrement() {
52          return increment;
53      }
54  
55      @VisibleForTesting
56      public NumberDefinition setIncrement(final int increment) {
57          this.increment = increment;
58          return this;
59      }
60  
61      @Override
62      public void check() {
63          super.check();
64          checkState(getInitialValue().isPresent(), "the initial value must not be empty");
65          checkState(fieldNumber >= 0, "the field number must be >= 0");
66      }
67  }