NumberDefinition.java

  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. package org.basepom.mojo.propertyhelper.beans;

  15. import static com.google.common.base.Preconditions.checkState;

  16. import com.google.common.annotations.VisibleForTesting;

  17. public class NumberDefinition
  18.         extends AbstractDefinition<NumberDefinition> {

  19.     public static final String INITIAL_VALUE = "0";

  20.     /**
  21.      * If a multi-number, which field to increment. Field injected by Maven.
  22.      */
  23.     int fieldNumber = 0;

  24.     /**
  25.      * Increment of the property when changing it. Field injected by Maven.
  26.      */
  27.     int increment = 1;

  28.     public NumberDefinition() {
  29.         super();
  30.         setInitialValue(INITIAL_VALUE);
  31.     }

  32.     public int getFieldNumber() {
  33.         return fieldNumber;
  34.     }

  35.     @VisibleForTesting
  36.     public NumberDefinition setFieldNumber(final int fieldNumber) {
  37.         this.fieldNumber = fieldNumber;
  38.         return this;
  39.     }

  40.     public int getIncrement() {
  41.         return increment;
  42.     }

  43.     @VisibleForTesting
  44.     public NumberDefinition setIncrement(final int increment) {
  45.         this.increment = increment;
  46.         return this;
  47.     }

  48.     @Override
  49.     public void check() {
  50.         super.check();
  51.         checkState(getInitialValue().isPresent(), "the initial value must not be empty");
  52.         checkState(fieldNumber >= 0, "the field number must be >= 0");
  53.     }
  54. }