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.definitions;
16  
17  import static com.google.common.base.Preconditions.checkNotNull;
18  
19  import java.util.List;
20  import java.util.Objects;
21  import java.util.StringJoiner;
22  
23  import com.google.common.annotations.VisibleForTesting;
24  import com.google.common.base.Splitter;
25  
26  public class PropertyDefinition {
27  
28      /**
29       * Name. Field injected by maven.
30       */
31      String name = null;
32  
33      /**
34       * Value. Field injected by maven.
35       */
36      String value = null;
37  
38      /**
39       * Transformers. Field injected by maven.
40       */
41      private List<String> transformers = List.of();
42  
43      // called by maven
44      public void setTransformers(String transformers) {
45          this.transformers = Splitter.on(",")
46              .omitEmptyStrings()
47              .trimResults()
48              .splitToList(transformers);
49      }
50  
51      @VisibleForTesting
52      PropertyDefinition(final String name, final String value) {
53          this.name = checkNotNull(name, "name is null");
54          this.value = checkNotNull(value, "value is null");
55      }
56  
57      public PropertyDefinition() {
58      }
59  
60      public void check() {
61          checkNotNull(name, "property name is null");
62          checkNotNull(value, "property value is null");
63      }
64  
65      public String getName() {
66          return name;
67      }
68  
69      public String getValue() {
70          return value;
71      }
72  
73      public List<String> getTransformers() {
74          return transformers;
75      }
76  
77      @Override
78      public boolean equals(Object o) {
79          if (this == o) {
80              return true;
81          }
82          if (o == null || getClass() != o.getClass()) {
83              return false;
84          }
85          PropertyDefinition that = (PropertyDefinition) o;
86          return Objects.equals(name, that.name) && Objects.equals(value, that.value) && Objects.equals(transformers,
87              that.transformers);
88      }
89  
90      @Override
91      public String toString() {
92          return new StringJoiner(", ", PropertyDefinition.class.getSimpleName() + "[", "]")
93              .add("name='" + name + "'")
94              .add("value='" + value + "'")
95              .add("transformers='" + transformers + "'")
96              .toString();
97      }
98  
99      @Override
100     public int hashCode() {
101         return Objects.hash(name, value, transformers);
102     }
103 }
104 
105