Class COSArray

java.lang.Object
org.sejda.sambox.cos.COSBase
org.sejda.sambox.cos.COSArray
All Implemented Interfaces:
Iterable<COSBase>, Collection<COSBase>, List<COSBase>, COSObjectable

public class COSArray extends COSBase implements List<COSBase>
An array of PDFBase objects as part of the PDF document.
Author:
Ben Litchfield
  • Constructor Details

    • COSArray

      public COSArray()
    • COSArray

      public COSArray(COSBase... items)
  • Method Details

    • add

      public boolean add(COSObjectable object)
      Add an object to the array
      Parameters:
      object - The object to add to the array.
      See Also:
    • add

      public boolean add(COSBase object)
      Specified by:
      add in interface Collection<COSBase>
      Specified by:
      add in interface List<COSBase>
    • add

      public void add(int index, COSObjectable object)
      Add an object at the index location and push the rest to the right.
      Parameters:
      index - The index to add at.
      object - The object to add at that index.
      See Also:
    • add

      public void add(int index, COSBase object)
      Specified by:
      add in interface List<COSBase>
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<COSBase>
      Specified by:
      clear in interface List<COSBase>
    • removeAll

      public boolean removeAll(Collection<?> objectsList)
      Specified by:
      removeAll in interface Collection<COSBase>
      Specified by:
      removeAll in interface List<COSBase>
    • retainAll

      public boolean retainAll(Collection<?> objectsList)
      Specified by:
      retainAll in interface Collection<COSBase>
      Specified by:
      retainAll in interface List<COSBase>
    • addAll

      public boolean addAll(Collection<? extends COSBase> objectsList)
      Specified by:
      addAll in interface Collection<COSBase>
      Specified by:
      addAll in interface List<COSBase>
    • addAll

      public boolean addAll(COSArray objectList)
      This will add all objects to this array.
      Parameters:
      objectList - The objects to add.
    • addAll

      public boolean addAll(int i, Collection<? extends COSBase> objectList)
      Specified by:
      addAll in interface List<COSBase>
    • set

      public COSBase set(int index, COSBase object)
      Specified by:
      set in interface List<COSBase>
    • set

      public void set(int index, COSObjectable object)
      Set an object at a specific index.
      Parameters:
      index - zero based index into array.
      object - The object to set.
    • getObject

      public COSBase getObject(int index)
      This will get an object from the array. This will dereference the object. If the object is COSNull then null will be returned.
      Parameters:
      index - The index into the array to get the object.
      Returns:
      The object at the requested index.
    • getObject

      public <T extends COSBase> T getObject(int index, Class<T> clazz)
      This will get an object from the array. This will dereference the object. If the type is not compatible, null is returned
      Parameters:
      index -
      clazz -
      Returns:
      The object that matches the key and the type or null.
    • get

      public COSBase get(int index)
      Get an object from the array. This will NOT derefernce the COS object.
      Specified by:
      get in interface List<COSBase>
      Parameters:
      index - The index into the array to get the object.
      Returns:
      The object at the requested index.
      See Also:
    • getInt

      public int getInt(int index)
      Get the value of the array as an integer.
      Parameters:
      index - The index into the list.
      Returns:
      The value at that index or -1 if it is null.
    • getInt

      public int getInt(int index, int defaultValue)
      Get the value of the array as an integer, return the default if it does not exist.
      Parameters:
      index - The value of the array.
      defaultValue - The value to return if the value is null.
      Returns:
      The value at the index or the defaultValue.
    • getName

      public String getName(int index)
      Get the value of the array as a string.
      Parameters:
      index - The index into the array.
      Returns:
      The name converted to a string or null if it does not exist.
    • getName

      public String getName(int index, String defaultValue)
      Get an entry in the array that is expected to be a COSName.
      Parameters:
      index - The index into the array.
      defaultValue - The value to return if it is null.
      Returns:
      The value at the index or defaultValue if none is found.
    • setString

      public void setString(int index, String string)
      Set the value in the array as a string.
      Parameters:
      index - The index into the array.
      string - The string to set in the array.
    • getString

      public String getString(int index)
      Get the value of the array as a string.
      Parameters:
      index - The index into the array.
      Returns:
      The string or null if it does not exist.
    • getString

      public String getString(int index, String defaultValue)
      Get an entry in the array that is expected to be a COSName.
      Parameters:
      index - The index into the array.
      defaultValue - The value to return if it is null.
      Returns:
      The value at the index or defaultValue if none is found.
    • size

      public int size()
      Specified by:
      size in interface Collection<COSBase>
      Specified by:
      size in interface List<COSBase>
    • remove

      public COSBase remove(int i)
      Specified by:
      remove in interface List<COSBase>
    • removeLast

      public COSBase removeLast()
      Removes the last object of the array
      Returns:
      the removed object or null if the array was empty
    • remove

      public boolean remove(Object o)
      Specified by:
      remove in interface Collection<COSBase>
      Specified by:
      remove in interface List<COSBase>
    • removeObject

      public boolean removeObject(COSBase o)
      This will remove an element from the array. This method will also remove a reference to the object.
      Parameters:
      o - The object to remove.
      Returns:
      true if the object was removed, false otherwise
    • iterator

      public Iterator<COSBase> iterator()
      Specified by:
      iterator in interface Collection<COSBase>
      Specified by:
      iterator in interface Iterable<COSBase>
      Specified by:
      iterator in interface List<COSBase>
    • listIterator

      public ListIterator<COSBase> listIterator()
      Specified by:
      listIterator in interface List<COSBase>
    • listIterator

      public ListIterator<COSBase> listIterator(int index)
      Specified by:
      listIterator in interface List<COSBase>
    • lastIndexOf

      public int lastIndexOf(Object o)
      Specified by:
      lastIndexOf in interface List<COSBase>
    • indexOf

      public int indexOf(Object object)
      Specified by:
      indexOf in interface List<COSBase>
    • indexOfObject

      public int indexOfObject(COSBase object)
      This will return the index of the entry or -1 if it is not found. This method will also find references to indirect objects.
      Parameters:
      object - The object to search for.
      Returns:
      The index of the object or -1.
    • growToSize

      public COSArray growToSize(int size)
      This will add null values until the size of the array is at least as large as the parameter. If the array is already larger than the parameter then nothing is done.
      Parameters:
      size - The desired size of the array.
    • growToSize

      public COSArray growToSize(int size, COSBase object)
      This will add the object until the size of the array is at least as large as the parameter. If the array is already larger than the parameter then nothing is done.
      Parameters:
      size - The desired size of the array.
      object - The object to fill the array with.
    • trimToSize

      public COSArray trimToSize(int size)
      trims the array to the given size
      Parameters:
      size -
    • toFloatArray

      public float[] toFloatArray()
      This will take an COSArray of numbers and convert it to a float[].
      Returns:
      This COSArray as an array of float numbers.
    • setFloatArray

      public void setFloatArray(float[] value)
      Clear the current contents of the COSArray and set it with the float[].
      Parameters:
      value - The new value of the float array.
    • toList

      public List<? extends COSBase> toList()
      Returns:
      the COSArray as List
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<COSBase>
      Specified by:
      isEmpty in interface List<COSBase>
    • toArray

      public Object[] toArray()
      Specified by:
      toArray in interface Collection<COSBase>
      Specified by:
      toArray in interface List<COSBase>
    • toArray

      public <T> T[] toArray(T[] a)
      Specified by:
      toArray in interface Collection<COSBase>
      Specified by:
      toArray in interface List<COSBase>
    • contains

      public boolean contains(Object o)
      Specified by:
      contains in interface Collection<COSBase>
      Specified by:
      contains in interface List<COSBase>
    • containsAll

      public boolean containsAll(Collection<?> c)
      Specified by:
      containsAll in interface Collection<COSBase>
      Specified by:
      containsAll in interface List<COSBase>
    • subList

      public List<COSBase> subList(int fromIndex, int toIndex)
      Specified by:
      subList in interface List<COSBase>
    • accept

      public void accept(COSVisitor visitor) throws IOException
      Description copied from class: COSBase
      Visitor pattern for the COS model objects
      Specified by:
      accept in class COSBase
      Throws:
      IOException
    • duplicate

      public COSArray duplicate()
      Returns:
      a new COSArray that is a duplicate of this
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in interface Collection<COSBase>
      Specified by:
      equals in interface List<COSBase>
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Collection<COSBase>
      Specified by:
      hashCode in interface List<COSBase>
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object