Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximPlusov committed Apr 9, 2024
1 parent 783db2f commit 6ca2b9b
Show file tree
Hide file tree
Showing 23 changed files with 24 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ public String getTrapped() {
@Override
public Map<String, String> getCustomValues() {
if (info != null && info.getType() == COSObjType.COS_DICT) {
Map<String, String> res = new TreeMap<>();
Set<ASAtom> keys = new TreeSet<>(info.getKeySet());
Arrays.asList(predefinedKeys).forEach(keys::remove);
Map<String, String> res = new TreeMap<>();
for (ASAtom key : keys) {
res.put(key.getValue(), key == ASAtom.TRAPPED ? info.getNameKeyStringValue(key) : info.getStringKey(key));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ public MetadataFixerResult saveDocumentIncremental(final MetadataFixerResultImpl

@Override
public int removeFiltersForAllMetadataObjects() {
int res = 0;
List<COSObject> objects = this.document.getDocument().getObjectsByType(ASAtom.METADATA);

List<COSStream> metas = new ArrayList<>();
Expand All @@ -179,6 +178,7 @@ public int removeFiltersForAllMetadataObjects() {
LOGGER.log(Level.SEVERE, "Found non-stream Metadata dictionary.");
}
}
int res = 0;
for (COSStream stream : metas) {
if (stream.getFilters().size() > 0) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ public List<org.verapdf.model.operator.Operator> operatorsFromTokens(List<Object
PDResourcesHandler resourcesHandler, GraphicState inheritedGraphicState,
StructureElementAccessObject structureElementAccessObject, COSObject parentStructElem,
String parentsTags, boolean isRealContent) {
List<org.verapdf.model.operator.Operator> result = new ArrayList<>();
List<COSBase> arguments = new ArrayList<>();
this.isLastParsedContainsTransparency = false;
OperatorParser parser = new OperatorParser(inheritedGraphicState, structureElementAccessObject, resourcesHandler,
parentStructElem, parentsTags, isRealContent);

List<org.verapdf.model.operator.Operator> result = new ArrayList<>();
List<COSBase> arguments = new ArrayList<>();
for (Object rawToken : rawTokens) {
if (rawToken instanceof COSBase) {
arguments.add((COSBase) rawToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class OperatorParser {

private final Deque<TransparencyGraphicsState> transparencyGraphicStateStack = new ArrayDeque<>();
private final Stack<GFOpMarkedContent> markedContentStack = new Stack<>();
private final Set<Long> mcidSet = new HashSet<Long>();
private final Set<Long> mcidSet = new HashSet<>();
private final StructureElementAccessObject structureElementAccessObject;
private final TransparencyGraphicsState transparencyGraphicState = new TransparencyGraphicsState();
private final COSObject parentStructElem;
Expand Down Expand Up @@ -403,7 +403,7 @@ void parseOperator(List<org.verapdf.model.operator.Operator> processedOperators,
this.graphicState);
break;

// COMPABILITY
// COMPATIBILITY
case Operators.BX:
processedOperators.add(new GFOp_BX(arguments));
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.verapdf.cos.*;
import org.verapdf.gf.model.impl.containers.StaticContainers;
import org.verapdf.gf.model.impl.pd.GFPDDocument;
import org.verapdf.gf.model.impl.pd.util.XMPChecker;
import org.verapdf.gf.model.impl.sa.GFSAPDFDocument;
import org.verapdf.gf.model.tools.FileSpecificationKeysHelper;
import org.verapdf.model.baselayer.Object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,14 @@ private List<CosFilter> getFilters() {
if (filters == null || filters.getFilters().isEmpty()) {
return Collections.emptyList();
}
List<CosFilter> result = new ArrayList<>();

COSObject decodeParmsObject = this.baseObject.getKey(ASAtom.DECODE_PARMS);
COSBase decodeParms = null;
if (decodeParmsObject != null) {
decodeParms = decodeParmsObject.get();
}

List<CosFilter> result = new ArrayList<>();
if (filters.getFilters().size() == 1) {
if (decodeParms instanceof COSArray) {
decodeParms = decodeParms.at(0).get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public Boolean getisValidPDFA12() {
if (this.stream == null) {
return Boolean.TRUE;
}
boolean retVal = false;
saveStaticContainersState();
boolean retVal = false;
try (InputStream unfilteredStream = stream.getData(COSStream.FilterFlags.DECODE)) {
retVal = isValidPdfaStream(unfilteredStream, PDFAFlavour.PDFA_1_B);
if (!retVal) {
Expand All @@ -100,8 +100,8 @@ public Boolean getisValidPDFA124() {
if (this.stream == null) {
return Boolean.TRUE;
}
boolean retVal = false;
saveStaticContainersState();
boolean retVal = false;
try (InputStream unfilteredStream = stream.getData(COSStream.FilterFlags.DECODE)) {
retVal = isValidPdfaStream(unfilteredStream, PDFAFlavour.PDFA_1_B);
if (!retVal) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.verapdf.gf.model.factory.fonts.FontFactory;
import org.verapdf.gf.model.factory.operators.GraphicState;
import org.verapdf.gf.model.factory.operators.RenderingMode;
import org.verapdf.gf.model.impl.containers.StaticContainers;
import org.verapdf.gf.model.impl.operator.base.GFOperator;
import org.verapdf.gf.model.impl.operator.markedcontent.GFOpMarkedContent;
import org.verapdf.gf.model.impl.pd.util.PDResourcesHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class GFOutputIntents extends GenericModelObject implements OutputIntents

public static final String OUTPUT_INTENTS = "outputIntents";

List<org.verapdf.pd.PDOutputIntent> outInts;
private final List<org.verapdf.pd.PDOutputIntent> outInts;

public GFOutputIntents(List<org.verapdf.pd.PDOutputIntent> outInts) {
super(OUTPUT_INTENTS_TYPE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ private List<PDColorSpace> getColorSpace() {
}
}
}
List<PDColorSpace> colorSpaces = new ArrayList<>(GFPDObject.MAX_NUMBER_OF_ELEMENTS);
if (colorSpaceName != null) {
colorSpace = resources.getColorSpace(colorSpaceName);
}
if (colorSpace != null) {
List<PDColorSpace> colorSpaces = new ArrayList<>(GFPDObject.MAX_NUMBER_OF_ELEMENTS);
colorSpaces.add(org.verapdf.gf.model.factory.colors.ColorSpaceFactory.getColorSpace(colorSpace));
return Collections.unmodifiableList(colorSpaces);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.verapdf.cos.COSObjType;
import org.verapdf.cos.COSObject;
import org.verapdf.cos.COSString;
import org.verapdf.gf.model.impl.containers.StaticContainers;
import org.verapdf.gf.model.impl.cos.GFCosLang;
import org.verapdf.gf.model.impl.pd.actions.GFPDAction;
import org.verapdf.gf.model.impl.pd.actions.GFPDAdditionalActions;
Expand Down Expand Up @@ -105,8 +104,7 @@ public class GFPDDocument extends GFPDObject implements PDDocument {

public GFPDDocument(org.verapdf.pd.PDDocument document) {
super(document, PD_DOCUMENT_TYPE);
PDCatalog catalog;
catalog = document.getCatalog();
PDCatalog catalog = document.getCatalog();
this.catalog = catalog;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ private List<XMPPackage> getXMPPackage() {
if (isMainMetadata) {
xmp.add(new AXLMainXMPPackage(metadata, true, flavour));
} else if (flavour == null || flavour.getPart() != PDFAFlavour.Specification.ISO_19005_1) {
VeraPDFXMPNode mainExtensionNode = null;
try (InputStream mainStream = mainMetadata != null ? mainMetadata.getStream() : null) {
VeraPDFXMPNode mainExtensionNode = null;
if (mainStream != null) {
VeraPDFMeta mainMeta = VeraPDFMeta.parse(mainStream);
mainExtensionNode = mainMeta.getExtensionSchemasNode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ private List<PDContentStream> parseContentStream() {
StaticContainers.getTransparencyVisitedContentStreams().clear();
List<PDContentStream> pdContentStreams = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS);
org.verapdf.pd.PDPage page = (org.verapdf.pd.PDPage) this.simplePDObject;
GFPDContentStream pdContentStream;
if (page.getContent() != null) {
PDResourcesHandler resourcesHandler = PDResourcesHandler.getInstance(page.getResources(), page.isInheritedResources());
GFPDContentStream pdContentStream;
if (PDFAFlavour.IsoStandardSeries.ISO_14289 != StaticContainers.getFlavour().getPart().getSeries() &&
PDFAFlavour.SpecificationFamily.WCAG != StaticContainers.getFlavour().getPart().getFamily()) {
pdContentStream = new GFPDContentStream(page.getContent(), resourcesHandler, null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,13 @@ private List<CosLang> getLang() {

@Override
public String getparentLang() {
COSString baseLang = null;
Set<COSKey> keys = new HashSet<>();
COSKey key = this.simplePDObject.getObject().getObjectKey();
if (key != null) {
keys.add(key);
}
org.verapdf.pd.structure.PDStructElem parent = ((org.verapdf.pd.structure.PDStructElem) this.simplePDObject).getParent();
COSString baseLang = null;
while (baseLang == null && parent != null) {
key = parent.getObject().getObjectKey();
if (keys.contains(key)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
public class GFTransparencyColorSpace extends GenericModelObject implements TransparencyColorSpace {

protected PDColorSpace colorSpace;
protected final PDColorSpace colorSpace;

public static final String TRANSPARENCY_COLOR_SPACE_TYPE = "TransparencyColorSpace";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class GFSENote extends GFPDStructElem implements SENote {

public static final String NOTE_STRUCTURE_ELEMENT_TYPE = "SENote";

public String noteID;
public final String noteID;

public boolean hasDuplicateNoteID;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ public Boolean getisArtifact() {

protected Boolean hasParentWithStandardType(String standardType) {
TaggedPDFRoleMapHelper taggedPDFRoleMapHelper = StaticResources.getRoleMapHelper();
Set<COSKey> keys = new HashSet<>();
if (parentStructElem != null && taggedPDFRoleMapHelper != null) {
PDStructElem structElem = new PDStructElem(parentStructElem);
Set<COSKey> keys = new HashSet<>();
while (structElem != null) {
if (standardType.equals(PDStructElem.getStructureElementStandardType(structElem))) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ private List<SEContentItem> getContentItem() {
if (operators == null) {
return Collections.emptyList();
}
int markedContentIndex;
Stack<Integer> markedContentStack = new Stack<>();
List<SEContentItem> list = new ArrayList<>();
for (int i = 0; i < operators.size(); i++) {
Expand All @@ -91,7 +90,7 @@ private List<SEContentItem> getContentItem() {
markedContentStack.push(i);
} else if (GFOp_EMC.OP_EMC_TYPE.equals(type)) {
if (!markedContentStack.empty()) {
markedContentIndex = markedContentStack.pop();
int markedContentIndex = markedContentStack.pop();
if (markedContentStack.empty()) {
list.add(new GFSEMarkedContent((GFOpMarkedContent)operators.get(markedContentIndex),
operators.subList(markedContentIndex + 1, i + 1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
public abstract class GFSESimpleContentItem extends GFSEContentItem implements SESimpleContentItem {

protected GFSEGroupedContent groupedContent;
protected final GFSEGroupedContent groupedContent;

public GFSESimpleContentItem(String objectType, GFSEGroupedContent groupedContent) {
super(objectType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ public boolean isContainsTransparency() {
}

private void parseContentStream() {
List<PDContentStream> contentStreams = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS);
org.verapdf.pd.patterns.PDTilingPattern pattern = (org.verapdf.pd.patterns.PDTilingPattern) this.simplePDObject;
GFPDContentStream contentStream = new GFPDContentStream(pattern, this.resourcesHandler, inheritedGraphicState,
new StructureElementAccessObject(this.simpleCOSObject));
this.containsTransparency |= contentStream.isContainsTransparency();
List<PDContentStream> contentStreams = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS);
contentStreams.add(contentStream);
this.contentStreams = contentStreams;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class GFPDSignature extends GFPDObject implements PDSignature {
public static final String CONTENTS = "Contents";
public static final String REFERENCE = "Reference";

protected COSString contents;
protected final COSString contents;
protected long signatureOffset = -1;

public GFPDSignature(org.verapdf.pd.PDSignature pdSignature, COSObject signatureReference) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ public double getTranslateY() {

public BoundingBox transformBoundingBox(BoundingBox boundingBox) {
List<Double> xCoordinates = new ArrayList<>(4);
List<Double> yCoordinates = new ArrayList<>(4);
xCoordinates.add(transformX(boundingBox.getLeftX(), boundingBox.getBottomY()));
xCoordinates.add(transformX(boundingBox.getRightX(), boundingBox.getBottomY()));
xCoordinates.add(transformX(boundingBox.getLeftX(), boundingBox.getTopY()));
xCoordinates.add(transformX(boundingBox.getRightX(), boundingBox.getTopY()));
List<Double> yCoordinates = new ArrayList<>(4);
yCoordinates.add(transformY(boundingBox.getLeftX(), boundingBox.getBottomY()));
yCoordinates.add(transformY(boundingBox.getRightX(), boundingBox.getBottomY()));
yCoordinates.add(transformY(boundingBox.getLeftX(), boundingBox.getTopY()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public List<? extends Object> getLinkedObjects(String link) {

private List<SAAnnotation> parseAnnotations() {
List<PDAnnotation> annots = pdPage.getAnnotations();
if (annots.size() > 0) {
if (!annots.isEmpty()) {
List<SAAnnotation> res = new ArrayList<>(annots.size());
for (PDAnnotation annot : annots) {
res.add(GFSAAnnotation.createAnnot(annot, pdPage));
Expand Down

0 comments on commit 6ca2b9b

Please sign in to comment.