Class COSIncrement

java.lang.Object
org.apache.pdfbox.cos.COSIncrement
All Implemented Interfaces:
Iterable<COSBase>

public class COSIncrement extends Object implements Iterable<COSBase>
A COSIncrement starts at a given COSUpdateInfo to collect updates, that have been made to a COSDocument and therefore should be added to it´s next increment.
See Also:
  • Field Details

    • objects

      private final Set<COSBase> objects
      Contains the COSBases, that shall be added to the increment at top level.
    • excluded

      private final Set<COSBase> excluded
      Contains the direct COSBases, that are either contained written directly by structures contained in objects or that must be excluded from being written as indirect COSObjects for other reasons.
    • processedObjects

      private final Set<COSObject> processedObjects
      Contains all COSObjects, that have already been processed by this COSIncrement and shall not be processed again.
    • incrementOrigin

      private final COSUpdateInfo incrementOrigin
      Contains the COSUpdateInfo that this COSIncrement creates an increment for.
    • initialized

      private boolean initialized
      Whether this COSIncrement has already been determined, or must still be evaluated.
  • Constructor Details

  • Method Details

    • collect

      private boolean collect(COSBase base)
      Collect all updates made to the given COSBase and it's contained structures.
      This shall forward all COSUpdateInfo objects to the proper specialized collection methods.
      Parameters:
      base - The COSBase updates shall be collected for.
      Returns:
      Returns true, if the COSBase represents a direct child structure, that would require it´s parent to be updated instead.
      See Also:
    • collect

      private boolean collect(COSDictionary dictionary)
      Collect all updates made to the given COSDictionary and it's contained structures.
      Parameters:
      dictionary - The COSDictionary updates shall be collected for.
      Returns:
      Returns true, if the COSDictionary represents a direct child structure, that would require it´s parent to be updated instead.
    • collect

      private boolean collect(COSArray array)
      Collect all updates made to the given COSArray and it's contained structures.
      Parameters:
      array - The COSDictionary updates shall be collected for.
      Returns:
      Returns true, if the COSArray´s elements changed. A COSArray shall always be treated as a direct structure, that would require it´s parent to be updated instead.
    • collect

      private boolean collect(COSObject object)
      Collect all updates made to the given COSObject and it's contained structures.
      Parameters:
      object - The COSObject updates shall be collected for.
      Returns:
      Always returns false. COSObjects by definition are indirect and shall never cause a parent structure to be updated.
    • contains

      public boolean contains(COSBase base)
      Returns true, if the given COSBase is already known to and has been processed by this COSIncrement.
      Parameters:
      base - The COSBase to check.
      Returns:
      true, if the given COSBase is already known to and has been processed by this COSIncrement.
      See Also:
    • updateDifferentOrigin

      private void updateDifferentOrigin(COSUpdateState updateState)
      Check whether the given COSUpdateState´s COSDocumentState differs from the COSIncrement´s known incrementOrigin.
      Should that be the case, the COSUpdateState originates from another COSDocument and must be added to the COSIncrement, hence call COSUpdateState.update().
      Parameters:
      updateState - The COSUpdateState that shall be updated, if it's originating from another COSDocument.
      See Also:
    • add

      private void add(COSBase object)
      The given object and actual {COSBase}s shall be part of the increment and must be added to objects, if possible.
      null values shall be skipped.
      Parameters:
      object - The COSBase to add to objects.
      See Also:
    • addProcessedObject

      private void addProcessedObject(COSObject base)
      The given COSObject has been processed, or is being processed. It shall be added to processedObjects to skip it, should it be encountered again.
      null values shall be ignored.
      Parameters:
      base - The COSObject to add to processedObjects.
      See Also:
    • exclude

      public COSIncrement exclude(COSBase... base)
      The given COSBases are not fit for inclusion in an increment and shall be added to excluded.
      null values shall be ignored.
      Parameters:
      base - The COSBases to add to excluded.
      Returns:
      The COSIncrement itself, to allow method chaining.
      See Also:
    • isExcluded

      private boolean isExcluded(COSBase base)
      Returns true, if the given COSBase has been excluded from the increment, and hence is contained in excluded.
      Parameters:
      base - The COSBase to check for exclusion.
      Returns:
      true, if the given COSBase has been excluded from the increment, and hence is contained in excluded.
      See Also:
    • getObjects

      public Set<COSBase> getObjects()
      Returns all indirect COSBases, that shall be written to an increment as top level COSObjects.
      Calling this method will cause the increment to be initialized.
      Returns:
      All indirect COSBases, that shall be written to an increment as top level COSObjects.
      See Also:
    • iterator

      public Iterator<COSBase> iterator()
      Return an iterator for the determined objects contained in this COSIncrement.
      Specified by:
      iterator in interface Iterable<COSBase>
      Returns:
      An iterator for the determined objects contained in this COSIncrement.