KickJava   Java API By Example, From Geeks To Geeks.

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


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 integer object.
11    @author Nassib Nassar
12 */

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

19     protected int _n;
20
21         /**
22            A <code>PdfInteger</code> object representing the int value
23            <code>0</code>.
24          */

25         public static final PdfInteger ZERO = new PdfInteger(0);
26
27     /**
28        Constructs an integer object representing an int value.
29        @param n the int value.
30      */

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