package org.verapdf.model.impl.pb.cos;

import org.apache.pdfbox.cos.COSArray;
import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.cos.COSString;
import org.verapdf.model.coslayer.CosTrailer;

/**
 * Created by Evgeniy Muravitskiy on 5/1/15.
 * <p>
 *     Trailer of the document. It has the same behavior as the PBCosDict.
 * </p>
 */
public class PBCosTrailer extends PBCosDict implements CosTrailer {

    private COSDictionary linearizedDictionary = null;
    private CosTrailer firstTrailer = null;
    private Long length = null;

    public PBCosTrailer(COSDictionary pdfBoxObject) {
        super(pdfBoxObject);
        setType("CosTrailer");
    }

    public PBCosTrailer(COSDictionary mainTrailer, COSDictionary firstTrailer, COSDictionary linearizedDictionary, Long length) {
        super(mainTrailer);
        this.firstTrailer = new PBCosTrailer(firstTrailer);
        this.linearizedDictionary = linearizedDictionary;
        this.length = length;
    }

    public String getid1() {
        return getPartOfID(0);
    }

    public String getid2() {
        return getPartOfID(1);
    }

    private String getPartOfID(int index) {
        COSArray ids = (COSArray) ((COSDictionary) baseObject).getItem("ID");

        if (ids != null && ids.size() > index) {
            if (ids.get(index) instanceof COSString) {
                return new String(((COSString) ids.get(index)).getBytes());
            } else {
                // TODO : discuss about this case
                throw new IllegalArgumentException("ID not conforming defined type for ID.");
            }
        } else {
            return null;
        }
    }

    // TODO : need to support of this feature
    public Boolean getisLinearized() {
        return !(baseObject == firstTrailer || linearizedDictionary == null);
    }

    public Boolean getisEncrypted() {
        return ((COSDictionary) baseObject).getItem("Encrypt") != null;
    }

    @Override
    public Boolean getdoFirstLastTrailerIDsMatch() {
        return getid1().equals(firstTrailer.getid1()) && getid2().equals(firstTrailer.getid2());
    }
}

@@ -185,296 +185,609 @@
 del.
-cos
+base
 layer.
-CosTrailer;%0A%0A/**%0A * Created by Evgeniy Muravitskiy on 5/1/15.%0A * %3Cp%3E%0A *     Trailer of the document. It has the same behavior as the PBCosDict.%0A * %3C/p%3E%0A */%0Apublic class PBCosTrailer extends PBCosDict implements CosTrailer %7B%0A%0A    private COSDictionary linearizedDictionary = null;
+*;%0Aimport org.verapdf.model.baselayer.Object;%0Aimport org.verapdf.model.coslayer.CosIndirect;%0Aimport org.verapdf.model.coslayer.CosTrailer;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0A/**%0A * Trailer of the document.%0A *%0A * @author Evgeniy Muravitskiy%0A */%0Apublic class PBCosTrailer extends PBCosDict implements CosTrailer %7B%0A%0A    private final String CATALOG = %22Catalog%22;%0A    /** if document is linearized its must have dictionary of linearization%0A     */%0A    private COSDictionary linearizedDictionary = null;%0A    /** if document is linearized first trailer is differ from last%0A     */
 %0A   
@@ -823,24 +823,63 @@
 ler = null;%0A
+    /** length of the document%0A     */%0A
     private 
@@ -1325,32 +1325,95 @@
  length;%0A    %7D%0A%0A
+    /**%0A     * @return first part of ID if its present%0A     */%0A
     public Strin
@@ -1455,32 +1455,96 @@
 OfID(0);%0A    %7D%0A%0A
+    /**%0A     * @return second part of ID if its present%0A     */%0A
     public Strin
@@ -2131,24 +2131,98 @@
    %7D%0A    %7D%0A%0A
+    /**%0A     * @return true if the current document is linearized%0A     */%0A
     // TODO 
@@ -2371,32 +2371,105 @@
 = null);%0A    %7D%0A%0A
+    /**%0A     * @return true if the current document is encrypted%0A     */%0A
     public Boole
@@ -2565,24 +2565,103 @@
 ull;%0A    %7D%0A%0A
+    /**%0A     * @return true if ID of first and last trailers are match%0A     */%0A
     @Overrid
@@ -2817,11 +2817,587 @@
 );%0A    %7D
+%0A%0A    @Override%0A    public List%3C? extends Object%3E getLinkedObjects(String link) %7B%0A        List%3C? extends Object%3E list;%0A        switch (link) %7B%0A            case CATALOG:%0A                list = getCatalog();%0A                break;%0A            default:%0A                list = super.getLinkedObjects(link);%0A                break;%0A        %7D%0A        return list;%0A    %7D%0A%0A    private List%3CCosIndirect%3E getCatalog() %7B%0A        List%3CCosIndirect%3E catalog = new ArrayList%3C%3E(1);%0A        catalog.add((CosIndirect) ((COSDictionary) baseObject).getItem(CATALOG));%0A        return catalog;%0A    %7D
 %0A%7D%0A

Add link for catalog from trailer. Add javadoc for PBCosTrailer