KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > common > Param


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.admin.common;
25
26 import java.io.Serializable JavaDoc;
27
28
29 /**
30     Encapsulates a name/value pair.
31     <p>
32     The name of a Param is required to be a string, but its value may be
33     any Serializable object. Param does not alter value at any time. Thus
34     Param is an immutable class.
35     @author Lloyd Chambers
36     @version 1.0
37 */

38
39 public class Param implements Serializable JavaDoc
40 {
41     public static long serialVersionUID = -6783475004108829145L;
42
43     public String JavaDoc mName;
44     public Serializable JavaDoc mValue;
45
46     /**
47         Constructs a new Param with name and value.
48         <p>
49         @param name non-null String specifying parameter name
50         @param value any Serializable (may be null)
51      */

52     public Param( String JavaDoc name, Serializable JavaDoc value )
53     {
54         //Assert.assert( (name != null), "null name" );
55

56         mName = name;
57         mValue = value;
58     }
59
60     /**
61         Generates a string of the form: "name: value".
62      */

63     public String JavaDoc toString()
64     {
65         if ( mValue != null )
66         {
67             return( mName + ": " + mValue );
68         }
69         return( mName + ": <null>" );
70     }
71         
72         /**
73             Defines the logical equality of Param instance with any other
74             Object. Note that this method <strong> does not </strong> obey
75             the general contract of the java.lang.Object.equls() method.
76             An instance of Param is equal to other Object iff
77             <li> it is also an instance of Param &&
78             <li> it has the same name as that of this instance.
79             It is clear that this method does not take into account the value
80             of the Param.
81          
82             @param other instance of object to be compared
83             @return boolean false if the objects are "equal" false otherwise
84         */

85         
86         public boolean equals(Object JavaDoc other)
87         {
88             boolean isSame = false;
89             if (other instanceof Param)
90             {
91                 isSame = this.mName.equals(((Param)other).mName);
92             }
93             
94             return isSame;
95         }
96         
97         /**
98             Generates the hashcode for this param. Since equals() method takes
99             only name into account, this method also takes into account only
100             the name.
101             
102             @return integer hashcode
103         */

104         public int hashCode()
105         {
106             return (mName.hashCode ());
107         }
108 }
Popular Tags