KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > print > cUnit


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.core.print;
17
18 public abstract class cUnit implements Cloneable JavaDoc {
19
20     private double units = 0.0;
21
22     public cUnit() {
23     }
24
25     public double getUnits() {
26         return units;
27     }
28
29     public void setUnits(double units) {
30         this.units = units;
31     }
32
33     public abstract void setPoints(double p);
34
35     public abstract double getPoints();
36
37     public cUnit add(double units) {
38         cUnit temp = (cUnit) clone();
39         temp.setUnits(this.getUnits() + units);
40
41         return temp;
42     }
43
44     public cUnit add(cUnit units) {
45         cUnit temp = (cUnit) clone();
46         temp.setPoints(this.getPoints() + units.getPoints());
47
48         return temp;
49     }
50
51     public void addI(cUnit units) {
52         setPoints(getPoints() + units.getPoints());
53     }
54
55     public cUnit sub(double units) {
56         cUnit temp = (cUnit) clone();
57         temp.setUnits(this.getUnits() - units);
58
59         return temp;
60     }
61
62     public cUnit sub(cUnit units) {
63         cUnit temp = (cUnit) clone();
64         temp.setPoints(this.getPoints() - units.getPoints());
65
66         return temp;
67     }
68
69     public void subI(cUnit units) {
70         setPoints(getPoints() - units.getPoints());
71     }
72
73     public cUnit mul(double units) {
74         cUnit temp = (cUnit) clone();
75         temp.setUnits(this.getUnits() * units);
76
77         return temp;
78     }
79
80     public cUnit mul(cUnit units) {
81         cUnit temp = (cUnit) clone();
82         temp.setPoints(this.getPoints() * units.getPoints());
83
84         return temp;
85     }
86
87     public void mulI(cUnit units) {
88         setPoints(getPoints() * units.getPoints());
89     }
90
91     public cUnit div(double units) {
92         cUnit temp = (cUnit) clone();
93         temp.setUnits(this.getUnits() / units);
94
95         return temp;
96     }
97
98     public cUnit div(cUnit units) {
99         cUnit temp = (cUnit) clone();
100         temp.setPoints(this.getPoints() / units.getPoints());
101
102         return temp;
103     }
104
105     public void divI(cUnit units) {
106         setPoints(getPoints() / units.getPoints());
107     }
108
109     public boolean equals(Object JavaDoc unit) {
110         if (unit instanceof cUnit) {
111             return (getPoints() == ((cUnit) unit).getPoints());
112         }
113
114         return false;
115     }
116
117     public Object JavaDoc clone() {
118         cUnit clone;
119
120         try {
121             clone = (cUnit) super.clone();
122         } catch (Exception JavaDoc e) {
123             System.err.println(e);
124
125             return null;
126         }
127
128         clone.setUnits(getPoints());
129
130         return clone;
131     }
132 }
133
Popular Tags