Package com.orsonpdf
Class Dictionary
- java.lang.Object
-
- com.orsonpdf.Dictionary
-
public class Dictionary extends java.lang.Object
A dictionary is a map and supports writing the bytes for the dictionary in the PDF syntax. The dictionary has an optionaltype
entry which is treated as a special case (to ensure it comes first in the output if it is specified).
-
-
Constructor Summary
Constructors Constructor Description Dictionary()
Creates a new instance with no type.Dictionary(java.lang.String type)
Creates a new dictionary with the specified type (which can benull
).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getType()
Returns the dictionary type.boolean
isEmpty()
Returnstrue
if the dictionary has no entries, andfalse
otherwise.void
put(java.lang.String key, java.lang.Object value)
Puts an entry in the dictionary.java.lang.Object
remove(java.lang.String key)
Removes an entry from the dictionary, returning the value that was stored previously.void
setType(java.lang.String type)
Sets the type (for example, "/Catalog").int
size()
Returns the number of items in the dictionary.byte[]
toPDFBytes()
Returns a byte array containing the ASCII encoding of the dictionary.java.lang.String
toPDFString()
Returns a string containing the PDF text describing the dictionary.
-
-
-
Field Detail
-
type
private java.lang.String type
The type entry. We treat this as a special case, because when a type is defined, we want it to appear first in the PDF output. Note that it can be set to null for some dictionaries.
-
map
private final java.util.Map<java.lang.String,java.lang.Object> map
Data storage.
-
-
Method Detail
-
getType
public java.lang.String getType()
Returns the dictionary type.- Returns:
- The dictionary type (possibly (
null
).
-
setType
public void setType(java.lang.String type)
Sets the type (for example, "/Catalog").- Parameters:
type
- the type (null
permitted).
-
isEmpty
public boolean isEmpty()
Returnstrue
if the dictionary has no entries, andfalse
otherwise.- Returns:
- A boolean.
- See Also:
size()
-
size
public int size()
Returns the number of items in the dictionary.- Returns:
- The number of items in the dictionary.
-
put
public void put(java.lang.String key, java.lang.Object value)
Puts an entry in the dictionary.- Parameters:
key
- the key.value
- the value.
-
remove
public java.lang.Object remove(java.lang.String key)
Removes an entry from the dictionary, returning the value that was stored previously.- Parameters:
key
- the key.- Returns:
- The value that was associated with the key.
-
toPDFBytes
public byte[] toPDFBytes()
Returns a byte array containing the ASCII encoding of the dictionary.- Returns:
- A byte array.
-
toPDFString
public java.lang.String toPDFString()
Returns a string containing the PDF text describing the dictionary. Note that this is a Java string, conversion to byte format happens elsewhere.- Returns:
- A string.
-
-