KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > groovy > runtime > LongMath


1 /*
2  * Created on Mar 5, 2004
3  *
4  */

5 package org.codehaus.groovy.runtime;
6
7 /**
8  * Long NumberMath operations
9  *
10  * @author Steve Goetze
11  */

12 public class LongMath extends NumberMath {
13
14     protected static LongMath instance = new LongMath();
15
16     private LongMath() {}
17                     
18     protected Number JavaDoc absImpl(Number JavaDoc number) {
19         return new Long JavaDoc(Math.abs(number.longValue()));
20     }
21     
22     protected Number JavaDoc addImpl(Number JavaDoc left, Number JavaDoc right) {
23         return new Long JavaDoc(left.longValue() + right.longValue());
24     }
25
26     protected Number JavaDoc subtractImpl(Number JavaDoc left, Number JavaDoc right) {
27         return new Long JavaDoc(left.longValue() - right.longValue());
28     }
29
30     protected Number JavaDoc multiplyImpl(Number JavaDoc left, Number JavaDoc right) {
31         return new Long JavaDoc(left.longValue() * right.longValue());
32     }
33
34     protected Number JavaDoc divideImpl(Number JavaDoc left, Number JavaDoc right) {
35         return BigDecimalMath.instance.divideImpl(left, right);
36     }
37     
38     protected int compareToImpl(Number JavaDoc left, Number JavaDoc right) {
39         long leftVal = left.longValue();
40         long rightVal = right.longValue();
41         return (leftVal<rightVal ? -1 : (leftVal==rightVal ? 0 : 1));
42     }
43
44     protected Number JavaDoc andImpl(Number JavaDoc left, Number JavaDoc right) {
45         return new Long JavaDoc(left.longValue() & right.longValue());
46     }
47     
48     protected Number JavaDoc intdivImpl(Number JavaDoc left, Number JavaDoc right) {
49         return new Long JavaDoc(left.longValue() / right.longValue());
50     }
51     
52     protected Number JavaDoc modImpl(Number JavaDoc left, Number JavaDoc right) {
53         return new Long JavaDoc(left.longValue() % right.longValue());
54     }
55     
56     protected Number JavaDoc negateImpl(Number JavaDoc left) {
57         return new Long JavaDoc(-left.longValue());
58     }
59     
60     protected Number JavaDoc orImpl(Number JavaDoc left, Number JavaDoc right) {
61         return new Long JavaDoc(left.longValue() | right.longValue());
62     }
63
64     protected Number JavaDoc leftShiftImpl(Number JavaDoc left, Number JavaDoc right) {
65         return new Long JavaDoc(left.longValue() << right.longValue());
66     }
67
68     protected Number JavaDoc rightShiftImpl(Number JavaDoc left, Number JavaDoc right) {
69         return new Long JavaDoc(left.longValue() >> right.longValue());
70     }
71
72     protected Number JavaDoc rightShiftUnsignedImpl(Number JavaDoc left, Number JavaDoc right) {
73         return new Long JavaDoc(left.longValue() >>> right.longValue());
74     }
75 }
76
Popular Tags