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.dvc.model;
16  
17  import static com.google.common.base.Preconditions.checkNotNull;
18  
19  import org.basepom.mojo.dvc.QualifiedNameMatcher;
20  
21  import java.util.Objects;
22  
23  import com.google.common.base.MoreObjects;
24  import com.google.common.collect.ImmutableList;
25  
26  /**
27   * Represents a "resolver" element in the configuration section.
28   */
29  public final class ResolverDefinition {
30  
31      private String strategy = "";
32      private ImmutableList<QualifiedNameMatcher> includes = ImmutableList.of();
33  
34      public void setStrategy(final String strategy) {
35          this.strategy = checkNotNull(strategy, "strategyName is null");
36      }
37  
38      @SuppressWarnings("PMD.UseVarargs") // called by maven, don't use varargs
39      public void setIncludes(final String[] includes) {
40          checkNotNull(includes, "includes is null");
41  
42          ImmutableList.Builder<QualifiedNameMatcher> builder = ImmutableList.builder();
43          for (final String include : includes) {
44              builder.add(new QualifiedNameMatcher(include));
45          }
46          this.includes = builder.build();
47      }
48  
49      public String getStrategy() {
50          return strategy;
51      }
52  
53      public ImmutableList<QualifiedNameMatcher> getIncludes() {
54          return includes;
55      }
56  
57      @Override
58      public boolean equals(final Object o) {
59          if (this == o) {
60              return true;
61          }
62          if (o == null || getClass() != o.getClass()) {
63              return false;
64          }
65          ResolverDefinition that = (ResolverDefinition) o;
66          return strategy.equals(that.strategy)
67                  && includes.equals(that.includes);
68      }
69  
70      @Override
71      public int hashCode() {
72          return Objects.hash(strategy, includes);
73      }
74  
75      @Override
76      public String toString() {
77          return MoreObjects.toStringHelper(this)
78                  .add("strategy", strategy)
79                  .add("includes", includes)
80                  .toString();
81      }
82  }
83  
84