KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > math > CQuantity


1 // Copyright (c) 1997 Per M.A. Bothner.
2
// This is free software; for terms and warranty disclaimer see ./COPYING.
3

4 package gnu.math;
5 import java.io.*;
6
7 /** General Cartesian Complex quantity. */
8
9 public class CQuantity extends Quantity implements Externalizable
10 {
11   Complex num;
12   Unit unt;
13
14   public CQuantity (Complex num, Unit unit)
15   {
16     this.num = num;
17     this.unt = unit;
18   }
19
20   public CQuantity (RealNum real, RealNum imag, Unit unit)
21   {
22     this.num = new CComplex (real, imag);
23     this.unt = unit;
24   }
25
26   public Complex number() { return num; }
27   public Unit unit() { return unt; }
28
29   public boolean isExact () { return num.isExact(); }
30
31   public boolean isZero () { return num.isZero(); }
32
33   /**
34    * @serialData Write the complex value (using writeObject) followed
35    * by the Unit (also using writeUnit).
36    */

37
38   public void writeExternal(ObjectOutput out) throws IOException
39   {
40     out.writeObject(num);
41     out.writeObject(unt);
42   }
43
44   public void readExternal(ObjectInput in)
45     throws IOException, ClassNotFoundException JavaDoc
46   {
47     num = (Complex) in.readObject();
48     unt = (Unit) in.readObject();
49   }
50 }
51
Popular Tags