KickJava   Java API By Example, From Geeks To Geeks.

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


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

13 public class PdfNull
14     extends PdfObject {
15
16     /**
17        A <code>PdfNull</code> object representing the null value.
18      */

19         public static final PdfNull NULL = new PdfNull();
20     
21     /**
22        Constructs a null object. <b>In most cases there is no
23        need to create a new instance of this class, and the {@link
24        #valueOf() valueOf()} method is preferred.</b>
25      */

26     public PdfNull() {
27     }
28
29     /**
30        Checks whether an object represents a null value. Note
31        that this method differs slightly from {@link
32        #equals(Object) equals(Object)} in that this returns
33        <code>true</code> when called with a <code>null</code>
34        value. This method is useful for examining PDF objects, in
35        which <code>null</code> and <code>PdfNull</code> should
36        normally be considered equivalent. For example, if a
37        dictionary value or an indirect object is
38        <code>PdfNull</code>, it is equivalent to the object not
39        existing.
40        @param obj the object to examine.
41        @return <code>true</code> if the object is either
42        <code>null</code> or an instance of <code>PdfNull</code>;
43        otherwise <code>false</code> is returned.
44      */

45     public static boolean isNull(Object JavaDoc obj) {
46
47         return ( (obj == null) || (obj instanceof PdfNull) );
48         
49     }
50     
51     public boolean equals(Object JavaDoc obj) {
52
53         if ( (obj == null) || ( !(obj instanceof PdfNull) ) ) {
54             return false;
55         }
56
57         return true;
58     }
59
60     public int hashCode() {
61         return 4321;
62     }
63
64     /**
65        Returns a <code>PdfNull</code> object. This method is
66        normally preferable to {@link #PdfNull() PdfNull()} because
67        it avoids allocating a new instance.
68        @return the null object.
69      */

70     public static PdfNull valueOf() {
71         return PdfNull.NULL;
72     }
73
74     protected int writePdf(PdfWriter w, boolean spacing) throws IOException {
75
76         DataOutputStream dos = w.getDataOutputStream();
77         
78         int count;
79
80         if (spacing) {
81             dos.write(' ');
82             count = 1;
83         } else {
84             count = 0;
85         }
86
87         dos.writeBytes("null");
88         return count + 4;
89     }
90
91 }
92
Popular Tags