ResolverDefinition.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.dvc.model;

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

  16. import org.basepom.mojo.dvc.QualifiedNameMatcher;

  17. import java.util.Objects;

  18. import com.google.common.base.MoreObjects;
  19. import com.google.common.collect.ImmutableList;

  20. /**
  21.  * Represents a "resolver" element in the configuration section.
  22.  */
  23. public final class ResolverDefinition {

  24.     private String strategy = "";
  25.     private ImmutableList<QualifiedNameMatcher> includes = ImmutableList.of();

  26.     public void setStrategy(final String strategy) {
  27.         this.strategy = checkNotNull(strategy, "strategyName is null");
  28.     }

  29.     @SuppressWarnings("PMD.UseVarargs") // called by maven, don't use varargs
  30.     public void setIncludes(final String[] includes) {
  31.         checkNotNull(includes, "includes is null");

  32.         ImmutableList.Builder<QualifiedNameMatcher> builder = ImmutableList.builder();
  33.         for (final String include : includes) {
  34.             builder.add(new QualifiedNameMatcher(include));
  35.         }
  36.         this.includes = builder.build();
  37.     }

  38.     public String getStrategy() {
  39.         return strategy;
  40.     }

  41.     public ImmutableList<QualifiedNameMatcher> getIncludes() {
  42.         return includes;
  43.     }

  44.     @Override
  45.     public boolean equals(final Object o) {
  46.         if (this == o) {
  47.             return true;
  48.         }
  49.         if (o == null || getClass() != o.getClass()) {
  50.             return false;
  51.         }
  52.         ResolverDefinition that = (ResolverDefinition) o;
  53.         return strategy.equals(that.strategy)
  54.                 && includes.equals(that.includes);
  55.     }

  56.     @Override
  57.     public int hashCode() {
  58.         return Objects.hash(strategy, includes);
  59.     }

  60.     @Override
  61.     public String toString() {
  62.         return MoreObjects.toStringHelper(this)
  63.                 .add("strategy", strategy)
  64.                 .add("includes", includes)
  65.                 .toString();
  66.     }
  67. }