Source Code Cross Referenced for MathInteger.java in  » Science » JSci » JSci » maths » 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 » JSci » JSci.maths 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package JSci.maths;
002:
003:        import java.lang.Comparable;
004:
005:        import JSci.GlobalSettings;
006:        import JSci.maths.groups.AbelianGroup;
007:        import JSci.maths.fields.*;
008:
009:        /**
010:         * The MathInteger class encapsulates integer numbers.
011:         * @see JSci.maths.fields.IntegerRing
012:         * @version 1.0
013:         * @author Mark Hale
014:         */
015:        public final class MathInteger extends Number implements  Comparable,
016:                Ring.Member {
017:            private static final long serialVersionUID = 6893485894391864141L;
018:
019:            private final int x;
020:
021:            /**
022:             * Constructs an integer number.
023:             */
024:            public MathInteger(final int num) {
025:                x = num;
026:            }
027:
028:            /**
029:             * Constructs the integer number represented by a string.
030:             * @param s a string representing an integer number.
031:             * @exception NumberFormatException if the string does not contain a parsable number.
032:             */
033:            public MathInteger(final String s) throws NumberFormatException {
034:                x = Integer.parseInt(s);
035:            }
036:
037:            /**
038:             * Compares two integer numbers for equality.
039:             * @param obj an integer number.
040:             */
041:            public boolean equals(Object obj) {
042:                if (obj instanceof  MathInteger)
043:                    return x == ((MathInteger) obj).value();
044:                else
045:                    return false;
046:            }
047:
048:            public int hashCode() {
049:                return x;
050:            }
051:
052:            /**
053:             * Compares two integer numbers.
054:             * @param obj an integer number.
055:             * @return a negative value if <code>this&lt;obj</code>,
056:             * zero if <code>this==obj</code>,
057:             * and a positive value if <code>this&gt;obj</code>.
058:             */
059:            public int compareTo(Object obj) throws IllegalArgumentException {
060:                if (obj != null && (obj instanceof  MathInteger)) {
061:                    int objValue = ((MathInteger) obj).x;
062:                    if (x == objValue)
063:                        return 0;
064:                    else
065:                        return x - objValue;
066:                } else
067:                    throw new IllegalArgumentException("Invalid object: "
068:                            + obj.getClass());
069:            }
070:
071:            /**
072:             * Returns a string representing the value of this integer number.
073:             */
074:            public String toString() {
075:                return Integer.toString(x);
076:            }
077:
078:            /**
079:             * Returns the integer value.
080:             */
081:            public int value() {
082:                return x;
083:            }
084:
085:            public int intValue() {
086:                return x;
087:            }
088:
089:            public long longValue() {
090:                return x;
091:            }
092:
093:            public float floatValue() {
094:                return x;
095:            }
096:
097:            public double doubleValue() {
098:                return x;
099:            }
100:
101:            /**
102:             * Returns true if this number is even.
103:             */
104:            public boolean isEven() {
105:                return (x & 1) == 0;
106:            }
107:
108:            /**
109:             * Returns true if this number is odd.
110:             */
111:            public boolean isOdd() {
112:                return (x & 1) == 1;
113:            }
114:
115:            public Object getSet() {
116:                return IntegerRing.getInstance();
117:            }
118:
119:            /**
120:             * Returns the negative of this number.
121:             */
122:            public AbelianGroup.Member negate() {
123:                return new MathInteger(-x);
124:            }
125:
126:            /**
127:             * Returns the addition of this number and another.
128:             */
129:            public AbelianGroup.Member add(final AbelianGroup.Member n) {
130:                if (n instanceof  MathInteger)
131:                    return add((MathInteger) n);
132:                else
133:                    throw new IllegalArgumentException(
134:                            "Member class not recognised by this method: "
135:                                    + n.getClass());
136:            }
137:
138:            /**
139:             * Returns the addition of this integer number and another.
140:             */
141:            public MathInteger add(final MathInteger n) {
142:                return add(n.x);
143:            }
144:
145:            public MathInteger add(int y) {
146:                return new MathInteger(x + y);
147:            }
148:
149:            /**
150:             * Returns the subtraction of this number and another.
151:             */
152:            public AbelianGroup.Member subtract(final AbelianGroup.Member n) {
153:                if (n instanceof  MathInteger)
154:                    return subtract((MathInteger) n);
155:                else
156:                    throw new IllegalArgumentException(
157:                            "Member class not recognised by this method: "
158:                                    + n.getClass());
159:            }
160:
161:            /**
162:             * Returns the subtraction of this integer number and another.
163:             * @param n an integer number.
164:             */
165:            public MathInteger subtract(final MathInteger n) {
166:                return subtract(n.x);
167:            }
168:
169:            public MathInteger subtract(int y) {
170:                return new MathInteger(x - y);
171:            }
172:
173:            /**
174:             * Returns the multiplication of this number and another.
175:             */
176:            public Ring.Member multiply(final Ring.Member n) {
177:                if (n instanceof  MathInteger)
178:                    return multiply((MathInteger) n);
179:                else
180:                    throw new IllegalArgumentException(
181:                            "Member class not recognised by this method: "
182:                                    + n.getClass());
183:            }
184:
185:            /**
186:             * Returns the multiplication of this integer number and another.
187:             * @param n an integer number.
188:             */
189:            public MathInteger multiply(final MathInteger n) {
190:                return multiply(n.x);
191:            }
192:
193:            public MathInteger multiply(int y) {
194:                return new MathInteger(x * y);
195:            }
196:
197:            /**
198:             * Returns this integer number raised to the power of another.
199:             * @param n an integer number.
200:             */
201:            public MathInteger pow(final MathInteger n) {
202:                if (n.x == 0)
203:                    return IntegerRing.ONE;
204:                else {
205:                    int ans = x;
206:                    for (int i = 1; i < n.x; i++)
207:                        ans *= x;
208:                    return new MathInteger(ans);
209:                }
210:            }
211:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.