KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > stefanochizzolini > clown > objects > PdfArray


1 /*
2   Copyright 2006 Stefano Chizzolini. http://clown.stefanochizzolini.it
3
4   Contributors:
5     * Stefano Chizzolini (original code developer, info@stefanochizzolini.it):
6       contributed code is Copyright 2006 by Stefano Chizzolini.
7
8   This file should be part of the source code distribution of "PDF Clown library"
9   (the Program): see the accompanying README files for more info.
10
11   This Program is free software; you can redistribute it and/or modify it under
12   the terms of the GNU General Public License as published by the Free Software
13   Foundation; either version 2 of the License, or (at your option) any later version.
14
15   This Program is distributed in the hope that it will be useful, but WITHOUT ANY
16   WARRANTY, either expressed or implied; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more details.
18
19   You should have received a copy of the GNU General Public License along with this
20   Program (see README files); if not, go to the GNU website (http://www.gnu.org/).
21
22   Redistribution and use, with or without modification, are permitted provided that such
23   redistributions retain the above copyright notice, license and disclaimer, along with
24   this list of conditions.
25 */

26
27 package it.stefanochizzolini.clown.objects;
28
29 import it.stefanochizzolini.clown.bytes.IOutputStream;
30 import it.stefanochizzolini.clown.files.File;
31 import it.stefanochizzolini.clown.util.NotImplementedException;
32
33 import java.util.ArrayList JavaDoc;
34 import java.util.Collection JavaDoc;
35 import java.util.Iterator JavaDoc;
36 import java.util.List JavaDoc;
37 import java.util.ListIterator JavaDoc;
38
39 /**
40   PDF array object.
41 */

42 public class PdfArray
43   extends PdfDirectObject
44   implements List JavaDoc<PdfDirectObject>
45 {
46   // <class>
47
// <dynamic>
48
// <fields>
49
private ArrayList JavaDoc<PdfDirectObject> items;
50   // </fields>
51

52   // <constructors>
53
public PdfArray(
54     )
55   {items = new ArrayList JavaDoc<PdfDirectObject>();}
56
57   public PdfArray(
58     int capacity
59     )
60   {items = new ArrayList JavaDoc<PdfDirectObject>(capacity);}
61
62   public PdfArray(
63     PdfDirectObject[] items
64     )
65   {
66     this(items.length);
67
68     for(PdfDirectObject item : items)
69     {this.items.add(item);}
70   }
71   // </constructors>
72

73   // <interface>
74
// <public>
75
@Override JavaDoc
76   public Object JavaDoc clone(
77     File context
78     )
79   {
80     //TODO:IMPL redefine to support real cloning (current implementation is prone to object slicing hazard)!!!
81
PdfArray clone = new PdfArray(items.size());
82
83     for(PdfDirectObject item : items)
84     {clone.add((PdfDirectObject)item.clone(context));}
85
86     return clone;
87   }
88
89   @Override JavaDoc
90   public String JavaDoc toPdf(
91     )
92   {throw new NotImplementedException();}
93
94   @Override JavaDoc
95   public String JavaDoc toString(
96     )
97   {
98     StringBuilder JavaDoc buffer = new StringBuilder JavaDoc();
99
100     // Begin.
101
buffer.append("[ ");
102
103     // Elements.
104
for(PdfDirectObject item : items)
105     {buffer.append(item.toString() + " ");}
106
107     // End.
108
buffer.append("]");
109
110     return buffer.toString();
111   }
112
113   // <List>
114
public void add(
115     int index,
116     PdfDirectObject object
117     )
118   {items.add(index,object);}
119
120   public boolean addAll(
121     int index,
122     Collection JavaDoc<? extends PdfDirectObject> objects
123     )
124   {return items.addAll(index,objects);}
125
126   public PdfDirectObject get(
127     int index
128     )
129   {return items.get(index);}
130
131   public int indexOf(
132     Object JavaDoc object
133     )
134   {return items.indexOf(object);}
135
136   public int lastIndexOf(
137     Object JavaDoc object
138     )
139   {return items.lastIndexOf(object);}
140
141   public ListIterator JavaDoc<PdfDirectObject> listIterator(
142     )
143   {return items.listIterator();}
144
145   public ListIterator JavaDoc<PdfDirectObject> listIterator(
146     int index
147     )
148   {return items.listIterator(index);}
149
150   public PdfDirectObject remove(
151     int index
152     )
153   {return items.remove(index);}
154
155   public PdfDirectObject set(
156     int index,
157     PdfDirectObject object
158     )
159   {return items.set(index,object);}
160
161   public List JavaDoc<PdfDirectObject> subList(
162     int fromIndex,
163     int toIndex
164     )
165   {return items.subList(fromIndex,toIndex);}
166
167   // <Collection>
168
public boolean add(
169     PdfDirectObject object
170     )
171   {return items.add(object);}
172
173   public boolean addAll(
174     Collection JavaDoc<? extends PdfDirectObject> objects
175     )
176   {return items.addAll(objects);}
177
178   public void clear(
179     )
180   {items.clear();}
181
182   public boolean contains(
183     Object JavaDoc object
184     )
185   {return items.contains(object);}
186
187   public boolean containsAll(
188     Collection JavaDoc<?> objects
189     )
190   {return items.containsAll(objects);}
191
192   public boolean equals(
193     PdfDirectObject object
194     )
195   {throw new NotImplementedException();}
196
197   public int hashCode(
198     )
199   {return items.hashCode();}
200
201   public boolean isEmpty(
202     )
203   {return items.isEmpty();}
204
205   public boolean remove(
206     Object JavaDoc object
207     )
208   {return items.remove(object);}
209
210   public boolean removeAll(
211     Collection JavaDoc<?> objects
212     )
213   {return items.removeAll(objects);}
214
215   public boolean retainAll(
216     Collection JavaDoc<?> objects
217     )
218   {return items.retainAll(objects);}
219
220   public int size(
221     )
222   {return items.size();}
223
224   public PdfDirectObject[] toArray(
225     )
226   {return (PdfDirectObject[])items.toArray();}
227
228   public <PdfDirectObject> PdfDirectObject[] toArray(
229     PdfDirectObject[] objects
230     )
231   {return (PdfDirectObject[])items.toArray(objects);}
232
233   // <Iterable>
234
public Iterator JavaDoc<PdfDirectObject> iterator(
235     )
236   {return items.iterator();}
237   // </Iterable>
238
// </Collection>
239
// </List>
240
// </public>
241

242   // <internal>
243
int writeTo(
244     IOutputStream stream
245     )
246   {
247     // Begin.
248
int size = stream.write("[ ");
249
250     // Elements.
251
for(
252       PdfDirectObject item : items
253       )
254     {
255       size += item.writeTo(stream);
256       size += stream.write(" ");
257     }
258
259     // End.
260
size += stream.write("]");
261
262     return size;
263   }
264   // </internal>
265
// </interface>
266
// </dynamic>
267
// </class>
268
}
Popular Tags