class AcroFormUtils {

    public static void mergeDefaults(PDAcroForm mergeThis, PDAcroForm intoThis) {
        if (!intoThis.isNeedAppearances() && mergeThis.isNeedAppearances()) {
            intoThis.setNeedAppearances(true);
        }
        String da = mergeThis.getDefaultAppearance();
        if (isBlank(intoThis.getDefaultAppearance()) && !isBlank(da)) {
            intoThis.setDefaultAppearance(da);
        }
        int quadding = mergeThis.getCOSObject().getInt(COSName.Q);
        if ((quadding >= 0 && quadding <= 2) && !intoThis.getCOSObject().containsKey(COSName.Q)) {
            intoThis.setQuadding(quadding);
        }
        final COSDictionary formResources = ofNullable(
                intoThis.getCOSObject().getDictionaryObject(COSName.DR, COSDictionary.class))
                        .orElseGet(COSDictionary::new);
        ofNullable(mergeThis.getCOSObject().getDictionaryObject(COSName.DR, COSDictionary.class)).ifPresent(dr -> {
            for (COSName currentKey : dr.keySet()) {
                ofNullable(dr.getDictionaryObject(currentKey)).ifPresent(value -> {
                    if (value instanceof COSDictionary) {
                        mergeResourceDictionaryValue(formResources, (COSDictionary) value, currentKey);
                    } else if (value instanceof COSArray) {
                        mergeResourceArrayValue(formResources, (COSArray) value, currentKey);
                    } else {
                        LOG.warn("Unsupported resource dictionary type {}", value);
                    }
                });
            }
        });
        intoThis.getCOSObject().setItem(COSName.DR, formResources);
        LOG.debug("Merged AcroForm dictionary");
    }

    private  AcroFormUtils();

}