org.apache.pdfbox.pdmodel.common

## Class COSArrayList<E>

- java.lang.Object
- - org.apache.pdfbox.pdmodel.common.COSArrayList<E>

Type Parameters:
  `E` - Element type.

All Implemented Interfaces:
  Iterable<E>, Collection<E>, List<E>

    public class COSArrayList<E>
    extends Object
    implements List<E>

This is an implementation of a List that will sync its contents to a COSArray.

Author:
  Ben Litchfield

### Constructor Summary

Constructors
Constructor and Description
`COSArrayList()` Default constructor.
`COSArrayList(COSDictionary dictionary, COSName dictionaryKey)` This constructor is to be used if the array doesn't exist, but is to be created and added to the parent dictionary as soon as the first element is added to the array.
`COSArrayList(E actualObject, COSBase item, COSDictionary dictionary, COSName dictionaryKey)` This is a really special constructor.
`COSArrayList(List<E> actualList, COSArray cosArray)` Create the COSArrayList specifying the List and the backing COSArray.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`boolean` `add(E o)`
`void` `add(int index, E element)`
`boolean` `addAll(Collection<? extends E> c)`
`boolean` `addAll(int index, Collection<? extends E> c)`
`void` `clear()`
`boolean` `contains(Object o)`
`boolean` `containsAll(Collection<?> c)`
`static COSArray` `converterToCOSArray(List<?> cosObjectableList)` This will convert a list of COSObjectables to an array list of COSBase objects.
`boolean` `equals(Object o)`
`E` `get(int index)`
`int` `hashCode()`
`int` `indexOf(Object o)`
`boolean` `isEmpty()`
`Iterator<E>` `iterator()`
`int` `lastIndexOf(Object o)`
`ListIterator<E>` `listIterator()`
`ListIterator<E>` `listIterator(int index)`
`E` `remove(int index)`
`boolean` `remove(Object o)`
`boolean` `removeAll(Collection<?> c)`
`boolean` `retainAll(Collection<?> c)`
`E` `set(int index, E element)`
`int` `size()`
`List<E>` `subList(int fromIndex, int toIndex)`
`Object[]` `toArray()`
`<X> X[]` `toArray(X[] a)`
`COSArray` `toList()` This will return then underlying COSArray.
`String` `toString()`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface java.util.List

`replaceAll, sort, spliterator`

### Methods inherited from interface java.util.Collection

`parallelStream, removeIf, stream`

### Methods inherited from interface java.lang.Iterable

`forEach`

### Constructor Detail

#### COSArrayList

    public COSArrayList()

Default constructor.

#### COSArrayList

    public COSArrayList(List<E> actualList,
                        COSArray cosArray)

Create the COSArrayList specifying the List and the backing COSArray.

User of this constructor need to ensure that the entries in the List and the backing COSArray are matching i.e. the COSObject of the List entry is included in the COSArray.

If the number of entries in the List and the COSArray differ it is assumed that the List has been filtered. In that case the COSArrayList shall only be used for reading purposes and no longer for updating.

Parameters:
  `actualList` - The list of standard java objects
  `cosArray` - The COS array object to sync to.

#### COSArrayList

    public COSArrayList(COSDictionary dictionary,
                        COSName dictionaryKey)

This constructor is to be used if the array doesn't exist, but is to be created and added to the parent dictionary as soon as the first element is added to the array.

Parameters:
  `dictionary` - The dictionary that holds the item, and will hold the array if an item is added.
  `dictionaryKey` - The key into the dictionary to set the item.

#### COSArrayList

    public COSArrayList(E actualObject,
                        COSBase item,
                        COSDictionary dictionary,
                        COSName dictionaryKey)

This is a really special constructor. Sometimes the PDF spec says that a dictionary entry can either be a single item or an array of those items. But in the PDModel interface we really just want to always return a java.util.List. In the case were we get the list and never modify it we don't want to convert to COSArray and put one element, unless we append to the list. So here we are going to create this object with a single item instead of a list, but allow more items to be added and then converted to an array.

Parameters:
  `actualObject` - The PDModel object.
  `item` - The COS Model object.
  `dictionary` - The dictionary that holds the item, and will hold the array if an item is added.
  `dictionaryKey` - The key into the dictionary to set the item.

