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.checkNotNull;
18  
19  import java.util.List;
20  import java.util.Objects;
21  
22  import com.google.common.annotations.VisibleForTesting;
23  import com.google.common.collect.ImmutableList;
24  
25  public class StringDefinition
26          extends AbstractDefinition<StringDefinition> {
27  
28      /**
29       * Values for this string. Field injected by Maven.
30       */
31      List<String> values = ImmutableList.of();
32  
33      /**
34       * Whether a blank string is a valid value. Field injected by Maven.
35       */
36      boolean blankIsValid = true;
37  
38      /**
39       * Default action on missing value. Field injected by Maven.
40       */
41      IgnoreWarnFail onMissingValue = IgnoreWarnFail.FAIL;
42  
43      public StringDefinition() {
44      }
45  
46      public List<String> getValues() {
47          return values;
48      }
49  
50      @VisibleForTesting
51      public StringDefinition setValues(final List<String> values) {
52          checkNotNull(values, "values is null");
53          final ImmutableList.Builder<String> builder = ImmutableList.builder();
54          for (String value : values) {
55              builder.add(Objects.requireNonNullElse(value, ""));
56          }
57          this.values = builder.build();
58          return this;
59      }
60  
61      public boolean isBlankIsValid() {
62          return blankIsValid;
63      }
64  
65      @VisibleForTesting
66      public StringDefinition setBlankIsValid(final boolean blankIsValid) {
67          this.blankIsValid = blankIsValid;
68          return this;
69      }
70  
71      public IgnoreWarnFail getOnMissingValue() {
72          return onMissingValue;
73      }
74  
75      @VisibleForTesting
76      public StringDefinition setOnMissingValue(final String onMissingValue) {
77          checkNotNull(onMissingValue, "onMissingValue is null");
78          this.onMissingValue = IgnoreWarnFail.forString(onMissingValue);
79          return this;
80      }
81  }