KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > junit > NamedObject


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 2004 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.junit;
21
22 /**
23  * Object wrapper which allows to assign a name to an object.
24  */

25 public final class NamedObject {
26
27     /** name of the object */
28     public String JavaDoc name;
29     /** object wrapper wrapped by this <code>NamedObject</code> */
30     public Object JavaDoc object;
31
32     /**
33      * Creates an instance of <code>NamedObject</code>
34      *
35      * @param object object to be wrapped by this object
36      * @param name name of this object
37      */

38     public NamedObject(Object JavaDoc object, String JavaDoc name) {
39         if ((object == null) || (name == null)) {
40             throw new IllegalArgumentException JavaDoc("null"); //NOI18N
41
}
42         this.object = object;
43         this.name = name;
44     }
45     
46     /**
47      * Returns a string representation of this object.
48      *
49      * @return name of the object
50      */

51     public String JavaDoc toString() {
52         return name;
53     }
54     
55     /**
56      */

57     public boolean equals(Object JavaDoc o) {
58         if (o == this) {
59             return true;
60         }
61         if (o == null) {
62             return false;
63         }
64         if (!o.getClass().equals(NamedObject.class)) {
65             return false;
66         }
67         final NamedObject otherNamed = (NamedObject) o;
68         return name.equals(otherNamed.name)
69                && object.equals(otherNamed.object);
70     }
71     
72     /**
73      */

74     public int hashCode() {
75         return name.hashCode() + object.hashCode();
76     }
77     
78 }
79
Popular Tags