Source Code Cross Referenced for MutableBoolean.java in  » Library » Apache-common-lang » org » apache » commons » lang » mutable » 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 » Library » Apache common lang » org.apache.commons.lang.mutable 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.commons.lang.mutable;
019:
020:        import java.io.Serializable;
021:
022:        import org.apache.commons.lang.BooleanUtils;
023:
024:        /**
025:         * A mutable <code>boolean</code> wrapper.
026:         * 
027:         * @see Boolean
028:         * @since 2.2
029:         * @author Apache Software Foundation
030:         * @version $Id: MutableBoolean.java 491052 2006-12-29 17:16:37Z scolebourne $
031:         */
032:        public class MutableBoolean implements  Mutable, Serializable,
033:                Comparable {
034:
035:            /**
036:             * Required for serialization support.
037:             * 
038:             * @see java.io.Serializable
039:             */
040:            private static final long serialVersionUID = -4830728138360036487L;
041:
042:            /** The mutable value. */
043:            private boolean value;
044:
045:            /**
046:             * Constructs a new MutableBoolean with the default value of false.
047:             */
048:            public MutableBoolean() {
049:                super ();
050:            }
051:
052:            /**
053:             * Constructs a new MutableBoolean with the specified value.
054:             * 
055:             * @param value
056:             *            a value.
057:             */
058:            public MutableBoolean(boolean value) {
059:                super ();
060:                this .value = value;
061:            }
062:
063:            /**
064:             * Constructs a new MutableBoolean with the specified value.
065:             * 
066:             * @param value
067:             *            a value.
068:             * @throws NullPointerException
069:             *             if the object is null
070:             */
071:            public MutableBoolean(Boolean value) {
072:                super ();
073:                this .value = value.booleanValue();
074:            }
075:
076:            // -----------------------------------------------------------------------
077:            /**
078:             * Returns the value of this MutableBoolean as a boolean.
079:             * 
080:             * @return the boolean value represented by this object.
081:             */
082:            public boolean booleanValue() {
083:                return value;
084:            }
085:
086:            /**
087:             * Compares this mutable to another in ascending order.
088:             * 
089:             * @param obj
090:             *            the mutable to compare to
091:             * @return zero if this object represents the same boolean value as the argument; a positive value if this object
092:             *         represents true and the argument represents false; and a negative value if this object represents false
093:             *         and the argument represents true
094:             * @throws ClassCastException
095:             *             if the argument is not a MutableInt
096:             */
097:            public int compareTo(Object obj) {
098:                MutableBoolean other = (MutableBoolean) obj;
099:                boolean anotherVal = other.value;
100:                return value == anotherVal ? 0 : (value ? 1 : -1);
101:            }
102:
103:            // -----------------------------------------------------------------------
104:            /**
105:             * Compares this object to the specified object. The result is <code>true</code> if and only if the argument is
106:             * not <code>null</code> and is an <code>MutableBoolean</code> object that contains the same
107:             * <code>boolean</code> value as this object.
108:             * 
109:             * @param obj
110:             *            the object to compare with.
111:             * @return <code>true</code> if the objects are the same; <code>false</code> otherwise.
112:             */
113:            public boolean equals(Object obj) {
114:                if (obj instanceof  MutableBoolean) {
115:                    return value == ((MutableBoolean) obj).booleanValue();
116:                }
117:                return false;
118:            }
119:
120:            // -----------------------------------------------------------------------
121:            /**
122:             * Gets the value as a Boolean instance.
123:             * 
124:             * @return the value as a Boolean
125:             */
126:            public Object getValue() {
127:                return BooleanUtils.toBooleanObject(this .value);
128:            }
129:
130:            /**
131:             * Returns a suitable hashcode for this mutable.
132:             * 
133:             * @return the integer <code>1231</code> if this object represents <code>true</code>; returns the integer
134:             *         <code>1237</code> if this object represents <code>false</code>.
135:             */
136:            public int hashCode() {
137:                return value ? Boolean.TRUE.hashCode() : Boolean.FALSE
138:                        .hashCode();
139:            }
140:
141:            /**
142:             * Sets the value.
143:             * 
144:             * @param value
145:             *            the value to set
146:             */
147:            public void setValue(boolean value) {
148:                this .value = value;
149:            }
150:
151:            /**
152:             * Sets the value from any Boolean instance.
153:             * 
154:             * @param value
155:             *            the value to set
156:             * @throws NullPointerException
157:             *             if the object is null
158:             * @throws ClassCastException
159:             *             if the type is not a {@link Boolean}
160:             */
161:            public void setValue(Object value) {
162:                setValue(((Boolean) value).booleanValue());
163:            }
164:
165:            /**
166:             * Returns the String value of this mutable.
167:             * 
168:             * @return the mutable value as a string
169:             */
170:            public String toString() {
171:                return String.valueOf(value);
172:            }
173:
174:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.