Coverage Report - de.smartics.ci.config.load.LoaderPlan
 
Classes in this File Line Coverage Branch Coverage Complexity
LoaderPlan
0%
0/27
0%
0/12
1.778
 
 1  
 /*
 2  
  * Copyright 2012 smartics, Kronseder & Reiner GmbH
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package de.smartics.ci.config.load;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.Iterator;
 20  
 import java.util.List;
 21  
 
 22  
 import de.smartics.ci.config.maven.MavenConfig;
 23  
 import de.smartics.util.lang.Arguments;
 24  
 import de.smartics.util.lang.BlankArgumentException;
 25  
 import de.smartics.util.lang.NullArgumentException;
 26  
 
 27  
 /**
 28  
  * Allows to iterate over configurations.
 29  
  */
 30  
 public final class LoaderPlan implements Iterable<String>
 31  
 {
 32  
   // ********************************* Fields *********************************
 33  
 
 34  
   // --- constants ------------------------------------------------------------
 35  
 
 36  
   // --- members --------------------------------------------------------------
 37  
 
 38  
   /**
 39  
    * The information from the Maven project configuration. The Maven information
 40  
    * is applied first and may be overridden by the configuration list.
 41  
    */
 42  
   private final MavenConfig mavenConfig;
 43  
 
 44  
   /**
 45  
    * The identifier of the loader plan.
 46  
    */
 47  
   private final String id;
 48  
 
 49  
   /**
 50  
    * The names of configurations to find at a location managed by a location
 51  
    * manager.
 52  
    */
 53  0
   private final List<String> configurationNames = new ArrayList<String>();
 54  
 
 55  
   // ****************************** Initializer *******************************
 56  
 
 57  
   // ****************************** Constructors ******************************
 58  
 
 59  
   /**
 60  
    * Default constructor.
 61  
    *
 62  
    * @param id the identifier of the loader plan.
 63  
    * @param mavenConfig the information from the Maven project configuration.
 64  
    * @throws BlankArgumentException if {@code id} is blank.
 65  
    * @throws NullArgumentException if {@code mavenConfig} is <code>null</code>.
 66  
    */
 67  
   public LoaderPlan(final String id, final MavenConfig mavenConfig)
 68  
     throws BlankArgumentException, NullArgumentException
 69  0
   {
 70  0
     Arguments.checkNotBlank("id", id);
 71  0
     Arguments.checkNotNull("mavenConfig", mavenConfig);
 72  
 
 73  0
     this.id = id;
 74  0
     this.mavenConfig = mavenConfig;
 75  0
   }
 76  
 
 77  
   // ****************************** Inner Classes *****************************
 78  
 
 79  
   // ********************************* Methods ********************************
 80  
 
 81  
   // --- init -----------------------------------------------------------------
 82  
 
 83  
   // --- get&set --------------------------------------------------------------
 84  
 
 85  
   /**
 86  
    * Returns the identifier of the loader plan.
 87  
    *
 88  
    * @return the identifier of the loader plan.
 89  
    */
 90  
   public String getId()
 91  
   {
 92  0
     return id;
 93  
   }
 94  
 
 95  
   /**
 96  
    * Returns the information from the Maven project configuration.
 97  
    *
 98  
    * @return the information from the Maven project configuration.
 99  
    */
 100  
   public MavenConfig getMavenConfig()
 101  
   {
 102  0
     return mavenConfig;
 103  
   }
 104  
 
 105  
   // --- business -------------------------------------------------------------
 106  
 
 107  
   /**
 108  
    * Adds a configuration name to the loader plan.
 109  
    *
 110  
    * @param configurationName the name to add.
 111  
    * @throws BlankArgumentException if {@code configurationName} is blank.
 112  
    */
 113  
   public void addConfigurationName(final String configurationName)
 114  
     throws BlankArgumentException
 115  
   {
 116  0
     Arguments.checkNotBlank("configurationName", configurationName);
 117  
 
 118  0
     configurationNames.add(configurationName);
 119  0
   }
 120  
 
 121  
   /**
 122  
    * {@inheritDoc}
 123  
    *
 124  
    * @see java.lang.Iterable#iterator()
 125  
    */
 126  
   @Override
 127  
   public Iterator<String> iterator()
 128  
   {
 129  0
     return configurationNames.iterator();
 130  
   }
 131  
 
 132  
   /**
 133  
    * Checks if the loader plan contains at least on name.
 134  
    *
 135  
    * @return <code>false</code> if the loader plan contains at least one name,
 136  
    *         <code>true</code> if it is empty.
 137  
    */
 138  
   public boolean isEmpty()
 139  
   {
 140  0
     return configurationNames.isEmpty();
 141  
   }
 142  
 
 143  
   // --- object basics --------------------------------------------------------
 144  
 
 145  
   /**
 146  
    * Returns the hash code of the object.
 147  
    *
 148  
    * @return the hash code.
 149  
    */
 150  
   @Override
 151  
   public int hashCode()
 152  
   {
 153  0
     return id.hashCode();
 154  
   }
 155  
 
 156  
   /**
 157  
    * Returns <code>true</code> if the given object is semantically equal to the
 158  
    * given object, <code>false</code> otherwise.
 159  
    * <p>
 160  
    * The Maven configuration is not a part of the check.
 161  
    * </p>
 162  
    *
 163  
    * @param object the instance to compare to.
 164  
    * @return <code>true</code> if the given object is semantically equal to the
 165  
    *         given object, <code>false</code> otherwise.
 166  
    */
 167  
   @Override
 168  
   public boolean equals(final Object object)
 169  
   {
 170  0
     if (this == object)
 171  
     {
 172  0
       return true;
 173  
     }
 174  0
     else if (object == null || getClass() != object.getClass())
 175  
     {
 176  0
       return false;
 177  
     }
 178  
 
 179  0
     final LoaderPlan other = (LoaderPlan) object;
 180  
 
 181  0
     return (id.equals(other.id) && configurationNames
 182  
         .equals(other.configurationNames));
 183  
   }
 184  
 
 185  
   /**
 186  
    * {@inheritDoc}
 187  
    *
 188  
    * @see java.lang.Object#toString()
 189  
    */
 190  
   @Override
 191  
   public String toString()
 192  
   {
 193  0
     final StringBuilder buffer = new StringBuilder(64);
 194  
 
 195  0
     buffer.append(id).append(": ");
 196  0
     for (final String configurationName : configurationNames)
 197  
     {
 198  0
       buffer.append(configurationName).append(' ');
 199  
     }
 200  
 
 201  0
     buffer.append(mavenConfig);
 202  
 
 203  0
     return buffer.toString();
 204  
   }
 205  
 }