Source Code Cross Referenced for Integer64.java in  » Science » jscience-4.3.1 » org » jscience » mathematics » number » 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 » Science » jscience 4.3.1 » org.jscience.mathematics.number 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JScience - Java(TM) Tools and Libraries for the Advancement of Sciences.
003:         * Copyright (C) 2006 - JScience (http://jscience.org/)
004:         * All rights reserved.
005:         * 
006:         * Permission to use, copy, modify, and distribute this software is
007:         * freely granted, provided that this notice is preserved.
008:         */
009:        package org.jscience.mathematics.number;
010:
011:        import javolution.context.ObjectFactory;
012:        import javolution.lang.MathLib;
013:        import javolution.text.Text;
014:        import javolution.text.TypeFormat;
015:        import javolution.xml.XMLFormat;
016:        import javolution.xml.stream.XMLStreamException;
017:
018:        /**
019:         * <p> This class represents a 64 bits integer number.</p>
020:         * 
021:         * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
022:         * @version 3.0, February 13, 2006
023:         * @see <a href="http://en.wikipedia.org/wiki/Integer">
024:         *      Wikipedia: Integer</a>
025:         */
026:        public final class Integer64 extends Number<Integer64> {
027:
028:            /**
029:             * Holds the default XML representation for 64 bits integer numbers.
030:             * This representation consists of a simple <code>value</code> attribute
031:             * holding the {@link #toText() textual} representation.
032:             */
033:            static final XMLFormat<Integer64> XML = new XMLFormat<Integer64>(
034:                    Integer64.class) {
035:
036:                @Override
037:                public Integer64 newInstance(Class<Integer64> cls,
038:                        InputElement xml) throws XMLStreamException {
039:                    return Integer64.valueOf(xml.getAttribute("value", 0L));
040:                }
041:
042:                public void write(Integer64 integer64, OutputElement xml)
043:                        throws XMLStreamException {
044:                    xml.setAttribute("value", integer64._value);
045:                }
046:
047:                public void read(InputElement xml, Integer64 integer64) {
048:                    // Nothing to do, immutable.
049:                }
050:            };
051:
052:            /**
053:             * Holds the factory used to produce 64 bits integer instances.
054:             */
055:            private static final ObjectFactory<Integer64> FACTORY = new ObjectFactory<Integer64>() {
056:
057:                protected Integer64 create() {
058:                    return new Integer64();
059:                }
060:            };
061:
062:            /**
063:             * The 64 bits floating point representing zero.
064:             */
065:            public static final Integer64 ZERO = new Integer64(0L);
066:
067:            /**
068:             * The 64 bits floating point representing one.
069:             */
070:            public static final Integer64 ONE = new Integer64(1L);
071:
072:            /**
073:             * The associated long value.
074:             */
075:            private long _value;
076:
077:            /**
078:             * Default constructor.
079:             */
080:            private Integer64() {
081:            }
082:
083:            /**
084:             * Returns the 64 bits integer from the specified <code>long</code> value.
085:             *
086:             * @param  longValue the <code>long</code> value for this number.
087:             * @see    #longValue()
088:             */
089:            private Integer64(long longValue) {
090:                _value = longValue;
091:            }
092:
093:            /**
094:             * Returns the 64 bits integer from the specified <code>long</code> value.
095:             *
096:             * @param  longValue the <code>long</code> value for this number.
097:             * @return the corresponding number.
098:             * @see    #longValue()
099:             */
100:            public static Integer64 valueOf(long longValue) {
101:                Integer64 r = FACTORY.object();
102:                r._value = longValue;
103:                return r;
104:            }
105:
106:            /**
107:             * Returns the number for the specified character sequence.
108:             *
109:             * @param  chars the character sequence.
110:             * @return the corresponding number.
111:             */
112:            public static Integer64 valueOf(CharSequence chars) {
113:                Integer64 r = FACTORY.object();
114:                r._value = TypeFormat.parseLong(chars);
115:                return r;
116:            }
117:
118:            /**
119:             * Returns the opposite of this number.
120:             *
121:             * @return <code>-this</code>.
122:             */
123:            public Integer64 opposite() {
124:                Integer64 r = FACTORY.object();
125:                r._value = -this ._value;
126:                return r;
127:            }
128:
129:            /**
130:             * Returns the sum of this number with the one specified.
131:             *
132:             * @param  that the number to be added.
133:             * @return <code>this + that</code>.
134:             */
135:            public Integer64 plus(Integer64 that) {
136:                Integer64 r = FACTORY.object();
137:                r._value = this ._value + that._value;
138:                return r;
139:            }
140:
141:            /**
142:             * Returns the sum of this number with the specifice value.
143:             *
144:             * @param  value the value to be added.
145:             * @return <code>this + value</code>.
146:             */
147:            public Integer64 plus(long value) {
148:                Integer64 r = FACTORY.object();
149:                r._value = this ._value + value;
150:                return r;
151:            }
152:
153:            /**
154:             * Returns the difference between this number and the one specified.
155:             *
156:             * @param  that the number to be subtracted.
157:             * @return <code>this - that</code>.
158:             */
159:            public Integer64 minus(Integer64 that) {
160:                Integer64 r = FACTORY.object();
161:                r._value = this ._value - that._value;
162:                return r;
163:            }
164:
165:            /**
166:             * Returns the difference between this number and the specified value
167:             *
168:             * @param  value the value to be subtracted.
169:             * @return <code>this - value</code>.
170:             */
171:            public Integer64 minus(long value) {
172:                Integer64 r = FACTORY.object();
173:                r._value = this ._value - value;
174:                return r;
175:            }
176:
177:            /**
178:             * Returns the product of this number with the one specified.
179:             *
180:             * @param  that the number multiplier.
181:             * @return <code>this · that</code>.
182:             */
183:            public Integer64 times(Integer64 that) {
184:                Integer64 r = FACTORY.object();
185:                r._value = this ._value * that._value;
186:                return r;
187:            }
188:
189:            /**
190:             * Returns the product of this number with the specified value.
191:             *
192:             * @param  value the value multiplier.
193:             * @return <code>this · value</code>.
194:             */
195:            public Integer64 times(long value) {
196:                Integer64 r = FACTORY.object();
197:                r._value = this ._value * value;
198:                return r;
199:            }
200:
201:            /**
202:             * Returns this number divided by the one specified.
203:             *
204:             * @param  that the number divisor.
205:             * @return <code>this / that</code>.
206:             */
207:            public Integer64 divide(Integer64 that) {
208:                Integer64 r = FACTORY.object();
209:                r._value = this ._value / that._value;
210:                return r;
211:            }
212:
213:            /**
214:             * Returns this number divided by the specified value.
215:             *
216:             * @param  value the value divisor.
217:             * @return <code>this / value</code>.
218:             */
219:            public Integer64 divide(long value) {
220:                Integer64 r = FACTORY.object();
221:                r._value = this ._value / value;
222:                return r;
223:            }
224:
225:            /**
226:             * Compares the magnitude of this number with that number.
227:             *
228:             * @return <code>|this| > |that|</code>
229:             */
230:            public boolean isLargerThan(Integer64 that) {
231:                return MathLib.abs(this ._value) > MathLib.abs(that._value);
232:            }
233:
234:            /**
235:             * Returns the absolute value of this number.
236:             *
237:             * @return <code>|this|</code>.
238:             */
239:            public Integer64 abs() {
240:                Integer64 r = FACTORY.object();
241:                r._value = MathLib.abs(this ._value);
242:                return r;
243:            }
244:
245:            /**
246:             * Returns the decimal text representation of this number.
247:             *
248:             * @return the text representation of this number.
249:             */
250:            public Text toText() {
251:                return Text.valueOf(_value);
252:            }
253:
254:            /**
255:             * Compares this number against the specified object.
256:             *
257:             * @param  that the object to compare with.
258:             * @return <code>true</code> if the objects are the same;
259:             *         <code>false</code> otherwise.
260:             */
261:            public boolean equals(Object that) {
262:                return (that instanceof  Integer64)
263:                        && (this ._value == ((Integer64) that)._value);
264:            }
265:
266:            /**
267:             * Compares this number against the specified value.
268:             *
269:             * @param  value the value to compare with.
270:             * @return <code>this.longValue() == value</code>
271:             */
272:            public boolean equals(long value) {
273:                return this ._value == value;
274:            }
275:
276:            /**
277:             * Compares this number with the specified value for order.
278:             * 
279:             * @param value the value to be compared with.
280:             * @return a negative integer, zero, or a positive integer as this number
281:             *        is less than, equal to, or greater than the specified value.
282:             */
283:            public int compareTo(long value) {
284:                if (this ._value < value) {
285:                    return -1;
286:                } else if (this ._value > value) {
287:                    return 1;
288:                } else {
289:                    return 0;
290:                }
291:            }
292:
293:            /**
294:             * Returns the hash code for this number.
295:             * 
296:             * @return the hash code value.
297:             */
298:            public int hashCode() {
299:                int h = Float.floatToIntBits((float) _value);
300:                h += ~(h << 9);
301:                h ^= (h >>> 14);
302:                h += (h << 4);
303:                return h ^ (h >>> 10);
304:            }
305:
306:            @Override
307:            public long longValue() {
308:                return _value;
309:            }
310:
311:            @Override
312:            public double doubleValue() {
313:                return _value;
314:            }
315:
316:            @Override
317:            public int compareTo(Integer64 that) {
318:                return compareTo(that._value);
319:            }
320:
321:            @Override
322:            public Integer64 copy() {
323:                return Integer64.valueOf(_value);
324:            }
325:
326:            private static final long serialVersionUID = 1L;
327:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.