1 4 5 package com.etymon.pjx; 6 7 import java.io.*; 8 import java.util.*; 9 10 14 public class PdfArray 15 extends PdfObject { 16 17 20 protected List _a; 21 22 26 protected PdfArray() { } 28 29 35 public PdfArray(List a) { 36 _a = Collections.unmodifiableList(new ArrayList(a)); 37 } 38 39 protected PdfObject filterContents(PdfObjectFilter f) throws PdfFormatException { 40 List newList = new ArrayList(_a.size()); 41 for (Iterator t = _a.iterator(); t.hasNext(); ) { 42 Object obj = t.next(); 43 if ( !(obj instanceof PdfObject) ) { 44 throw new PdfFormatException("Array element is not a PDF object."); 45 } 46 47 PdfObject objF = ((PdfObject)obj).filter(f); 48 49 if (objF != null) { 50 newList.add(objF); 51 } 52 } 53 return f.postFilter(new PdfArray(newList)); 54 } 55 56 public boolean equals(Object obj) { 57 58 if ( (obj == null) || ( !(obj instanceof PdfArray) ) ) { 59 return false; 60 } 61 62 return _a.equals( ((PdfArray)obj)._a ); 63 } 64 65 70 public List getList() { 71 return _a; 72 } 73 74 public int hashCode() { 75 return _a.hashCode(); 76 } 77 78 89 protected static PdfArray wrap(List a) { 90 PdfArray pa = new PdfArray(); 91 pa._a = Collections.unmodifiableList(a); 92 return pa; 93 } 94 95 protected int writePdf(PdfWriter w, boolean spacing) throws IOException { 96 97 DataOutputStream dos = w.getDataOutputStream(); 98 99 int count = 2; 101 dos.write('['); 102 103 boolean first = true; 104 for (Iterator p = _a.iterator(); p.hasNext(); ) { 105 PdfObject obj = (PdfObject)p.next(); 106 if (first) { 107 count += obj.writePdf(w, false); 108 first = false; 109 } else { 110 count += obj.writePdf(w, true); 111 } 112 } 113 114 dos.write(']'); 115 116 return count; 117 } 118 119 } 120 | Popular Tags |