Package com.orsonpdf

Class Dictionary

java.lang.Object
com.orsonpdf.Dictionary

public class Dictionary extends Object
A dictionary is a map and supports writing the bytes for the dictionary in the PDF syntax. The dictionary has an optional type entry which is treated as a special case (to ensure it comes first in the output if it is specified).
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Map<String,Object>
    Data storage.
    private String
    The type entry.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance with no type.
    Creates a new dictionary with the specified type (which can be null).
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the dictionary type.
    boolean
    Returns true if the dictionary has no entries, and false otherwise.
    void
    put(String key, Object value)
    Puts an entry in the dictionary.
    Removes an entry from the dictionary, returning the value that was stored previously.
    void
    Sets the type (for example, "/Catalog").
    int
    Returns the number of items in the dictionary.
    byte[]
    Returns a byte array containing the ASCII encoding of the dictionary.
    Returns a string containing the PDF text describing the dictionary.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • type

      private 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 Map<String,Object> map
      Data storage.
  • Constructor Details

    • Dictionary

      public Dictionary()
      Creates a new instance with no type.
    • Dictionary

      public Dictionary(String type)
      Creates a new dictionary with the specified type (which can be null).
      Parameters:
      type - the type value (for example, "/Catalog").
  • Method Details

    • getType

      public String getType()
      Returns the dictionary type.
      Returns:
      The dictionary type (possibly (null).
    • setType

      public void setType(String type)
      Sets the type (for example, "/Catalog").
      Parameters:
      type - the type (null permitted).
    • isEmpty

      public boolean isEmpty()
      Returns true if the dictionary has no entries, and false otherwise.
      Returns:
      A boolean.
      See Also:
    • size

      public int size()
      Returns the number of items in the dictionary.
      Returns:
      The number of items in the dictionary.
    • put

      public void put(String key, Object value)
      Puts an entry in the dictionary.
      Parameters:
      key - the key.
      value - the value.
    • remove

      public Object remove(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 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.