Coverage details for org.chwf.resources.ResourceID

LineHitsSource
1 /*
2 Chrysalis Web Framework [http://chrysalis.sourceforge.net]
3 Copyright (c) 2002, 2003, 2004, Paul Strack
4  
5 All rights reserved.
6  
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9  
10 1. Redistributions of source code must retain the above copyright notice, this
11 list of conditions and the following disclaimer.
12  
13 2. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16  
17 3. Neither the name of the copyright holder nor the names of its contributors
18 may be used to endorse or promote products derived from this software without
19 specific prior written permission.
20  
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
25 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
28 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32  
33 package org.chwf.resources;
34  
35 /**
36  * Class used to identify a resource/resource factory. It is suitable for use
37  * as a key in hash maps.
38  *
39  * @author Paul Strack
40  */
41 public class ResourceID {
42  
43   /** The resource type. */
44   private final Class type;
45  
46   /** The resource name. */
47   private final String name;
48  
49   /** The hashCode */
50   private final int hashCode;
51  
52   /**
53    * Constructor.
54    *
55    * @param type The resource type.
56    * @param name The resource name.
57    * @throws IllegalArgumentException If either parameter is null.
58    */
5947  public ResourceID(Class type, String name) throws IllegalArgumentException {
6047    checkNull(type);
6146    checkNull(name);
6246    this.type = type;
6346    this.name = name;
6446    this.hashCode = type.getName().hashCode() ^ name.hashCode();
6546  }
66  
67   /**
68    * The resource type.
69    *
70    * @return The resource type.
71    */
72   public Class getType() {
731    return this.type;
74   }
75  
76   /**
77    * The resource name.
78    *
79    * @return The resource type.
80    */
81   public String getName() {
821    return this.name;
83   }
84  
85   /**
86    * Compare one resource ID to another.
87    *
88    * @param o The compared object.
89    * @return True if type and name are equal, false if not (or not the object
90    * is not a ResourceID).
91    */
92   public boolean equals(Object o) {
9320    if (!(o instanceof ResourceID)) {
941      return false;
95     }
9619    ResourceID that = (ResourceID) o;
9719    return (this.type.equals(that.type)) && (this.name.equals(that.name));
98   }
99  
100   /**
101    * The ID's hashCode.
102    *
103    * @return The ID's hashCode.
104    */
105   public int hashCode() {
10640    return this.hashCode;
107   }
108  
109   /**
110    * Check if a value is null, throw an IllegalArgumentException if it is.
111    *
112    * @param o The value to check.
113    * @throws IllegalArgumentException If the value is null.
114    */
115   private void checkNull(Object o) throws IllegalArgumentException {
11693    if (o == null) {
1171      throw new IllegalArgumentException("Null values are not allowed");
118     }
11992  }
120 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.