1 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.Collection ; 34 import java.util.HashMap ; 35 import java.util.Map ; 36 import java.util.Set ; 37 38 41 public class PdfDictionary 42 extends PdfDirectObject 43 implements Map <PdfName,PdfDirectObject> 44 { 45 private HashMap <PdfName,PdfDirectObject> entries; 49 51 public PdfDictionary( 53 ) 54 {entries = new HashMap <PdfName,PdfDirectObject>();} 55 56 public PdfDictionary( 57 int capacity 58 ) 59 {entries = new HashMap <PdfName,PdfDirectObject>(capacity);} 60 61 public PdfDictionary( 62 PdfName[] keys, 63 PdfDirectObject[] values 64 ) 65 { 66 this(values.length); 67 68 for( 69 int index = 0; 70 index < values.length; 71 index++ 72 ) 73 { 74 put( 75 keys[index], 76 values[index] 77 ); 78 } 79 } 80 82 @Override  85 public Object clone( 86 File context 87 ) 88 { 89 PdfDictionary clone = new PdfDictionary(entries.size()); 91 92 for( 93 Map.Entry <PdfName,PdfDirectObject> entry : entries.entrySet() 94 ) 95 { 96 clone.put( 97 entry.getKey(), 98 (PdfDirectObject)entry.getValue().clone(context) 99 ); 100 } 101 102 return clone; 103 } 104 105 108 public PdfName getKey( 109 PdfDirectObject value 110 ) 111 { 112 123 for( 124 Map.Entry <PdfName,PdfDirectObject> entry : entries.entrySet() 125 ) 126 { 127 if(entry.getValue().equals(value)) 128 return entry.getKey(); } 130 131 return null; } 133 134 @Override  135 public String toPdf( 136 ) 137 {throw new NotImplementedException();} 138 139 @Override  140 public String toString( 141 ) 142 { 143 StringBuilder buffer = new StringBuilder (); 144 145 buffer.append("<< "); 147 148 for( 150 Map.Entry <PdfName,PdfDirectObject> entry : entries.entrySet() 151 ) 152 { 153 buffer.append(entry.getKey().toString() + " "); 156 157 buffer.append(entry.getValue().toString() + " "); 159 } 160 161 buffer.append(">>"); 163 164 return buffer.toString(); 165 } 166 167 public void clear( 169 ) 170 {entries.clear();} 171 172 public boolean containsKey( 173 Object key 174 ) 175 {return entries.containsKey(key);} 176 177 public boolean containsValue( 178 Object value 179 ) 180 {return entries.containsValue(value);} 181 182 public Set <Map.Entry <PdfName,PdfDirectObject>> entrySet( 183 ) 184 {return entries.entrySet();} 185 186 public boolean equals( 187 Object object 188 ) 189 {throw new NotImplementedException();} 190 191 public PdfDirectObject get( 192 Object key 193 ) 194 {return entries.get(key);} 195 196 public int hashCode( 197 ) 198 {return entries.hashCode();} 199 200 public boolean isEmpty( 201 ) 202 {return entries.isEmpty();} 203 204 public Set <PdfName> keySet( 205 ) 206 {return entries.keySet();} 207 208 public PdfDirectObject put( 209 PdfName key, 210 PdfDirectObject value 211 ) 212 {return entries.put(key,value);} 213 214 public void putAll( 215 Map <? extends PdfName,? extends PdfDirectObject> entries 216 ) 217 {this.entries.putAll(entries);} 218 219 public PdfDirectObject remove( 220 Object key 221 ) 222 {return entries.remove(key);} 223 224 public int size( 225 ) 226 {return entries.size();} 227 228 public Collection <PdfDirectObject> values( 229 ) 230 {return entries.values();} 231 234 239 @Override  240 public int writeTo( 241 IOutputStream stream 242 ) 243 { 244 int size = stream.write("<< "); 246 247 for( 249 Map.Entry <PdfName,PdfDirectObject> entry : entries.entrySet() 250 ) 251 { 252 size += entry.getKey().writeTo(stream); 255 size += stream.write(" "); 256 257 size += entry.getValue().writeTo(stream); 259 size += stream.write(" "); 260 } 261 262 size += stream.write(">>"); 264 265 return size; 266 } 267 } | Popular Tags |