Source Code Cross Referenced for IntArithmetic.java in  » Rule-Engine » Mandarax » org » mandarax » lib » math » 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 » Rule Engine » Mandarax » org.mandarax.lib.math 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 1999-2004 <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</a>
003:         *
004:         * This library is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 2 of the License, or (at your option) any later version.
008:         *
009:         * This library is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:         * Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:         */
018:        package org.mandarax.lib.math;
019:
020:        import org.mandarax.kernel.Function;
021:        import org.mandarax.kernel.Predicate;
022:
023:        /**
024:         * Class serving predicates and functions needed for int arithmetic.
025:         * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
026:         * @version 3.4 <7 March 05>
027:         * @since 1.4  (in 1.3 in the renamed package org.mandarax.math)
028:         */
029:        public class IntArithmetic {
030:
031:            // binary functions
032:            public static final Function MAX = new IntArithmetic.Max();
033:            public static final Function MIN = new IntArithmetic.Min();
034:            public static final Function PLUS = new IntArithmetic.Plus();
035:            public static final Function MINUS = new IntArithmetic.Minus();
036:            public static final Function TIMES = new IntArithmetic.Times();
037:            public static final Function POW = new IntArithmetic.Pow();
038:
039:            // unary functions
040:            public static final Function ABS = new IntArithmetic.Abs();
041:
042:            // binary predicates
043:            public static final Predicate LESS_THAN = new IntArithmetic.LessThan();
044:            public static final Predicate GREATER_THAN = new IntArithmetic.GreaterThan();
045:            public static final Predicate EQUAL = new IntArithmetic.Equal();
046:            public static final Predicate NOT_EQUAL = new IntArithmetic.NotEqual();
047:            public static final Predicate LESS_THAN_OR_EQUAL = new IntArithmetic.LessThanOrEqual();
048:            public static final Predicate GREATER_THAN_OR_EQUAL = new IntArithmetic.GreaterThanOrEqual();
049:
050:            // ternary predicates
051:            public static final Predicate INCLUSIVE_BETWEEN = new IntArithmetic.InclusiveBetween();
052:            public static final Predicate EXCLUSIVE_BETWEEN = new IntArithmetic.ExclusiveBetween();
053:
054:            // all functions and predicates
055:            public static final Function[] ALL_FUNCTIONS = { MAX, MIN, PLUS,
056:                    MINUS, TIMES, POW, ABS };
057:            public static final Predicate[] ALL_PREDICATES = { EQUAL,
058:                    NOT_EQUAL, LESS_THAN, GREATER_THAN, LESS_THAN_OR_EQUAL,
059:                    GREATER_THAN_OR_EQUAL, INCLUSIVE_BETWEEN, EXCLUSIVE_BETWEEN };
060:
061:            // class representing the max function
062:            public static class Max extends BinaryIntArithmeticFunction {
063:
064:                public String getName() {
065:                    return "max";
066:                }
067:
068:                public int compute(int x1, int x2) {
069:                    return Math.max(x1, x2);
070:                }
071:            }
072:
073:            // class representing the min function
074:            public static class Min extends BinaryIntArithmeticFunction {
075:
076:                public String getName() {
077:                    return "min";
078:                }
079:
080:                public int compute(int x1, int x2) {
081:                    return Math.min(x1, x2);
082:                }
083:            }
084:
085:            // class representing the plus function
086:            public static class Plus extends BinaryIntArithmeticFunction {
087:
088:                public String getName() {
089:                    return "+";
090:                }
091:
092:                public int compute(int x1, int x2) {
093:                    return x1 + x2;
094:                }
095:            }
096:
097:            // class representing the times function
098:            public static class Times extends BinaryIntArithmeticFunction {
099:
100:                public String getName() {
101:                    return "*";
102:                }
103:
104:                public int compute(int x1, int x2) {
105:                    return x1 * x2;
106:                }
107:            }
108:
109:            // class representing the minus function
110:            public static class Minus extends BinaryIntArithmeticFunction {
111:
112:                public String getName() {
113:                    return "-";
114:                }
115:
116:                public int compute(int x1, int x2) {
117:                    return x1 - x2;
118:                }
119:            }
120:
121:            // class representing the to the power of function
122:            public static class Pow extends BinaryIntArithmeticFunction {
123:
124:                public String getName() {
125:                    return "pow";
126:                }
127:
128:                public int compute(int x1, int x2) {
129:                    return x1 ^ x2;
130:                }
131:            }
132:
133:            // class representing the abs function
134:            public static class Abs extends UnaryIntArithmeticFunction {
135:
136:                public String getName() {
137:                    return "abs";
138:                }
139:
140:                public int compute(int x) {
141:                    return Math.abs(x);
142:                }
143:            }
144:
145:            // class representing the equals predicate
146:            public static class Equal extends BinaryIntArithmeticPredicate {
147:
148:                public String getName() {
149:                    return "=";
150:                }
151:
152:                public boolean evaluate(int x1, int x2) {
153:                    return x1 == x2;
154:                }
155:            }
156:
157:            // class representing the equals not predicate
158:            public static class NotEqual extends BinaryIntArithmeticPredicate {
159:
160:                public String getName() {
161:                    return "!=";
162:                }
163:
164:                public boolean evaluate(int x1, int x2) {
165:                    return x1 != x2;
166:                }
167:            }
168:
169:            // class representing the greater than predicate
170:            public static class GreaterThan extends
171:                    BinaryIntArithmeticPredicate {
172:
173:                public String getName() {
174:                    return ">";
175:                }
176:
177:                public boolean evaluate(int x1, int x2) {
178:                    return x1 > x2;
179:                }
180:            }
181:
182:            // class representing the less than predicate
183:            public static class LessThan extends BinaryIntArithmeticPredicate {
184:
185:                public String getName() {
186:                    return "<";
187:                }
188:
189:                public boolean evaluate(int x1, int x2) {
190:                    return x1 < x2;
191:                }
192:            }
193:
194:            // class representing the less than or equals predicate
195:            public static class LessThanOrEqual extends
196:                    BinaryIntArithmeticPredicate {
197:
198:                public String getName() {
199:                    return "=<";
200:                }
201:
202:                public boolean evaluate(int x1, int x2) {
203:                    return (x1 < x2) || (x1 == x2);
204:                }
205:            }
206:
207:            // class representing the greater than or equals predicate
208:            public static class GreaterThanOrEqual extends
209:                    BinaryIntArithmeticPredicate {
210:
211:                public String getName() {
212:                    return "=>";
213:                }
214:
215:                public boolean evaluate(int x1, int x2) {
216:                    return (x1 > x2) || (x1 == x2);
217:                }
218:            }
219:
220:            // class representing the exclusive between predicate
221:            public static class ExclusiveBetween extends
222:                    TernaryIntArithmeticPredicate {
223:
224:                public String getName() {
225:                    return "between (excl.)";
226:                }
227:
228:                public boolean evaluate(int x1, int x2, int x3) {
229:                    return (x1 < x2) && (x2 < x3);
230:                }
231:            }
232:
233:            // class representing the inclusive between predicate
234:            public static class InclusiveBetween extends
235:                    TernaryIntArithmeticPredicate {
236:
237:                public String getName() {
238:                    return "between (incl.)";
239:                }
240:
241:                public boolean evaluate(int x1, int x2, int x3) {
242:                    return (x1 <= x2) && (x2 <= x3);
243:                }
244:            }
245:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.