KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > customizers > data > ParamMapping


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 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * ParamMapping.java
21  *
22  * Created on January 29, 2004, 2:06 PM
23  */

24
25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.data;
26
27 /**
28  *
29  * @author Peter Williams
30  */

31 public class ParamMapping implements Comparable JavaDoc {
32     
33     private PropertyParam param;
34 // private String displayText;
35

36     /** Creates a new instance of ParamMapping
37      * This object does handle a null PropertyParam
38      */

39     public ParamMapping(final PropertyParam pp) {
40         param = pp;
41     }
42
43     /** equals() maps to PropertyParam.equals()
44      *
45      * @return true/false based on whether the embedded property param objects
46      * compare as equal.
47      */

48     public boolean equals(Object JavaDoc obj) {
49         boolean result = false;
50         
51         // This implementation is made more difficult due to the allowing of the
52
// param member to be null (to represent a null entry in the combobox).
53
//
54
if(obj instanceof ParamMapping) {
55             if(this == obj) {
56                 result = true;
57             } else {
58                 ParamMapping targetMapping = (ParamMapping) obj;
59                 PropertyParam targetParam = targetMapping.getParam();
60                 if(param != null) {
61                     if(targetParam != null) {
62                         result = param.getParamName().equals(targetParam.getParamName());
63                     }
64                 } else if(targetParam == null) {
65                     result = true;
66                 }
67             }
68         }
69         return result;
70     }
71     
72     /** hashCode() maps to PropertyParam.hashCode()
73      *
74      * @return the hashcode
75      */

76     public int hashCode() {
77         int hashcode = 509; // use this prime for nulls.
78
if(param != null) {
79             hashcode = param.getParamName().hashCode();
80         }
81         return hashcode;
82     }
83     
84     /** A more readable display string
85      *
86      * @return A descriptive string
87      */

88     public String JavaDoc toString() {
89         String JavaDoc result = "";
90         if(param != null) {
91             result = param.getParamName();
92         }
93         return result;
94     }
95
96     /** The property param
97      *
98      * @return the property param this is a mapping for
99      */

100     public PropertyParam getParam() {
101         return param;
102     }
103     
104     /** For sorted collections. We compare the string representations of the
105      * embedded property param.
106      *
107      * @param obj the ParamMapping to compare to
108      * @return result of comparison (negative, 0, or positive depending on match)
109      */

110     public int compareTo(Object JavaDoc obj) {
111         int result = -1;
112         
113         // This implementation is made more difficult due to the allowing of the
114
// param member to be null (to represent a null entry in the combobox).
115
//
116
// If param is null, that entry is considered less than any other param
117
// type so that it's always at the top of the list.
118
//
119
if(obj instanceof ParamMapping) {
120             if(this == obj) {
121                 result = 0;
122             } else {
123                 ParamMapping targetMapping = (ParamMapping) obj;
124                 PropertyParam targetParam = targetMapping.getParam();
125                 if(param != null) {
126                     if(targetParam != null) {
127                         result = param.getParamName().compareTo(targetParam.getParamName());
128                     } else {
129                         result = 1;
130                     }
131                 } else if(targetParam == null) {
132                     result = 0;
133                 }
134             }
135         }
136         
137         return result;
138     }
139 }
140
Popular Tags