01: /* Copyright 2002 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal;
07:
08: import java.io.Serializable;
09:
10: /**
11: * A key and type that uniquely identify a portal entity.
12: * @author Dan Ellentuck
13: * @version $Revision: 34805 $
14: * @see IBasicEntity
15: */
16: public class EntityIdentifier implements Serializable {
17: protected String key;
18: protected Class type;
19:
20: /**
21: * KeyTypePair constructor.
22: */
23: public EntityIdentifier(String entityKey, Class entityType) {
24: super ();
25: key = entityKey;
26: type = entityType;
27: }
28:
29: /**
30: * @param o the Object to compare with
31: * @return true if these Objects are equal; false otherwise.
32: */
33: public boolean equals(Object o) {
34: if (o == null)
35: return false;
36: if (!(o instanceof EntityIdentifier))
37: return false;
38: EntityIdentifier ei = (EntityIdentifier) o;
39: return ei.getType() == getType() && ei.getKey().equals(key);
40: }
41:
42: /**
43: * @return java.lang.String
44: */
45: public String getKey() {
46: return key;
47: }
48:
49: /**
50: * @return java.lang.Class
51: */
52: public Class getType() {
53: return type;
54: }
55:
56: /**
57: * @return an integer hash code for the receiver
58: */
59: public int hashCode() {
60: return getType().hashCode() + getKey().hashCode();
61: }
62:
63: /**
64: * Returns a String that represents the value of this object.
65: * @return a string representation of the receiver
66: */
67: public String toString() {
68: return "EntityIdentifier (" + type + "(" + key + "))";
69: }
70:
71: }
|