KickJava   Java API By Example, From Geeks To Geeks.

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


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

13 public class PdfBoolean
14     extends PdfObject {
15
16     /**
17        The Boolean value of this object.
18     */

19     protected boolean _b;
20
21     /**
22        A <code>PdfBoolean</code> object representing the Boolean
23        value <code>false</code>.
24      */

25     public static final PdfBoolean FALSE = new PdfBoolean(false);
26     
27     /**
28        A <code>PdfBoolean</code> object representing the Boolean
29        value <code>true</code>.
30      */

31     public static final PdfBoolean TRUE = new PdfBoolean(true);
32
33     /**
34        Constructs a Boolean object representing a Boolean value.
35        <b>In most cases there is no need to create a new instance
36        of this class, and the {@link #valueOf(boolean)
37        valueOf(boolean)} method is preferred.</b>
38        @param b the Boolean value.
39      */

40     public PdfBoolean(boolean b) {
41         _b = b;
42     }
43
44     public boolean equals(Object JavaDoc obj) {
45
46         if ( (obj == null) || ( !(obj instanceof PdfBoolean) ) ) {
47             return false;
48         }
49
50         return (_b == ((PdfBoolean)obj)._b);
51     }
52
53     /**
54        Returns the Boolean value of this object.
55        @return the Boolean value.
56      */

57     public boolean getBoolean() {
58         return _b;
59     }
60
61     public int hashCode() {
62         return _b ? 1231 : 1237;
63     }
64
65     /**
66        Returns a <code>PdfBoolean</code> object with the specified
67        value. This method is normally preferable to {@link
68        #PdfBoolean(boolean) PdfBoolean(boolean)} because it avoids
69        allocating a new instance.
70        @param b the Boolean value.
71        @return the Boolean object.
72      */

73     public static PdfBoolean valueOf(boolean b) {
74         return b ? PdfBoolean.TRUE : PdfBoolean.FALSE;
75     }
76
77     protected int writePdf(PdfWriter w, boolean spacing) throws IOException {
78
79         DataOutputStream dos = w.getDataOutputStream();
80         
81         int count;
82         
83         if (spacing) {
84             dos.write(' ');
85             count = 1;
86         } else {
87             count = 0;
88         }
89         
90         if (_b) {
91             dos.writeBytes("true");
92             return count + 4;
93         } else {
94             dos.writeBytes("false");
95             return count + 5;
96         }
97
98     }
99
100 }
101
Popular Tags