001: /*
002: * $Header: /export/home/cvsroot/MyPersonalizerRepository/MyPersonalizer/Subsystems/Kernel/Sources/es/udc/mypersonalizer/kernel/model/repository/interfaces/ServicePropertyKey.java,v 1.1.1.1 2004/03/25 12:08:36 fbellas Exp $
003: * $Revision: 1.1.1.1 $
004: * $Date: 2004/03/25 12:08:36 $
005: *
006: * =============================================================================
007: *
008: * Copyright (c) 2003, The MyPersonalizer Development Group
009: * (http://www.tic.udc.es/~fbellas/mypersonalizer/index.html) at
010: * University Of A Coruna
011: * All rights reserved.
012: *
013: * Redistribution and use in source and binary forms, with or without
014: * modification, are permitted provided that the following conditions are met:
015: *
016: * - Redistributions of source code must retain the above copyright notice,
017: * this list of conditions and the following disclaimer.
018: *
019: * - Redistributions in binary form must reproduce the above copyright notice,
020: * this list of conditions and the following disclaimer in the documentation
021: * and/or other materials provided with the distribution.
022: *
023: * - Neither the name of the University Of A Coruna nor the names of its
024: * contributors may be used to endorse or promote products derived from
025: * this software without specific prior written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
028: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
029: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
030: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
031: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
032: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
033: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
034: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
035: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
036: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
037: * POSSIBILITY OF SUCH DAMAGE.
038: *
039: */
040:
041: package es.udc.mypersonalizer.kernel.model.repository.interfaces;
042:
043: import java.io.Serializable;
044:
045: /**
046: * This convenience class encapsulates the key fields that uniquely identify
047: * an instance of a <code>ServiceProperty</code>. It contains a service
048: * identifier and a property identifier. Several property identifiers for the
049: * same service identifier could exist.
050: * <p>
051: * Example:
052: * <p>
053: * <table border="1">
054: * <tr>
055: * <td><b>service identifier</b></td>
056: * <td><b>property identifier</b></td>
057: * <td><b>service property</b></td>
058: * </tr>
059: * <tr>
060: * <td>the weather</td>
061: * <td>1</td>
062: * <td>service property A</td>
063: * </tr>
064: * <tr>
065: * <td>the weather</td>
066: * <td>2</td>
067: * <td>service property B</td>
068: * </tr>
069: * </table>
070: *
071: * @author Fernando Bellas
072: * @since 1.0
073: */
074: public class ServicePropertyKey implements Serializable {
075:
076: /**
077: * For interoperability with possible future changes.
078: *
079: */
080: private static final long serialVersionUID = -1210152873817476198L;
081:
082: /**
083: * The service identifier key field.
084: *
085: * @serial
086: */
087: private String serviceIdentifier = null;
088:
089: /**
090: * The service property key field.
091: *
092: * @serial
093: */
094: private Long propertyIdentifier = null;
095:
096: /**
097: * Constructs an instance of this class.
098: *
099: * @param serviceIdentifier the service identifier key field.
100: * @param propertyIdentifier the property identifier key field.
101: * @throws NullPointerException if <code>serviceIdentifier</code> or
102: * <code>propertyIdentifier</code> are <code>null</code>.
103: */
104: public ServicePropertyKey(String serviceIdentifier,
105: Long propertyIdentifier) {
106:
107: if (serviceIdentifier == null || propertyIdentifier == null) {
108: throw new NullPointerException();
109: }
110:
111: this .serviceIdentifier = serviceIdentifier;
112: this .propertyIdentifier = propertyIdentifier;
113: }
114:
115: /**
116: * Gets the service identifier key field.
117: *
118: * @return the service identifier
119: */
120: public String getServiceIdentifier() {
121: return serviceIdentifier;
122: }
123:
124: /**
125: * Gets the property identifier key field.
126: *
127: * @return the property identifier
128: */
129: public Long getPropertyIdentifier() {
130: return propertyIdentifier;
131: }
132:
133: /**
134: * Returns the hash code of an instance of this class. The resulting hash
135: * code is the sum of the service identifier hash code and the property
136: * identifier hash code.
137: *
138: * @return the hash code
139: */
140: public int hashCode() {
141: return serviceIdentifier.hashCode()
142: + propertyIdentifier.hashCode();
143: }
144:
145: /**
146: * Returns if an instance of this class is equals to the one passed as a
147: * parameter. This method returns true if the service identifier and the
148: * property identifier of both instances are the same, and false otherwise.
149: *
150: * @param object the instance to be compared to.
151: * @return true if this instance and the one passed as a parameter are
152: * equal, false otherwise.
153: */
154: public boolean equals(Object object) {
155: if (object == null) {
156: return false;
157: }
158:
159: ServicePropertyKey key = null;
160: try {
161: key = (ServicePropertyKey) object;
162:
163: } catch (ClassCastException e) {
164: return false;
165: }
166:
167: if (key.getServiceIdentifier().equals(serviceIdentifier)
168: && key.getPropertyIdentifier().equals(
169: propertyIdentifier)) {
170: return true;
171: }
172:
173: return false;
174: }
175: }
|