### Method Detail

#### size

    public int size()

Specified by:
  `size` in interface `Collection<E>`
Specified by:
  `size` in interface `List<E>`

#### isEmpty

    public boolean isEmpty()

Specified by:
  `isEmpty` in interface `Collection<E>`
Specified by:
  `isEmpty` in interface `List<E>`

#### contains

    public boolean contains(Object o)

Specified by:
  `contains` in interface `Collection<E>`
Specified by:
  `contains` in interface `List<E>`

#### iterator

    public Iterator<E> iterator()

Specified by:
  `iterator` in interface `Iterable<E>`
Specified by:
  `iterator` in interface `Collection<E>`
Specified by:
  `iterator` in interface `List<E>`

#### toArray

    public Object[] toArray()

Specified by:
  `toArray` in interface `Collection<E>`
Specified by:
  `toArray` in interface `List<E>`

#### toArray

    public <X> X[] toArray(X[] a)

Specified by:
  `toArray` in interface `Collection<E>`
Specified by:
  `toArray` in interface `List<E>`

#### add

    public boolean add(E o)

Specified by:
  `add` in interface `Collection<E>`
Specified by:
  `add` in interface `List<E>`

#### remove

    public boolean remove(Object o)

Specified by:
  `remove` in interface `Collection<E>`
Specified by:
  `remove` in interface `List<E>`

#### containsAll

    public boolean containsAll(Collection<?> c)

Specified by:
  `containsAll` in interface `Collection<E>`
Specified by:
  `containsAll` in interface `List<E>`

#### addAll

    public boolean addAll(Collection<? extends E> c)

Specified by:
  `addAll` in interface `Collection<E>`
Specified by:
  `addAll` in interface `List<E>`

#### addAll

    public boolean addAll(int index,
                          Collection<? extends E> c)

Specified by:
  `addAll` in interface `List<E>`

#### converterToCOSArray

    public static COSArray converterToCOSArray(List<?> cosObjectableList)

This will convert a list of COSObjectables to an array list of COSBase objects.

Parameters:
  `cosObjectableList` - A list of COSObjectable.
Returns:
  A list of COSBase.
Throws:
  `IllegalArgumentException` - if an object type is not supported for conversion to a COSBase object.

#### removeAll

    public boolean removeAll(Collection<?> c)

Specified by:
  `removeAll` in interface `Collection<E>`
Specified by:
  `removeAll` in interface `List<E>`

#### retainAll

    public boolean retainAll(Collection<?> c)

Specified by:
  `retainAll` in interface `Collection<E>`
Specified by:
  `retainAll` in interface `List<E>`

#### clear

    public void clear()

Specified by:
  `clear` in interface `Collection<E>`
Specified by:
  `clear` in interface `List<E>`

#### equals

    public boolean equals(Object o)

Specified by:
  `equals` in interface `Collection<E>`
Specified by:
  `equals` in interface `List<E>`
Overrides:
  `equals` in class `Object`

#### hashCode

    public int hashCode()

Specified by:
  `hashCode` in interface `Collection<E>`
Specified by:
  `hashCode` in interface `List<E>`
Overrides:
  `hashCode` in class `Object`

#### get

    public E get(int index)

Specified by:
  `get` in interface `List<E>`

#### set

    public E set(int index,
                 E element)

Specified by:
  `set` in interface `List<E>`

#### add

    public void add(int index,
                    E element)

Specified by:
  `add` in interface `List<E>`

#### remove

    public E remove(int index)

Specified by:
  `remove` in interface `List<E>`

#### indexOf

    public int indexOf(Object o)

Specified by:
  `indexOf` in interface `List<E>`

#### lastIndexOf

    public int lastIndexOf(Object o)

Specified by:
  `lastIndexOf` in interface `List<E>`

#### listIterator

    public ListIterator<E> listIterator()

Specified by:
  `listIterator` in interface `List<E>`

#### listIterator

    public ListIterator<E> listIterator(int index)

Specified by:
  `listIterator` in interface `List<E>`

#### subList

    public List<E> subList(int fromIndex,
                           int toIndex)

Specified by:
  `subList` in interface `List<E>`

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

#### toList

    public COSArray toList()

This will return then underlying COSArray.

Returns:
  the COSArray