KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > explorer > core > common > lib > DefaultKey


1 /*====================================================================
2
3 Objectweb Explorer Framework
4 Copyright (C) 2000-2005 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Jerome Moroy, Philippe Merle.
23 Contributor(s): ______________________________________.
24
25 ====================================================================
26 $Id: DefaultKey.java,v 1.2 2005/07/06 15:36:00 moroy Exp $
27 ====================================================================*/

28
29 package org.objectweb.util.explorer.core.common.lib;
30
31 import org.objectweb.util.explorer.ExplorerUtils;
32 import org.objectweb.util.explorer.core.role.api.Role;
33
34 /**
35  * This class represents the key of the data structure containing the Explorer configuration.
36  * This is composed of two elements which are the ID and the associated role.
37  *
38  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jérôme Moroy</a>,
39  * <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>.
40  *
41  * @version 0.1
42  */

43 public class DefaultKey
44 {
45
46     //==================================================================
47
//
48
// Internal States.
49
//
50
// ==================================================================
51

52     /** The ID of the Type System */
53     protected String JavaDoc typeSystemId_;
54     
55     /** The type name. */
56     protected String JavaDoc typeName_;
57     
58     /** The role for which the node configuration is defined. */
59     protected Role role_;
60         
61     // ==================================================================
62
//
63
// Constructors.
64
//
65
// ==================================================================
66

67     /**
68      * Default constructor.
69      * @param typeSystemId The ID of the Type System.
70      * @param typeName The type name.
71      * @param role The role for which the node configuration is defined.
72      */

73     public DefaultKey(String JavaDoc typeSystemId, String JavaDoc typeName, Role role) {
74         this.typeSystemId_ = typeSystemId;
75         this.typeName_ = typeName;
76         this.role_ = role;
77     }
78
79     // ==================================================================
80
//
81
// Internal method.
82
//
83
// ==================================================================
84

85
86     
87     /**
88      * Two keys are considered equal if they have
89      * the same type system id, the same type name, and the same role.
90      */

91     protected boolean equals(DefaultKey key){
92         if (key != null) {
93             return ExplorerUtils.compareObjects(key.typeSystemId_,typeSystemId_)
94               && ExplorerUtils.compareObjects(key.typeName_,typeName_)
95               && ExplorerUtils.compareObjects(key.role_,role_);
96         }
97         return false;
98     }
99     
100
101     // ==================================================================
102
//
103
// Public methods surcharging Object class.
104
//
105
// ==================================================================
106

107     /**
108      * Surcharging the Object.equals method.
109      * @see DefaultKey#equals(DefaultKey)
110      */

111     public boolean equals(Object JavaDoc o){
112         if(o!=null && o instanceof DefaultKey)
113             return equals((DefaultKey)o);
114         return false;
115     }
116     
117     /**
118      * Return a String representation of a DefaultKey
119      */

120     public String JavaDoc toString(){
121         return "DefaultKey[typeSystem=" + typeSystemId_ + ", typeName=" + typeName_ + ", role=" + (role_!=null?role_.toString():"null") + "]";
122     }
123     
124     /**
125      * Returns a hash code value for the object.
126      * @see java.lang.Object#hashCode()
127      */

128     public int hashCode(){
129        return ExplorerUtils.getHashCode(typeSystemId_)
130            + ExplorerUtils.getHashCode(typeName_)
131            + ExplorerUtils.getHashCode(role_);
132     }
133 }
134
135
Popular Tags