Coverage report

  %line %branch
nl.toolforge.karma.core.manifest.ModuleDigester
83% 
86% 

 1  
 /*
 2  
 Karma core - Core of the Karma application
 3  
 Copyright (C) 2004  Toolforge <www.toolforge.nl>
 4  
 
 5  
 This library is free software; you can redistribute it and/or
 6  
 modify it under the terms of the GNU Lesser General Public
 7  
 License as published by the Free Software Foundation; either
 8  
 version 2.1 of the License, or (at your option) any later version.
 9  
 
 10  
 This library is distributed in the hope that it will be useful,
 11  
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
 Lesser General Public License for more details.
 14  
 
 15  
 You should have received a copy of the GNU Lesser General Public
 16  
 License along with this library; if not, write to the Free Software
 17  
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 18  
 */
 19  
 package nl.toolforge.karma.core.manifest;
 20  
 
 21  
 import nl.toolforge.karma.core.Version;
 22  
 
 23  
 import java.util.regex.PatternSyntaxException;
 24  
 
 25  
 /**
 26  
  * Class modelling a <code>&lt;module&gt;</code>-element in a manifest file.
 27  
  *
 28  
  * @author D.A. Smedes
 29  
  * @version $Id: ModuleDigester.java,v 1.2 2004/09/20 06:15:21 asmedes Exp $
 30  
  */
 31  
 public final class ModuleDigester {
 32  
 
 33  
   // todo string validation should be done in the xml-schema.
 34  
   //
 35  
 
 36  
   public static final String NAME_PATTERN_STRING = "[A-Za-z\\-\\d]+";
 37  
   public static final String LOCATION_PATTERN_STRING = "[0-9a-z\\-\\_]+";
 38  
 
 39  437
   private String name = null;
 40  437
   private String location = null;
 41  
 
 42  437
   private String version = null;
 43  
 
 44  
   /**
 45  
    *
 46  
    */
 47  437
   public ModuleDigester(String name, String location) {
 48  
 
 49  437
     if (name == null || !name.matches(NAME_PATTERN_STRING)) {
 50  0
       throw new PatternSyntaxException(
 51  
           "Pattern mismatch for name-attribute. Should match " + NAME_PATTERN_STRING, name, -1);
 52  
     }
 53  437
     this.name = name;
 54  
 
 55  437
     if (location == null || !location.matches(LOCATION_PATTERN_STRING)) {
 56  0
       throw new PatternSyntaxException(
 57  
           "Pattern mismatch for location-attribute. Should match " + LOCATION_PATTERN_STRING, location, -1);
 58  
     }
 59  437
     this.location = location;
 60  437
   }
 61  
 
 62  
 
 63  
   public String getName() {
 64  589
     return name;
 65  
   }
 66  
 
 67  
   public String getLocation() {
 68  266
     return location;
 69  
   }
 70  
 
 71  
   /**
 72  
    * Sets the modules' version. {@link nl.toolforge.karma.core.Version} is used to validate the version-string that
 73  
    * is passed as a parameter.
 74  
    *
 75  
    * @param version Version string.
 76  
    */
 77  
   public void setVersion(String version) {
 78  
 
 79  285
     if (!version.matches(Version.VERSION_PATTERN_STRING)) {
 80  0
       throw new PatternSyntaxException(
 81  
           "Pattern mismatch for version. Should match " + Version.VERSION_PATTERN_STRING, version, -1);
 82  
     }
 83  285
     this.version = version;
 84  285
   }
 85  
 
 86  
   public String getVersion() {
 87  190
     return version;
 88  
   }
 89  
 
 90  
   /**
 91  
    * Modules are equal when their name and location are equal.
 92  
    *
 93  
    * @param o The object instance that should be compared with <code>this</code>.
 94  
    * @return <code>true</code> if this module descriptor
 95  
    */
 96  
   public boolean equals(Object o) {
 97  
 
 98  228
     if (o instanceof ModuleDigester) {
 99  228
       if (
 100  
           (getName().equals(((ModuleDigester) o).getName())) &&
 101  
           (getLocation().equals(((ModuleDigester) o).getLocation())) ) {
 102  38
         return true;
 103  
       } else {
 104  190
         return false;
 105  
       }
 106  
     } else {
 107  0
       return false;
 108  
     }
 109  
   }
 110  
 
 111  
   public int hashCode() {
 112  
 
 113  1292
     return name.hashCode() + location.hashCode();
 114  
   }
 115  
 }
 116  
 
 117  
 

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.