Source Code Cross Referenced for MutableShort.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:        package org.apache.commons.lang.mutable;
018:
019:        /**
020:         * A mutable <code>short</code> wrapper.
021:         * 
022:         * @see Short
023:         * @since 2.1
024:         * @version $Id: MutableShort.java 437554 2006-08-28 06:21:41Z bayard $
025:         */
026:        public class MutableShort extends Number implements  Comparable, Mutable {
027:
028:            /**
029:             * Required for serialization support.
030:             * 
031:             * @see java.io.Serializable
032:             */
033:            private static final long serialVersionUID = -2135791679L;
034:
035:            /** The mutable value. */
036:            private short value;
037:
038:            /**
039:             * Constructs a new MutableShort with the default value of zero.
040:             */
041:            public MutableShort() {
042:                super ();
043:            }
044:
045:            /**
046:             * Constructs a new MutableShort with the specified value.
047:             * 
048:             * @param value
049:             *                  a value.
050:             */
051:            public MutableShort(short value) {
052:                super ();
053:                this .value = value;
054:            }
055:
056:            /**
057:             * Constructs a new MutableShort with the specified value.
058:             * 
059:             * @param value
060:             *                  a value.
061:             * @throws NullPointerException
062:             *                  if the object is null
063:             */
064:            public MutableShort(Number value) {
065:                super ();
066:                this .value = value.shortValue();
067:            }
068:
069:            //-----------------------------------------------------------------------
070:            /**
071:             * Gets the value as a Short instance.
072:             * 
073:             * @return the value as a Short
074:             */
075:            public Object getValue() {
076:                return new Short(this .value);
077:            }
078:
079:            /**
080:             * Sets the value.
081:             * 
082:             * @param value
083:             *                  the value to set
084:             */
085:            public void setValue(short value) {
086:                this .value = value;
087:            }
088:
089:            /**
090:             * Sets the value from any Number instance.
091:             * 
092:             * @param value
093:             *                  the value to set
094:             * @throws NullPointerException
095:             *                  if the object is null
096:             * @throws ClassCastException
097:             *                  if the type is not a {@link Number}
098:             */
099:            public void setValue(Object value) {
100:                setValue(((Number) value).shortValue());
101:            }
102:
103:            //-----------------------------------------------------------------------
104:            /**
105:             * Increments the value.
106:             *
107:             * @since Commons Lang 2.2
108:             */
109:            public void increment() {
110:                value++;
111:            }
112:
113:            /**
114:             * Decrements the value.
115:             *
116:             * @since Commons Lang 2.2
117:             */
118:            public void decrement() {
119:                value--;
120:            }
121:
122:            //-----------------------------------------------------------------------
123:            /**
124:             * Adds a value.
125:             * 
126:             * @param operand
127:             *            the value to add
128:             *
129:             * @since Commons Lang 2.2
130:             */
131:            public void add(short operand) {
132:                this .value += operand;
133:            }
134:
135:            /**
136:             * Adds a value.
137:             * 
138:             * @param operand
139:             *            the value to add
140:             * @throws NullPointerException
141:             *             if the object is null
142:             *
143:             * @since Commons Lang 2.2
144:             */
145:            public void add(Number operand) {
146:                this .value += operand.shortValue();
147:            }
148:
149:            /**
150:             * Subtracts a value.
151:             * 
152:             * @param operand
153:             *            the value to add
154:             *
155:             * @since Commons Lang 2.2
156:             */
157:            public void subtract(short operand) {
158:                this .value -= operand;
159:            }
160:
161:            /**
162:             * Subtracts a value.
163:             * 
164:             * @param operand
165:             *            the value to add
166:             * @throws NullPointerException
167:             *             if the object is null
168:             *
169:             * @since Commons Lang 2.2
170:             */
171:            public void subtract(Number operand) {
172:                this .value -= operand.shortValue();
173:            }
174:
175:            //-----------------------------------------------------------------------
176:            // bytValue relies on Number implementation
177:            /**
178:             * Returns the value of this MutableShort as a short.
179:             *
180:             * @return the numeric value represented by this object after conversion to type short.
181:             */
182:            public short shortValue() {
183:                return value;
184:            }
185:
186:            /**
187:             * Returns the value of this MutableShort as a int.
188:             *
189:             * @return the numeric value represented by this object after conversion to type int.
190:             */
191:            public int intValue() {
192:                return value;
193:            }
194:
195:            /**
196:             * Returns the value of this MutableShort as a long.
197:             *
198:             * @return the numeric value represented by this object after conversion to type long.
199:             */
200:            public long longValue() {
201:                return value;
202:            }
203:
204:            /**
205:             * Returns the value of this MutableShort as a float.
206:             *
207:             * @return the numeric value represented by this object after conversion to type float.
208:             */
209:            public float floatValue() {
210:                return value;
211:            }
212:
213:            /**
214:             * Returns the value of this MutableShort as a double.
215:             *
216:             * @return the numeric value represented by this object after conversion to type double.
217:             */
218:            public double doubleValue() {
219:                return value;
220:            }
221:
222:            //-----------------------------------------------------------------------
223:            /**
224:             * Gets this mutable as an instance of Short.
225:             *
226:             * @return a Short instance containing the value from this mutable
227:             */
228:            public Short toShort() {
229:                return new Short(shortValue());
230:            }
231:
232:            //-----------------------------------------------------------------------
233:            /**
234:             * Compares this object against the specified object. The result is <code>true</code> if and only if the argument
235:             * is not <code>null</code> and is a <code>MutableShort</code> object that contains the same <code>short</code>
236:             * value as this object.
237:             * 
238:             * @param obj
239:             *                  the object to compare with.
240:             * @return <code>true</code> if the objects are the same; <code>false</code> otherwise.
241:             */
242:            public boolean equals(Object obj) {
243:                if (obj instanceof  MutableShort) {
244:                    return value == ((MutableShort) obj).shortValue();
245:                }
246:                return false;
247:            }
248:
249:            /**
250:             * Returns a suitable hashcode for this mutable.
251:             * 
252:             * @return a suitable hashcode
253:             */
254:            public int hashCode() {
255:                return value;
256:            }
257:
258:            /**
259:             * Compares this mutable to another in ascending order.
260:             * 
261:             * @param obj
262:             *                  the mutable to compare to
263:             * @return negative if this is less, zero if equal, positive if greater
264:             * @throws ClassCastException if the argument is not a MutableShort
265:             */
266:            public int compareTo(Object obj) {
267:                MutableShort other = (MutableShort) obj;
268:                short anotherVal = other.value;
269:                return value < anotherVal ? -1 : (value == anotherVal ? 0 : 1);
270:            }
271:
272:            /**
273:             * Returns the String value of this mutable.
274:             * 
275:             * @return the mutable value as a string
276:             */
277:            public String toString() {
278:                return String.valueOf(value);
279:            }
280:
281:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.