| Line | Hits | Source |
|---|---|---|
| 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 | */ | |
| 59 | 47 | public ResourceID(Class type, String name) throws IllegalArgumentException { |
| 60 | 47 | checkNull(type); |
| 61 | 46 | checkNull(name); |
| 62 | 46 | this.type = type; |
| 63 | 46 | this.name = name; |
| 64 | 46 | this.hashCode = type.getName().hashCode() ^ name.hashCode(); |
| 65 | 46 | } |
| 66 | ||
| 67 | /** | |
| 68 | * The resource type. | |
| 69 | * | |
| 70 | * @return The resource type. | |
| 71 | */ | |
| 72 | public Class getType() { | |
| 73 | 1 | return this.type; |
| 74 | } | |
| 75 | ||
| 76 | /** | |
| 77 | * The resource name. | |
| 78 | * | |
| 79 | * @return The resource type. | |
| 80 | */ | |
| 81 | public String getName() { | |
| 82 | 1 | 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) { | |
| 93 | 20 | if (!(o instanceof ResourceID)) { |
| 94 | 1 | return false; |
| 95 | } | |
| 96 | 19 | ResourceID that = (ResourceID) o; |
| 97 | 19 | 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() { | |
| 106 | 40 | 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 { | |
| 116 | 93 | if (o == null) { |
| 117 | 1 | throw new IllegalArgumentException("Null values are not allowed"); |
| 118 | } | |
| 119 | 92 | } |
| 120 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |