01: /*
02: Copyright (C) Etymon Systems, Inc. <http://www.etymon.com/>
03: */
04:
05: package com.etymon.pjx;
06:
07: import java.io.*;
08:
09: /**
10: Represents the PDF null object.
11: @author Nassib Nassar
12: */
13: public class PdfNull extends PdfObject {
14:
15: /**
16: A <code>PdfNull</code> object representing the null value.
17: */
18: public static final PdfNull NULL = new PdfNull();
19:
20: /**
21: Constructs a null object. <b>In most cases there is no
22: need to create a new instance of this class, and the {@link
23: #valueOf() valueOf()} method is preferred.</b>
24: */
25: public PdfNull() {
26: }
27:
28: /**
29: Checks whether an object represents a null value. Note
30: that this method differs slightly from {@link
31: #equals(Object) equals(Object)} in that this returns
32: <code>true</code> when called with a <code>null</code>
33: value. This method is useful for examining PDF objects, in
34: which <code>null</code> and <code>PdfNull</code> should
35: normally be considered equivalent. For example, if a
36: dictionary value or an indirect object is
37: <code>PdfNull</code>, it is equivalent to the object not
38: existing.
39: @param obj the object to examine.
40: @return <code>true</code> if the object is either
41: <code>null</code> or an instance of <code>PdfNull</code>;
42: otherwise <code>false</code> is returned.
43: */
44: public static boolean isNull(Object obj) {
45:
46: return ((obj == null) || (obj instanceof PdfNull));
47:
48: }
49:
50: public boolean equals(Object obj) {
51:
52: if ((obj == null) || (!(obj instanceof PdfNull))) {
53: return false;
54: }
55:
56: return true;
57: }
58:
59: public int hashCode() {
60: return 4321;
61: }
62:
63: /**
64: Returns a <code>PdfNull</code> object. This method is
65: normally preferable to {@link #PdfNull() PdfNull()} because
66: it avoids allocating a new instance.
67: @return the null object.
68: */
69: public static PdfNull valueOf() {
70: return PdfNull.NULL;
71: }
72:
73: protected int writePdf(PdfWriter w, boolean spacing)
74: 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: }
|