Source Code Cross Referenced for LabelValueBean.java in  » Web-Framework » struts-1.3.8 » org » apache » struts » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » struts 1.3.8 » org.apache.struts.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: LabelValueBean.java 471754 2006-11-06 14:55:09Z husted $
003:         *
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *  http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.
020:         */
021:        package org.apache.struts.util;
022:
023:        import java.io.Serializable;
024:
025:        import java.util.Comparator;
026:
027:        /**
028:         * A simple JavaBean to represent label-value pairs. This is most commonly
029:         * used when constructing user interface elements which have a label to be
030:         * displayed to the user, and a corresponding value to be returned to the
031:         * server. One example is the <code>&lt;html:options&gt;</code> tag.
032:         *
033:         * <p> Note: this class has a natural ordering that is inconsistent with
034:         * equals. </p>
035:         *
036:         * @version $Rev: 471754 $ $Date: 2005-05-07 12:11:38 -0400 (Sat, 07 May 2005)
037:         *          $
038:         */
039:        public class LabelValueBean implements  Comparable, Serializable {
040:            /**
041:             * Comparator that can be used for a case insensitive sort of
042:             * <code>LabelValueBean</code> objects.
043:             */
044:            public static final Comparator CASE_INSENSITIVE_ORDER = new Comparator() {
045:                public int compare(Object o1, Object o2) {
046:                    String label1 = ((LabelValueBean) o1).getLabel();
047:                    String label2 = ((LabelValueBean) o2).getLabel();
048:
049:                    return label1.compareToIgnoreCase(label2);
050:                }
051:            };
052:
053:            // ------------------------------------------------------------- Properties
054:
055:            /**
056:             * The property which supplies the option label visible to the end user.
057:             */
058:            private String label = null;
059:
060:            /**
061:             * The property which supplies the value returned to the server.
062:             */
063:            private String value = null;
064:
065:            // ----------------------------------------------------------- Constructors
066:
067:            /**
068:             * Default constructor.
069:             */
070:            public LabelValueBean() {
071:                super ();
072:            }
073:
074:            /**
075:             * Construct an instance with the supplied property values.
076:             *
077:             * @param label The label to be displayed to the user.
078:             * @param value The value to be returned to the server.
079:             */
080:            public LabelValueBean(String label, String value) {
081:                this .label = label;
082:                this .value = value;
083:            }
084:
085:            public String getLabel() {
086:                return this .label;
087:            }
088:
089:            public void setLabel(String label) {
090:                this .label = label;
091:            }
092:
093:            public String getValue() {
094:                return this .value;
095:            }
096:
097:            public void setValue(String value) {
098:                this .value = value;
099:            }
100:
101:            // --------------------------------------------------------- Public Methods
102:
103:            /**
104:             * Compare LabelValueBeans based on the label, because that's the human
105:             * viewable part of the object.
106:             *
107:             * @see Comparable
108:             */
109:            public int compareTo(Object o) {
110:                // Implicitly tests for the correct type, throwing
111:                // ClassCastException as required by interface
112:                String otherLabel = ((LabelValueBean) o).getLabel();
113:
114:                return this .getLabel().compareTo(otherLabel);
115:            }
116:
117:            /**
118:             * Return a string representation of this object.
119:             */
120:            public String toString() {
121:                StringBuffer sb = new StringBuffer("LabelValueBean[");
122:
123:                sb.append(this .label);
124:                sb.append(", ");
125:                sb.append(this .value);
126:                sb.append("]");
127:
128:                return (sb.toString());
129:            }
130:
131:            /**
132:             * LabelValueBeans are equal if their values are both null or equal.
133:             *
134:             * @see Object#equals(Object)
135:             */
136:            public boolean equals(Object obj) {
137:                if (obj == this ) {
138:                    return true;
139:                }
140:
141:                if (!(obj instanceof  LabelValueBean)) {
142:                    return false;
143:                }
144:
145:                LabelValueBean bean = (LabelValueBean) obj;
146:                int nil = (this .getValue() == null) ? 1 : 0;
147:
148:                nil += ((bean.getValue() == null) ? 1 : 0);
149:
150:                if (nil == 2) {
151:                    return true;
152:                } else if (nil == 1) {
153:                    return false;
154:                } else {
155:                    return this .getValue().equals(bean.getValue());
156:                }
157:            }
158:
159:            /**
160:             * The hash code is based on the object's value.
161:             *
162:             * @see Object#hashCode()
163:             */
164:            public int hashCode() {
165:                return (this .getValue() == null) ? 17 : this.getValue()
166:                        .hashCode();
167:            }
168:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.