From 5aeb03dd7e9b12dc52fec8538a3bb015e68dddba Mon Sep 17 00:00:00 2001 From: Maxim Date: Fri, 8 Dec 2023 00:31:53 +0300 Subject: [PATCH] Refactoring --- .../wcag/algorithms/entities/AnnotationNode.java | 3 +++ .../algorithms/entities/AttributesDictionary.java | 2 ++ .../verapdf/wcag/algorithms/entities/BaseObject.java | 2 ++ .../verapdf/wcag/algorithms/entities/Document.java | 10 ++++++++-- .../org/verapdf/wcag/algorithms/entities/INode.java | 2 -- .../org/verapdf/wcag/algorithms/entities/ITree.java | 1 + .../org/verapdf/wcag/algorithms/entities/Page.java | 2 ++ .../wcag/algorithms/entities/RepeatedCharacters.java | 4 ++-- .../wcag/algorithms/entities/SemanticNode.java | 4 ++-- .../wcag/algorithms/entities/SemanticTextNode.java | 2 +- .../wcag/algorithms/entities/SemanticTree.java | 2 ++ .../wcag/algorithms/entities/content/InfoChunk.java | 7 ------- .../wcag/algorithms/entities/content/LineChunk.java | 9 ++++++--- .../wcag/algorithms/entities/content/TextChunk.java | 1 + .../wcag/algorithms/entities/content/TextColumn.java | 2 +- .../wcag/algorithms/entities/content/TextLine.java | 3 ++- .../algorithms/entities/geometry/BoundingBox.java | 4 +--- .../entities/geometry/MultiBoundingBox.java | 3 +++ .../wcag/algorithms/entities/geometry/Vertex.java | 2 ++ .../wcag/algorithms/entities/tables/Table.java | 2 +- .../entities/tables/TableBorderBuilder.java | 5 +++-- .../wcag/algorithms/entities/tables/TableRow.java | 2 +- .../entities/tables/tableBorders/TableBorder.java | 1 + .../entities/tables/tableBorders/TableBorderRow.java | 4 ++-- .../AccumulatedNodeSemanticChecker.java | 2 -- .../semanticalgorithms/ContrastRatioChecker.java | 2 -- .../consumers/AccumulatedNodeConsumer.java | 5 +++-- .../consumers/ClusterTableConsumer.java | 9 +++++---- .../consumers/ContrastRatioConsumer.java | 1 + .../consumers/HeadingCaptionConsumer.java | 3 ++- .../consumers/LinesPreprocessingConsumer.java | 1 + .../consumers/ListDetectionConsumer.java | 11 ++++++----- .../SemanticDocumentPostprocessingConsumer.java | 3 +-- .../SemanticDocumentPreprocessingConsumer.java | 4 +++- .../consumers/TOCDetectionConsumer.java | 2 ++ .../consumers/TableBorderConsumer.java | 5 +++-- .../semanticalgorithms/consumers/TableChecker.java | 1 + .../semanticalgorithms/tables/TableCluster.java | 7 ++++--- .../tables/TableRecognitionArea.java | 2 +- .../semanticalgorithms/tables/TableRecognizer.java | 2 +- .../semanticalgorithms/utils/ChunksMergeUtils.java | 2 +- .../semanticalgorithms/utils/ContextUtils.java | 2 ++ .../semanticalgorithms/utils/ListLabelsUtils.java | 5 ++--- .../semanticalgorithms/utils/ListUtils.java | 2 +- .../semanticalgorithms/utils/NodeUtils.java | 1 - .../semanticalgorithms/utils/TableUtils.java | 4 ++-- .../ArabicNumbersListLabelsDetectionAlgorithm.java | 2 +- .../LettersListLabelsDetectionAlgorithm.java | 6 ++++-- .../consumers/ContrastRatioConsumerTests.java | 4 ++-- .../wcag/algorithms/entities/JsonAttributes.java | 4 ++-- .../wcag/algorithms/entities/NodeIdResolver.java | 6 ++---- .../semanticalgorithms/ContrastRatioCheckerTests.java | 1 - 52 files changed, 102 insertions(+), 76 deletions(-) diff --git a/src/main/java/org/verapdf/wcag/algorithms/entities/AnnotationNode.java b/src/main/java/org/verapdf/wcag/algorithms/entities/AnnotationNode.java index 34434848..76959b22 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/entities/AnnotationNode.java +++ b/src/main/java/org/verapdf/wcag/algorithms/entities/AnnotationNode.java @@ -16,14 +16,17 @@ public AnnotationNode(String annotationType, BoundingBox boundingBox, Integer de this.destinationObjectKeyNumber = destinationObjectKeyNumber; } + @Override public String getAnnotationType() { return this.annotationType; } + @Override public Integer getDestinationPageNumber() { return this.destinationPageNumber; } + @Override public Integer getDestinationObjectKeyNumber() { return destinationObjectKeyNumber; } diff --git a/src/main/java/org/verapdf/wcag/algorithms/entities/AttributesDictionary.java b/src/main/java/org/verapdf/wcag/algorithms/entities/AttributesDictionary.java index a4179ee5..86bf4621 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/entities/AttributesDictionary.java +++ b/src/main/java/org/verapdf/wcag/algorithms/entities/AttributesDictionary.java @@ -23,10 +23,12 @@ public void setColSpan(long colSpan) { this.colSpan = colSpan; } + @Override public long getRowSpan() { return rowSpan; } + @Override public long getColSpan() { return colSpan; } diff --git a/src/main/java/org/verapdf/wcag/algorithms/entities/BaseObject.java b/src/main/java/org/verapdf/wcag/algorithms/entities/BaseObject.java index 5006889f..2de551ca 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/entities/BaseObject.java +++ b/src/main/java/org/verapdf/wcag/algorithms/entities/BaseObject.java @@ -100,10 +100,12 @@ public void setRecognizedStructureId(Long id) { recognizedStructureId = id; } + @Override public double getWidth() { return boundingBox.getWidth(); } + @Override public double getHeight() { return boundingBox.getHeight(); } diff --git a/src/main/java/org/verapdf/wcag/algorithms/entities/Document.java b/src/main/java/org/verapdf/wcag/algorithms/entities/Document.java index bc6c2b54..6203b2aa 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/entities/Document.java +++ b/src/main/java/org/verapdf/wcag/algorithms/entities/Document.java @@ -9,18 +9,20 @@ public class Document implements IDocument { - private ITree tree; - private List pages; + private final ITree tree; + private final List pages; public Document(ITree tree) { this.tree = tree; pages = new LinkedList<>(); } + @Override public ITree getTree(){ return tree; } + @Override public List getArtifacts(Integer pageNumber) { if (pageNumber < pages.size()) { return pages.get(pageNumber).getArtifacts(); @@ -28,14 +30,17 @@ public List getArtifacts(Integer pageNumber) { return Collections.emptyList(); } + @Override public List getPages() { return pages; } + @Override public int getNumberOfPages() { return pages.size(); } + @Override public IPage getPage(Integer pageNumber) { if (pageNumber < pages.size()) { return pages.get(pageNumber); @@ -43,6 +48,7 @@ public IPage getPage(Integer pageNumber) { return null; } + @Override public List getArtifacts() { List artifacts = new ArrayList<>(); for (IPage page : pages) { diff --git a/src/main/java/org/verapdf/wcag/algorithms/entities/INode.java b/src/main/java/org/verapdf/wcag/algorithms/entities/INode.java index 47e5c499..e3fdb9cb 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/entities/INode.java +++ b/src/main/java/org/verapdf/wcag/algorithms/entities/INode.java @@ -1,10 +1,8 @@ package org.verapdf.wcag.algorithms.entities; import org.verapdf.wcag.algorithms.entities.enums.SemanticType; -import org.verapdf.wcag.algorithms.entities.geometry.BoundingBox; import java.util.List; -import java.util.Set; public interface INode extends IObject { diff --git a/src/main/java/org/verapdf/wcag/algorithms/entities/ITree.java b/src/main/java/org/verapdf/wcag/algorithms/entities/ITree.java index fd9721b9..83cf3217 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/entities/ITree.java +++ b/src/main/java/org/verapdf/wcag/algorithms/entities/ITree.java @@ -6,6 +6,7 @@ public interface ITree extends Iterable { INode getRoot(); + @Override default Iterator iterator() { return new DFSTreeNodeIterator(getRoot()); } diff --git a/src/main/java/org/verapdf/wcag/algorithms/entities/Page.java b/src/main/java/org/verapdf/wcag/algorithms/entities/Page.java index 12258e34..afe73176 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/entities/Page.java +++ b/src/main/java/org/verapdf/wcag/algorithms/entities/Page.java @@ -17,10 +17,12 @@ public Page(int pageNumber, String pageLabel) { artifacts = new LinkedList<>(); } + @Override public List getArtifacts() { return artifacts; } + @Override public int getPageNumber() { return pageNumber; } diff --git a/src/main/java/org/verapdf/wcag/algorithms/entities/RepeatedCharacters.java b/src/main/java/org/verapdf/wcag/algorithms/entities/RepeatedCharacters.java index 61b92e6c..934a1802 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/entities/RepeatedCharacters.java +++ b/src/main/java/org/verapdf/wcag/algorithms/entities/RepeatedCharacters.java @@ -4,8 +4,8 @@ public class RepeatedCharacters { - private boolean nonSpace; - private Integer numberOfElements; + private final boolean nonSpace; + private final Integer numberOfElements; private BoundingBox boundingBox; public RepeatedCharacters(boolean nonSpace, Integer numberOfElements, BoundingBox boundingBox) { diff --git a/src/main/java/org/verapdf/wcag/algorithms/entities/SemanticNode.java b/src/main/java/org/verapdf/wcag/algorithms/entities/SemanticNode.java index 41fe3bcb..522a477d 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/entities/SemanticNode.java +++ b/src/main/java/org/verapdf/wcag/algorithms/entities/SemanticNode.java @@ -20,7 +20,7 @@ public class SemanticNode extends BaseObject implements INode { private boolean hasLowestDepthError = false; private IAttributesDictionary attributesDictionary; - public NodeInfo nodeInfo; + public final NodeInfo nodeInfo; public SemanticNode() { this((SemanticType)null); @@ -217,7 +217,7 @@ public boolean equals(Object o) { return Objects.equals(objectKeyNumber, that.objectKeyNumber) && Objects.equals(index, that.index) && Objects.equals(parent, that.parent) && - Objects.equals(initialSemanticType, that.initialSemanticType) && + initialSemanticType == that.initialSemanticType && depth == that.depth; } diff --git a/src/main/java/org/verapdf/wcag/algorithms/entities/SemanticTextNode.java b/src/main/java/org/verapdf/wcag/algorithms/entities/SemanticTextNode.java index 5caf5ae0..eb5a0484 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/entities/SemanticTextNode.java +++ b/src/main/java/org/verapdf/wcag/algorithms/entities/SemanticTextNode.java @@ -514,7 +514,7 @@ public int hashCode() { @Override public String toString() { - if (columns.size() == 0) { + if (columns.isEmpty()) { return this.getClass().getName() + "{}"; } StringBuilder result = new StringBuilder(this.getClass().getSimpleName()); diff --git a/src/main/java/org/verapdf/wcag/algorithms/entities/SemanticTree.java b/src/main/java/org/verapdf/wcag/algorithms/entities/SemanticTree.java index cb796a18..c87cf3f2 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/entities/SemanticTree.java +++ b/src/main/java/org/verapdf/wcag/algorithms/entities/SemanticTree.java @@ -10,10 +10,12 @@ public SemanticTree(INode root) { this.root = root; } + @Override public INode getRoot() { return root; } + @Override public Iterator iterator() { return new DFSTreeNodeIterator(this.getRoot()); } diff --git a/src/main/java/org/verapdf/wcag/algorithms/entities/content/InfoChunk.java b/src/main/java/org/verapdf/wcag/algorithms/entities/content/InfoChunk.java index c63f3792..089d9d2d 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/entities/content/InfoChunk.java +++ b/src/main/java/org/verapdf/wcag/algorithms/entities/content/InfoChunk.java @@ -3,8 +3,6 @@ import org.verapdf.wcag.algorithms.entities.BaseObject; import org.verapdf.wcag.algorithms.entities.geometry.BoundingBox; -import java.util.Objects; - public abstract class InfoChunk extends BaseObject implements IChunk { public InfoChunk() { @@ -16,11 +14,6 @@ public InfoChunk(BoundingBox bbox) { setBoundingBox(bbox); } - @Override - public int hashCode() { - return Objects.hashCode(getBoundingBox()); - } - @Override public boolean equals(Object o) { if (this == o) { diff --git a/src/main/java/org/verapdf/wcag/algorithms/entities/content/LineChunk.java b/src/main/java/org/verapdf/wcag/algorithms/entities/content/LineChunk.java index 5dd6689c..dfb7d1d4 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/entities/content/LineChunk.java +++ b/src/main/java/org/verapdf/wcag/algorithms/entities/content/LineChunk.java @@ -9,9 +9,9 @@ public class LineChunk extends InfoChunk { - public static int BUTT_CAP_STYLE = 0; - public static int ROUND_CAP_STYLE = 1; - public static int PROJECTING_SQUARE_CAP_STYLE = 2; + public static final int BUTT_CAP_STYLE = 0; + public static final int ROUND_CAP_STYLE = 1; + public static final int PROJECTING_SQUARE_CAP_STYLE = 2; private final Vertex start; private final Vertex end; @@ -74,12 +74,14 @@ public boolean isSquare() { return isSquare; } + @Override public double getWidth() { return width; } public static class HorizontalLineComparator implements Comparator { + @Override public int compare(LineChunk line1, LineChunk line2){ int res = Double.compare(line2.getCenterY(), line1.getCenterY()); if (res != 0) { @@ -91,6 +93,7 @@ public int compare(LineChunk line1, LineChunk line2){ public static class VerticalLineComparator implements Comparator { + @Override public int compare(LineChunk line1, LineChunk line2){ int res = Double.compare(line1.getCenterX(), line2.getCenterX()); if (res != 0) { diff --git a/src/main/java/org/verapdf/wcag/algorithms/entities/content/TextChunk.java b/src/main/java/org/verapdf/wcag/algorithms/entities/content/TextChunk.java index e76109ae..bc9cafd3 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/entities/content/TextChunk.java +++ b/src/main/java/org/verapdf/wcag/algorithms/entities/content/TextChunk.java @@ -58,6 +58,7 @@ public TextChunk(TextChunk chunk) { chunk.baseLine, chunk.fontColor, chunk.symbolEnds, chunk.slantDegree); } + @Override public String getValue() { return value; } diff --git a/src/main/java/org/verapdf/wcag/algorithms/entities/content/TextColumn.java b/src/main/java/org/verapdf/wcag/algorithms/entities/content/TextColumn.java index f8301a17..bb05e4b3 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/entities/content/TextColumn.java +++ b/src/main/java/org/verapdf/wcag/algorithms/entities/content/TextColumn.java @@ -153,7 +153,7 @@ public boolean hasOnlyOneBlock() { @Override public String toString() { - StringBuilder stringBuilder = new StringBuilder(""); + StringBuilder stringBuilder = new StringBuilder(); for (TextBlock textBlock : textBlocks) { stringBuilder.append(textBlock); } diff --git a/src/main/java/org/verapdf/wcag/algorithms/entities/content/TextLine.java b/src/main/java/org/verapdf/wcag/algorithms/entities/content/TextLine.java index ac28c5c4..a5abd912 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/entities/content/TextLine.java +++ b/src/main/java/org/verapdf/wcag/algorithms/entities/content/TextLine.java @@ -46,7 +46,7 @@ public TextChunk getLastTextChunk() { public TextChunk getLastNormalTextChunk() { for (int i = textChunks.size() - 2; i >= 0; i--) { TextChunk textChunk = textChunks.get(i); - if (TextFormat.NORMAL.equals(textChunk.getTextFormat())) { + if (TextFormat.NORMAL == textChunk.getTextFormat()) { return textChunk; } } @@ -69,6 +69,7 @@ public void add(TextLine line) { } } + @Override public String getValue() { if (textChunks.isEmpty()) { return ""; diff --git a/src/main/java/org/verapdf/wcag/algorithms/entities/geometry/BoundingBox.java b/src/main/java/org/verapdf/wcag/algorithms/entities/geometry/BoundingBox.java index 8bf3a7d4..a2e851ba 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/entities/geometry/BoundingBox.java +++ b/src/main/java/org/verapdf/wcag/algorithms/entities/geometry/BoundingBox.java @@ -225,9 +225,7 @@ public boolean weaklyContains(BoundingBox fullRectangle) { BoundingBox part = cross(fullRectangle); return part != null && part.getArea() >= fullRectangle.getArea() * 0.7; } - else { - return contains(fullRectangle); - } + return contains(fullRectangle); } public static BoundingBox cross(BoundingBox first, BoundingBox second) { diff --git a/src/main/java/org/verapdf/wcag/algorithms/entities/geometry/MultiBoundingBox.java b/src/main/java/org/verapdf/wcag/algorithms/entities/geometry/MultiBoundingBox.java index 4efbffa7..d8f114bb 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/entities/geometry/MultiBoundingBox.java +++ b/src/main/java/org/verapdf/wcag/algorithms/entities/geometry/MultiBoundingBox.java @@ -143,6 +143,7 @@ public List getBoundingBoxes() { return boundingBoxes; } + @Override public BoundingBox getBoundingBox(int pageNumber) { if (this.pageNumber > pageNumber || this.lastPageNumber < pageNumber) { return null; @@ -162,6 +163,7 @@ public BoundingBox getBoundingBox(int pageNumber) { return boundingBox; } + @Override public Double getRightX(int pageNumber) { if (this.pageNumber > pageNumber || this.lastPageNumber < pageNumber) { return null; @@ -179,6 +181,7 @@ public Double getRightX(int pageNumber) { return maxRight; } + @Override public Double getLeftX(int pageNumber) { if (this.pageNumber > pageNumber || this.lastPageNumber < pageNumber) { return null; diff --git a/src/main/java/org/verapdf/wcag/algorithms/entities/geometry/Vertex.java b/src/main/java/org/verapdf/wcag/algorithms/entities/geometry/Vertex.java index 8f36a291..7f38572d 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/entities/geometry/Vertex.java +++ b/src/main/java/org/verapdf/wcag/algorithms/entities/geometry/Vertex.java @@ -47,12 +47,14 @@ public static boolean areCloseVertexes(Vertex v1, Vertex v2, double epsilon) { } public static class VertexComparatorX implements Comparator { + @Override public int compare(Vertex vertex1, Vertex vertex2){ return Double.compare(vertex1.getLeftX(), vertex2.getLeftX()); } } public static class VertexComparatorY implements Comparator { + @Override public int compare(Vertex vertex1, Vertex vertex2){ return -Double.compare(vertex1.getTopY(), vertex2.getTopY()); } diff --git a/src/main/java/org/verapdf/wcag/algorithms/entities/tables/Table.java b/src/main/java/org/verapdf/wcag/algorithms/entities/tables/Table.java index c1ae706f..c9c40775 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/entities/tables/Table.java +++ b/src/main/java/org/verapdf/wcag/algorithms/entities/tables/Table.java @@ -176,7 +176,7 @@ private List pickCompactRows(List allRows) { } private void extractRestNodes(List restRows) { - Set nodeSet = new HashSet(); + Set nodeSet = new HashSet<>(); for (TableRow row : restRows) { for (TableCell cell : row.getCells()) { for (TableTokenRow tableTokenRow : cell.getContent()) { diff --git a/src/main/java/org/verapdf/wcag/algorithms/entities/tables/TableBorderBuilder.java b/src/main/java/org/verapdf/wcag/algorithms/entities/tables/TableBorderBuilder.java index 99f4f359..ff57fd1c 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/entities/tables/TableBorderBuilder.java +++ b/src/main/java/org/verapdf/wcag/algorithms/entities/tables/TableBorderBuilder.java @@ -11,8 +11,8 @@ public class TableBorderBuilder { private final BoundingBox boundingBox; private final Set vertexes; - private final TreeSet horizontalLines; - private final TreeSet verticalLines; + private final SortedSet horizontalLines; + private final SortedSet verticalLines; public TableBorderBuilder(LineChunk lineChunk) { vertexes = new HashSet<>(); @@ -119,6 +119,7 @@ public BoundingBox getBoundingBox() { } public static class TableBorderBuildersComparator implements Comparator { + @Override public int compare(TableBorderBuilder builder1, TableBorderBuilder builder2){ int res = Double.compare(builder2.getBoundingBox().getTopY(), builder1.getBoundingBox().getTopY()); if (res != 0) { diff --git a/src/main/java/org/verapdf/wcag/algorithms/entities/tables/TableRow.java b/src/main/java/org/verapdf/wcag/algorithms/entities/tables/TableRow.java index c3a0a247..a9032640 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/entities/tables/TableRow.java +++ b/src/main/java/org/verapdf/wcag/algorithms/entities/tables/TableRow.java @@ -9,7 +9,7 @@ public class TableRow extends TextInfoChunk { private Long id; - private List cells; + private final List cells; private SemanticType semanticType = null; public TableRow() { diff --git a/src/main/java/org/verapdf/wcag/algorithms/entities/tables/tableBorders/TableBorder.java b/src/main/java/org/verapdf/wcag/algorithms/entities/tables/tableBorders/TableBorder.java index 65ca0b80..02553670 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/entities/tables/tableBorders/TableBorder.java +++ b/src/main/java/org/verapdf/wcag/algorithms/entities/tables/tableBorders/TableBorder.java @@ -420,6 +420,7 @@ public boolean isBadTable() { } public static class TableBordersComparator implements Comparator { + @Override public int compare(TableBorder border1, TableBorder border2) { int res = Double.compare(border2.getBoundingBox().getTopY(), border1.getBoundingBox().getTopY()); if (res != 0) { diff --git a/src/main/java/org/verapdf/wcag/algorithms/entities/tables/tableBorders/TableBorderRow.java b/src/main/java/org/verapdf/wcag/algorithms/entities/tables/tableBorders/TableBorderRow.java index 6b227fc7..2ed15115 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/entities/tables/tableBorders/TableBorderRow.java +++ b/src/main/java/org/verapdf/wcag/algorithms/entities/tables/tableBorders/TableBorderRow.java @@ -6,8 +6,8 @@ import org.verapdf.wcag.algorithms.entities.geometry.BoundingBox; public class TableBorderRow extends BaseObject { - private int rowNumber; - protected TableBorderCell[] cells; + private final int rowNumber; + protected final TableBorderCell[] cells; private SemanticType semanticType; private INode node; diff --git a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/AccumulatedNodeSemanticChecker.java b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/AccumulatedNodeSemanticChecker.java index dd286994..afff49fa 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/AccumulatedNodeSemanticChecker.java +++ b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/AccumulatedNodeSemanticChecker.java @@ -6,8 +6,6 @@ import org.verapdf.wcag.algorithms.semanticalgorithms.consumers.*; import org.verapdf.wcag.algorithms.semanticalgorithms.containers.StaticContainers; -import java.util.function.Consumer; - public class AccumulatedNodeSemanticChecker implements ISemanticsChecker { @Override diff --git a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/ContrastRatioChecker.java b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/ContrastRatioChecker.java index 8ffeaac5..0b7f89c3 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/ContrastRatioChecker.java +++ b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/ContrastRatioChecker.java @@ -2,9 +2,7 @@ import org.verapdf.wcag.algorithms.entities.IDocument; import org.verapdf.wcag.algorithms.entities.INode; -import org.verapdf.wcag.algorithms.entities.IPage; import org.verapdf.wcag.algorithms.entities.ITree; -import org.verapdf.wcag.algorithms.entities.content.TextChunk; import org.verapdf.wcag.algorithms.entities.enums.TextType; import org.verapdf.wcag.algorithms.semanticalgorithms.consumers.ContrastRatioConsumer; diff --git a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/AccumulatedNodeConsumer.java b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/AccumulatedNodeConsumer.java index 428dc2c9..5ced97ee 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/AccumulatedNodeConsumer.java +++ b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/AccumulatedNodeConsumer.java @@ -142,7 +142,7 @@ private void acceptSpanParagraphPart(INode node, boolean isLeafChild) { boundingBox.union(child.getBoundingBox()); continue; } - if (child.getSemanticType().equals(SemanticType.FIGURE)) { + if (child.getSemanticType() == SemanticType.FIGURE) { continue; } if (part == null) { @@ -166,7 +166,7 @@ private void acceptSpanParagraphPart(INode node, boolean isLeafChild) { SemanticType semanticType = SemanticType.PART; INode accumulatedNode = part; if (part != null && part.getColumns().stream().allMatch(TextColumn::hasOnlyOneBlock)) { - boolean isSpan = SemanticType.SPAN.equals(node.getInitialSemanticType()) && + boolean isSpan = SemanticType.SPAN == node.getInitialSemanticType() && (isLeafChild || node.getChildren().stream() .allMatch(AccumulatedNodeConsumer::isAppropriateSpanChild)); if (isSpan) { @@ -310,6 +310,7 @@ private void updateTextChunksFormat(SemanticTextNode textNode) { } } + @Override public WCAGProgressStatus getWCAGProgressStatus() { return WCAGProgressStatus.PARAGRAPH_DETECTION; } diff --git a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/ClusterTableConsumer.java b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/ClusterTableConsumer.java index c94c9e7f..fe616657 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/ClusterTableConsumer.java +++ b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/ClusterTableConsumer.java @@ -171,7 +171,7 @@ private List recognize() { return recognizedTable.getRestNodes(); } - return new ArrayList(); + return new ArrayList<>(); } private boolean checkTable(Table recognizedTable) { @@ -394,7 +394,7 @@ private INode updateTreeWithRecognizedTable(Table table, INode root) { INode localRoot = findLocalRoot(rows); if (localRoot != null) { - if (type == SemanticType.TABLE_BODY && localRoot.getPageNumber() != localRoot.getLastPageNumber()) { + if (type == SemanticType.TABLE_BODY && !Objects.equals(localRoot.getPageNumber(), localRoot.getLastPageNumber())) { table.setBodyNode(localRoot); } else { updateNode(localRoot, table.getId(), type, table.getTableBorder() != null, @@ -538,7 +538,7 @@ private INode updateTreeWithRecognizedList(PDFList list) { private boolean updateNode(INode node, Long id, SemanticType semanticType, boolean hasTableBorder, BoundingBox boundingBox) { if ((((ListUtils.isDetectedListNode(node) && !hasTableBorder) || TableUtils.isTableNode(node)) && - node.getRecognizedStructureId() != id) || (semanticType != SemanticType.TABLE && !isNodeInsideTable(node, + !Objects.equals(node.getRecognizedStructureId(), id)) || (semanticType != SemanticType.TABLE && !isNodeInsideTable(node, id, boundingBox, semanticType))) { node.setRecognizedStructureId(null); return false; @@ -551,7 +551,7 @@ private boolean updateNode(INode node, Long id, SemanticType semanticType, boole //optimize public static boolean isNodeInsideTable(INode node, Long id, BoundingBox boundingBox, SemanticType semanticType) { - if (node.getRecognizedStructureId() == id) { + if (Objects.equals(node.getRecognizedStructureId(), id)) { return true; } if (node instanceof SemanticTextNode) { @@ -745,6 +745,7 @@ private static boolean hasOtherChildrenWithContents(INode parent, INode node) { return false; } + @Override public WCAGProgressStatus getWCAGProgressStatus() { return WCAGProgressStatus.TABLE_DETECTION; } diff --git a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/ContrastRatioConsumer.java b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/ContrastRatioConsumer.java index 9db5fdd9..89d6c026 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/ContrastRatioConsumer.java +++ b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/ContrastRatioConsumer.java @@ -416,6 +416,7 @@ public int compareTo(DataPoint o) { } } + @Override public WCAGProgressStatus getWCAGProgressStatus() { return WCAGProgressStatus.CONTRAST_DETECTION; } diff --git a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/HeadingCaptionConsumer.java b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/HeadingCaptionConsumer.java index 238ac2d0..f4133376 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/HeadingCaptionConsumer.java +++ b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/HeadingCaptionConsumer.java @@ -33,7 +33,7 @@ private void acceptChildrenSemanticHeading(INode node) { List children = new ArrayList<>(node.getChildren().size()); List textChildren = new ArrayList<>(node.getChildren().size()); for (INode child : node.getChildren()) { - if (child != null && !SemanticType.BLOCK_QUOTE.equals(child.getInitialSemanticType())) { + if (child != null && SemanticType.BLOCK_QUOTE != child.getInitialSemanticType()) { INode accumulatedChild = StaticContainers.getAccumulatedNodeMapper().get(child); if (accumulatedChild instanceof SemanticTextNode) { SemanticTextNode textNode = (SemanticTextNode)accumulatedChild; @@ -207,6 +207,7 @@ private void acceptImageCaption(INode imageNode, INode previousNode, INode nextN } } + @Override public WCAGProgressStatus getWCAGProgressStatus() { return WCAGProgressStatus.HEADING_AND_CAPTION_DETECTION; } diff --git a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/LinesPreprocessingConsumer.java b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/LinesPreprocessingConsumer.java index 55b71178..dec87715 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/LinesPreprocessingConsumer.java +++ b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/LinesPreprocessingConsumer.java @@ -116,6 +116,7 @@ private void mergeTableBorders(List tableBorders) { } } + @Override public WCAGProgressStatus getWCAGProgressStatus() { return WCAGProgressStatus.LINES_PREPROCESSING; } diff --git a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/ListDetectionConsumer.java b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/ListDetectionConsumer.java index 131ba4cb..24e73cb9 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/ListDetectionConsumer.java +++ b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/ListDetectionConsumer.java @@ -69,8 +69,8 @@ private void acceptSemanticList(INode node) { if (child == null) { continue; } - if (SemanticType.LIST.equals(child.getSemanticType()) && child.getChildren().stream() - .filter(i -> SemanticType.LIST_ITEM.equals(i.getSemanticType())) + if (SemanticType.LIST == child.getSemanticType() && child.getChildren().stream() + .filter(i -> SemanticType.LIST_ITEM == i.getSemanticType()) .count() > 1) { continue; } @@ -125,12 +125,12 @@ private void acceptSemanticList(INode node) { } private boolean updateTreeWithOneElementList(INode node, List itemsInfo) { - if (SemanticType.LIST.equals(node.getInitialSemanticType()) && + if (SemanticType.LIST == node.getInitialSemanticType() && itemsInfo.size() == itemsInfo.stream() - .filter(i -> SemanticType.LIST.equals(i.getSemanticType())) + .filter(i -> SemanticType.LIST == i.getSemanticType()) .count() + 1) { int index = IntStream.range(0, itemsInfo.size()) - .filter(i -> !SemanticType.LIST.equals(itemsInfo.get(i).getSemanticType())) + .filter(i -> SemanticType.LIST != itemsInfo.get(i).getSemanticType()) .findFirst().orElse(0); if (ListLabelsUtils.isListLabel(itemsInfo.get(index).getListItem())) { int originalIndex = itemsInfo.get(index).getIndex(); @@ -321,6 +321,7 @@ private static boolean isContainsSeveralPagesList(INode node) { return false; } + @Override public WCAGProgressStatus getWCAGProgressStatus() { return WCAGProgressStatus.LIST_DETECTION; } diff --git a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/SemanticDocumentPostprocessingConsumer.java b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/SemanticDocumentPostprocessingConsumer.java index 70670192..632f2e93 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/SemanticDocumentPostprocessingConsumer.java +++ b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/SemanticDocumentPostprocessingConsumer.java @@ -1,13 +1,11 @@ package org.verapdf.wcag.algorithms.semanticalgorithms.consumers; import org.verapdf.wcag.algorithms.entities.*; -import org.verapdf.wcag.algorithms.entities.ITree; import org.verapdf.wcag.algorithms.entities.content.TextChunk; import org.verapdf.wcag.algorithms.entities.content.TextColumn; import org.verapdf.wcag.algorithms.entities.content.TextLine; import org.verapdf.wcag.algorithms.semanticalgorithms.containers.StaticContainers; import org.verapdf.wcag.algorithms.semanticalgorithms.utils.*; -import org.verapdf.wcag.algorithms.entities.SemanticTextNode; import org.verapdf.wcag.algorithms.entities.enums.SemanticType; import org.verapdf.wcag.algorithms.entities.geometry.BoundingBox; import org.verapdf.wcag.algorithms.entities.geometry.MultiBoundingBox; @@ -214,6 +212,7 @@ private void updateIDs(ITree tree) { } } + @Override public WCAGProgressStatus getWCAGProgressStatus() { return WCAGProgressStatus.DOCUMENT_POSTPROCESSING; } diff --git a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/SemanticDocumentPreprocessingConsumer.java b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/SemanticDocumentPreprocessingConsumer.java index a014b534..cb5df801 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/SemanticDocumentPreprocessingConsumer.java +++ b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/SemanticDocumentPreprocessingConsumer.java @@ -48,12 +48,13 @@ public void setNodeParents() { } } + @Override public void accept(INode node) { // setup parent nodes for children if (node instanceof SemanticSpan) { textChunksNumber++; - if (node.getChildren().size() != 0) { + if (!node.getChildren().isEmpty()) { LOGGER.log(Level.WARNING, "Text chunk cannot contain children: {}", node); } } else if (node.getInitialSemanticType() == SemanticType.SPAN) { @@ -130,6 +131,7 @@ public long getStructElementsNumber() { return structElementsNumber; } + @Override public WCAGProgressStatus getWCAGProgressStatus() { return WCAGProgressStatus.DOCUMENT_PREPROCESSING; } diff --git a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/TOCDetectionConsumer.java b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/TOCDetectionConsumer.java index 01aa5003..3ce440a9 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/TOCDetectionConsumer.java +++ b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/TOCDetectionConsumer.java @@ -784,10 +784,12 @@ private static boolean checkArabicNumbering(INode child, String firstTOCI, Strin return true; } + @Override public WCAGProgressStatus getWCAGProgressStatus() { return WCAGProgressStatus.TOC_DETECTION; } + @Override public Double getPercent() { return 100.0d * processedStructElements / structElementsNumber; } diff --git a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/TableBorderConsumer.java b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/TableBorderConsumer.java index dba0b046..dfe20aa9 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/TableBorderConsumer.java +++ b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/TableBorderConsumer.java @@ -174,7 +174,7 @@ private static void updateTreeWithRecognizedTableRow(TableBorderRow row, TableBo private static void setType(INode node, SemanticType type, Long id, BoundingBox boundingBox) { if (node != null) { - if (((TableUtils.isTableNode(node)) && node.getRecognizedStructureId() != id) || + if (((TableUtils.isTableNode(node)) && !Objects.equals(node.getRecognizedStructureId(), id)) || !ClusterTableConsumer.isNodeInsideTable(node, id, boundingBox, type)) { node.setRecognizedStructureId(null); } else { @@ -315,7 +315,7 @@ private static List findParents(List nodes, int depth) { } public static INode findCommonParent(Set nodes) { - if (nodes.size() == 0) { + if (nodes.isEmpty()) { return null; } if (nodes.size() == 1) { @@ -340,6 +340,7 @@ public static INode findCommonParent(Set nodes) { return parents.iterator().next(); } + @Override public WCAGProgressStatus getWCAGProgressStatus() { return WCAGProgressStatus.TABLE_BORDER_DETECTION; } diff --git a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/TableChecker.java b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/TableChecker.java index fab7f961..7d7c2192 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/TableChecker.java +++ b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/consumers/TableChecker.java @@ -426,6 +426,7 @@ private static void checkTableVisualRepresentation(INode table, TableBorderCell[ } } + @Override public WCAGProgressStatus getWCAGProgressStatus() { return WCAGProgressStatus.TABLE_VALIDATION; } diff --git a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/tables/TableCluster.java b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/tables/TableCluster.java index 16f360ac..e5fac0f7 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/tables/TableCluster.java +++ b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/tables/TableCluster.java @@ -342,10 +342,10 @@ public void merge(TableCluster other, boolean update) { // update merged cluster min gaps if (update) { - if (leftSet.size() > 0) { + if (!leftSet.isEmpty()) { updateMinGap(Side.LEFT); } - if (rightSet.size() > 0) { + if (!rightSet.isEmpty()) { updateMinGap(Side.RIGHT); } } @@ -357,7 +357,7 @@ public void sortAndMergeRows() { return; } - Collections.sort(rows, Comparator.comparingInt(TableTokenRow::getRowNumber). + rows.sort(Comparator.comparingInt(TableTokenRow::getRowNumber). thenComparingDouble(y -> -y.getBaseLine()). thenComparingDouble(TableTokenRow::getLeftX)); @@ -377,6 +377,7 @@ public void sortAndMergeRows() { rows = result; } + @Override public double getFirstBaseLine() { return getFirstRow().getFirstBaseLine(); } diff --git a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/tables/TableRecognitionArea.java b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/tables/TableRecognitionArea.java index 6bcb6a76..a33510b0 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/tables/TableRecognitionArea.java +++ b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/tables/TableRecognitionArea.java @@ -258,7 +258,7 @@ private boolean joinHeaders(TableCluster currentHeader, TableCluster header, Tex } private boolean addCluster(TextInfoChunk token) { - if (token.getPageNumber() != token.getLastPageNumber()) { + if (!token.getPageNumber().equals(token.getLastPageNumber())) { isComplete = true; return false; } diff --git a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/tables/TableRecognizer.java b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/tables/TableRecognizer.java index 22dc43f6..bc9fdddc 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/tables/TableRecognizer.java +++ b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/tables/TableRecognizer.java @@ -350,7 +350,7 @@ private Table constructTable() { if (rowNumber == null || rowNumber <= i) { if (rowNumber == i) { TableCell cell = new TableCell(column.getRows().get(rowId), SemanticType.TABLE_CELL); - while (rowId + 1 < column.getRows().size() && column.getRows().get(rowId + 1).getRowNumber() == rowNumber) { + while (rowId + 1 < column.getRows().size() && column.getRows().get(rowId + 1).getRowNumber().equals(rowNumber)) { cell.add(column.getRows().get(++rowId)); } tableRow.add(cell); diff --git a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/ChunksMergeUtils.java b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/ChunksMergeUtils.java index e9e5612d..c124757a 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/ChunksMergeUtils.java +++ b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/ChunksMergeUtils.java @@ -127,7 +127,7 @@ public static double countOneLineProbability(SemanticTextNode secondNode, TextLi double centersDiff = getCentersDifference(x, y); double fontSizeDiff = getFontSizeDifference(x, y); - if (!TextFormat.NORMAL.equals(x.getTextFormat())) { + if (TextFormat.NORMAL != x.getTextFormat()) { TextChunk z = lastLine.getLastNormalTextChunk(); if (z != null) { baseLineDiff = getBaseLineDifference(z, y); diff --git a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/ContextUtils.java b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/ContextUtils.java index 95d83309..26c671eb 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/ContextUtils.java +++ b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/ContextUtils.java @@ -47,6 +47,7 @@ protected BoundingBoxSerializer(Class t) { super(t); } + @Override public void serialize(BoundingBox bbox, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeStartObject(); @@ -73,6 +74,7 @@ protected MultiBoundingBoxSerializer(Class t) { super(t); } + @Override public void serialize(MultiBoundingBox multiBBox, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { diff --git a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/ListLabelsUtils.java b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/ListLabelsUtils.java index 48e9d3ff..060ee561 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/ListLabelsUtils.java +++ b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/ListLabelsUtils.java @@ -12,7 +12,6 @@ import org.verapdf.wcag.algorithms.semanticalgorithms.utils.listLabelsDetection.RomanNumbersListLabelsDetectionAlgorithm; import java.util.*; -import java.util.stream.Collectors; public class ListLabelsUtils { @@ -119,7 +118,7 @@ public static Set getImageListItemsIntervals(List getItemsWithEqualsLabels(List for (ListItemTextInfo info : itemsInfo) { boolean badListItem = info.getListItem().length() == 1 && info.hasOneLine(); if (!Objects.equals(info.getListItem().charAt(0), firstChar) || badListItem) { - if (SemanticType.LIST.equals(info.getSemanticType())) { + if (SemanticType.LIST == info.getSemanticType()) { interval.getListsIndexes().add(info.getIndex()); continue; } diff --git a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/ListUtils.java b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/ListUtils.java index 3dbef3c2..78f515a6 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/ListUtils.java +++ b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/ListUtils.java @@ -88,7 +88,7 @@ public static void updateTreeWithRecognizedList(INode node, ListInterval listInt INode child = children.get(info.getIndex()); if (child.getSemanticType() != SemanticType.TABLE_OF_CONTENT_ITEM && child.getSemanticType() != SemanticType.TABLE_OF_CONTENT) - updateTreeWithRecognizedListItem(child, listId); + updateTreeWithRecognizedListItem(child, listId); } if (node.getRecognizedStructureId() == null) { double probability = ((double) (listInterval.getNumberOfListItemsAndLists())) / node.getChildren().size(); diff --git a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/NodeUtils.java b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/NodeUtils.java index dd3eee02..6d7d00c4 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/NodeUtils.java +++ b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/NodeUtils.java @@ -5,7 +5,6 @@ import org.verapdf.wcag.algorithms.entities.SemanticTextNode; import org.verapdf.wcag.algorithms.entities.content.LineChunk; import org.verapdf.wcag.algorithms.entities.content.TextChunk; -import org.verapdf.wcag.algorithms.entities.enums.SemanticType; import java.awt.*; import java.util.Arrays; diff --git a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/TableUtils.java b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/TableUtils.java index d8ef9021..b07439a0 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/TableUtils.java +++ b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/TableUtils.java @@ -90,11 +90,11 @@ public static boolean areOverlapping(TextInfoChunk chunk1, TextInfoChunk chunk2) } public static void sortClustersLeftToRight(List clusters) { - Collections.sort(clusters, Comparator.comparingDouble(TableCluster::getLeftX)); + clusters.sort(Comparator.comparingDouble(TableCluster::getLeftX)); } public static void sortClustersUpToBottom(List clusters) { - Collections.sort(clusters, Comparator.comparingDouble(TableCluster::getFirstBaseLine).reversed()); + clusters.sort(Comparator.comparingDouble(TableCluster::getFirstBaseLine).reversed()); } public static boolean isWeakCluster(TableCluster cluster, List headers) { diff --git a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/listLabelsDetection/ArabicNumbersListLabelsDetectionAlgorithm.java b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/listLabelsDetection/ArabicNumbersListLabelsDetectionAlgorithm.java index be45f196..ab0c4be5 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/listLabelsDetection/ArabicNumbersListLabelsDetectionAlgorithm.java +++ b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/listLabelsDetection/ArabicNumbersListLabelsDetectionAlgorithm.java @@ -56,7 +56,7 @@ public Set getItemsIntervals(List itemsInfo) { arabicNumberInformation.number++; ListItemTextInfo itemInfo = itemsInfo.get(i); if (!arabicNumberInformation.checkItem(itemInfo) || arabicNumberInformation.isBadItem(itemInfo)) { - if (SemanticType.LIST.equals(itemInfo.getSemanticType())) { + if (SemanticType.LIST == itemInfo.getSemanticType()) { arabicNumberInformation.number--; interval.getListsIndexes().add(itemInfo.getIndex()); continue; diff --git a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/listLabelsDetection/LettersListLabelsDetectionAlgorithm.java b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/listLabelsDetection/LettersListLabelsDetectionAlgorithm.java index 5887d868..b6f35828 100644 --- a/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/listLabelsDetection/LettersListLabelsDetectionAlgorithm.java +++ b/src/main/java/org/verapdf/wcag/algorithms/semanticalgorithms/utils/listLabelsDetection/LettersListLabelsDetectionAlgorithm.java @@ -7,6 +7,7 @@ import java.util.*; public abstract class LettersListLabelsDetectionAlgorithm extends ListLabelsDetectionAlgorithm { + @Override public boolean isListLabels(List labels, int commonStartLength, int commonEndLength) { if (!labels.get(0).substring(commonStartLength, labels.get(0).length() - commonEndLength).matches(getRegex())) { return false; @@ -39,13 +40,14 @@ public boolean isListLabels(List labels, int commonStartLength, int comm if (nextNumber == null) { return false; } - if (!substring.equalsIgnoreCase(getStringFromNumber(nextNumber)) || nextNumber != ++number) { + if (!substring.equalsIgnoreCase(getStringFromNumber(nextNumber)) || !nextNumber.equals(++number)) { return false; } } return true; } + @Override public Set getItemsIntervals(List itemsInfo) { Set listIntervals = new HashSet<>(); Integer number = null; @@ -63,7 +65,7 @@ public Set getItemsIntervals(List itemsInfo) { isCharMatchRegex(item, start + s.length()) || isBadItem(itemInfo, item, s, start) || ((!item.substring(start, start + s.length()).matches(getLowerCaseRegex()) || isUpperCase) && (!item.substring(start, start + s.length()).matches(getUpperCaseRegex()) || !isUpperCase))) { - if (SemanticType.LIST.equals(itemInfo.getSemanticType())) { + if (SemanticType.LIST == itemInfo.getSemanticType()) { interval.getListsIndexes().add(itemInfo.getIndex()); number--; continue; diff --git a/src/test/java/org/verapdf/wcag/algorithms/consumers/ContrastRatioConsumerTests.java b/src/test/java/org/verapdf/wcag/algorithms/consumers/ContrastRatioConsumerTests.java index 6af07743..0ececbca 100644 --- a/src/test/java/org/verapdf/wcag/algorithms/consumers/ContrastRatioConsumerTests.java +++ b/src/test/java/org/verapdf/wcag/algorithms/consumers/ContrastRatioConsumerTests.java @@ -58,7 +58,7 @@ void testColorContrastPass(String srcPdfPath, String jsonPdfPath, double ratioTh tree.forEach(contrastRatioConsumer); tree.forEach(node -> { - if (node.getChildren().size() == 0 && SemanticType.SPAN.equals(node.getSemanticType())) { + if (node.getChildren().isEmpty() && SemanticType.SPAN == node.getSemanticType()) { for (TextColumn textColumn : ((SemanticSpan)node).getColumns()) { for (TextLine line : textColumn.getLines()) { for (TextChunk chunk : line.getTextChunks()) { @@ -95,7 +95,7 @@ void testColorContrastFail(String srcPdfPath, String jsonPdfPath, double ratioTh tree.forEach(contrastRatioConsumer); tree.forEach(node -> { - if (node.getChildren().size() == 0 && SemanticType.SPAN.equals(node.getSemanticType())) { + if (node.getChildren().isEmpty() && SemanticType.SPAN == node.getSemanticType()) { for (TextColumn textColumn : ((SemanticSpan)node).getColumns()) { for (TextLine line : textColumn.getLines()) { for (TextChunk chunk : line.getTextChunks()) { diff --git a/src/test/java/org/verapdf/wcag/algorithms/entities/JsonAttributes.java b/src/test/java/org/verapdf/wcag/algorithms/entities/JsonAttributes.java index 558d9bbf..0ad93248 100644 --- a/src/test/java/org/verapdf/wcag/algorithms/entities/JsonAttributes.java +++ b/src/test/java/org/verapdf/wcag/algorithms/entities/JsonAttributes.java @@ -32,8 +32,8 @@ public boolean equals(Object o) { return false; } JsonAttributes jsonAttributes = (JsonAttributes) o; - return Long.compare(jsonAttributes.colSpan, colSpan) == 0 && - Long.compare(jsonAttributes.rowSpan, rowSpan) == 0; + return jsonAttributes.colSpan == colSpan && + jsonAttributes.rowSpan == rowSpan; } @Override diff --git a/src/test/java/org/verapdf/wcag/algorithms/entities/NodeIdResolver.java b/src/test/java/org/verapdf/wcag/algorithms/entities/NodeIdResolver.java index 9a36e8ed..934a2005 100644 --- a/src/test/java/org/verapdf/wcag/algorithms/entities/NodeIdResolver.java +++ b/src/test/java/org/verapdf/wcag/algorithms/entities/NodeIdResolver.java @@ -5,8 +5,6 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.jsontype.impl.TypeIdResolverBase; -import java.io.IOException; - public class NodeIdResolver extends TypeIdResolverBase { private JavaType superType; @@ -32,8 +30,8 @@ public String idFromValueAndType(Object o, Class aClass) { } @Override - public JavaType typeFromId(DatabindContext context, String id) throws IOException { - Class subType = null; + public JavaType typeFromId(DatabindContext context, String id) { + Class subType; switch (id) { case "TextChunk": subType = JsonTextChunk.class; diff --git a/src/test/java/org/verapdf/wcag/algorithms/semanticalgorithms/ContrastRatioCheckerTests.java b/src/test/java/org/verapdf/wcag/algorithms/semanticalgorithms/ContrastRatioCheckerTests.java index 3b46f230..e12252ad 100644 --- a/src/test/java/org/verapdf/wcag/algorithms/semanticalgorithms/ContrastRatioCheckerTests.java +++ b/src/test/java/org/verapdf/wcag/algorithms/semanticalgorithms/ContrastRatioCheckerTests.java @@ -18,7 +18,6 @@ import java.io.File; import java.io.IOException; import java.util.*; -import java.util.List; import java.util.stream.Stream; public class ContrastRatioCheckerTests {