KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > etymon > pjx > PdfFloat


1 /*
2   Copyright (C) Etymon Systems, Inc. <http://www.etymon.com/>
3 */

4
5 package com.etymon.pjx;
6
7 import java.io.*;
8
9 /**
10    Represents the PDF real object.
11    @author Nassib Nassar
12 */

13 public class PdfFloat
14     extends PdfNumber {
15
16     /**
17        The float value of this object.
18     */

19     protected float _n;
20     
21     /**
22        Constructs a real object representing a float value.
23        @param n the float value.
24      */

25     public PdfFloat(float n) {
26         _n = n;
27     }
28
29     public boolean equals(Object JavaDoc obj) {
30
31         if ( (obj == null) || ( !(obj instanceof PdfFloat) ) ) {
32             return false;
33         }
34
35         return (_n == ((PdfFloat)obj)._n);
36     }
37
38     public int getInt() {
39         return (int)_n;
40     }
41
42     public long getLong() {
43         return (long)_n;
44     }
45
46     public float getFloat() {
47         return _n;
48     }
49
50     public int hashCode() {
51         return Float.floatToIntBits(_n);
52     }
53
54     protected int writePdf(PdfWriter w, boolean spacing) throws IOException {
55
56         DataOutputStream dos = w.getDataOutputStream();
57             
58         int count;
59         
60         if (spacing) {
61             dos.write(' ');
62             count = 1;
63         } else {
64             count = 0;
65         }
66         
67         String JavaDoc s = Float.toString(_n);
68         dos.writeBytes(s);
69         return count + s.length();
70     }
71
72 }
73
Popular Tags