Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring based on static code analysis #320

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ public void setColSpan(long colSpan) {
this.colSpan = colSpan;
}

@Override
public long getRowSpan() {
return rowSpan;
}

@Override
public long getColSpan() {
return colSpan;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/org/verapdf/wcag/algorithms/entities/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,46 @@

public class Document implements IDocument {

private ITree tree;
private List<IPage> pages;
private final ITree tree;
private final List<IPage> pages;

public Document(ITree tree) {
this.tree = tree;
pages = new LinkedList<>();
}

@Override
public ITree getTree(){
return tree;
}

@Override
public List<IChunk> getArtifacts(Integer pageNumber) {
if (pageNumber < pages.size()) {
return pages.get(pageNumber).getArtifacts();
}
return Collections.emptyList();
}

@Override
public List<IPage> getPages() {
return pages;
}

@Override
public int getNumberOfPages() {
return pages.size();
}

@Override
public IPage getPage(Integer pageNumber) {
if (pageNumber < pages.size()) {
return pages.get(pageNumber);
}
return null;
}

@Override
public List<IChunk> getArtifacts() {
List<IChunk> artifacts = new ArrayList<>();
for (IPage page : pages) {
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/org/verapdf/wcag/algorithms/entities/INode.java
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public interface ITree extends Iterable<INode> {

INode getRoot();

@Override
default Iterator<INode> iterator() {
return new DFSTreeNodeIterator(getRoot());
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/verapdf/wcag/algorithms/entities/Page.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ public Page(int pageNumber, String pageLabel) {
artifacts = new LinkedList<>();
}

@Override
public List<IChunk> getArtifacts() {
return artifacts;
}

@Override
public int getPageNumber() {
return pageNumber;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ public SemanticTree(INode root) {
this.root = root;
}

@Override
public INode getRoot() {
return root;
}

@Override
public Iterator<INode> iterator() {
return new DFSTreeNodeIterator(this.getRoot());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,12 +74,14 @@ public boolean isSquare() {
return isSquare;
}

@Override
public double getWidth() {
return width;
}

public static class HorizontalLineComparator implements Comparator<LineChunk> {

@Override
public int compare(LineChunk line1, LineChunk line2){
int res = Double.compare(line2.getCenterY(), line1.getCenterY());
if (res != 0) {
Expand All @@ -91,6 +93,7 @@ public int compare(LineChunk line1, LineChunk line2){

public static class VerticalLineComparator implements Comparator<LineChunk> {

@Override
public int compare(LineChunk line1, LineChunk line2){
int res = Double.compare(line1.getCenterX(), line2.getCenterX());
if (res != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public TextChunk(TextChunk chunk) {
chunk.baseLine, chunk.fontColor, chunk.symbolEnds, chunk.slantDegree);
}

@Override
public String getValue() {
return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -69,6 +69,7 @@ public void add(TextLine line) {
}
}

@Override
public String getValue() {
if (textChunks.isEmpty()) {
return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public List<BoundingBox> getBoundingBoxes() {
return boundingBoxes;
}

@Override
public BoundingBox getBoundingBox(int pageNumber) {
if (this.pageNumber > pageNumber || this.lastPageNumber < pageNumber) {
return null;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ public static boolean areCloseVertexes(Vertex v1, Vertex v2, double epsilon) {
}

public static class VertexComparatorX implements Comparator<Vertex> {
@Override
public int compare(Vertex vertex1, Vertex vertex2){
return Double.compare(vertex1.getLeftX(), vertex2.getLeftX());
}
}

public static class VertexComparatorY implements Comparator<Vertex> {
@Override
public int compare(Vertex vertex1, Vertex vertex2){
return -Double.compare(vertex1.getTopY(), vertex2.getTopY());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private List<TableRow> pickCompactRows(List<TableRow> allRows) {
}

private void extractRestNodes(List<TableRow> restRows) {
Set<INode> nodeSet = new HashSet<INode>();
Set<INode> nodeSet = new HashSet<>();
for (TableRow row : restRows) {
for (TableCell cell : row.getCells()) {
for (TableTokenRow tableTokenRow : cell.getContent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class TableBorderBuilder {

private final BoundingBox boundingBox;
private final Set<Vertex> vertexes;
private final TreeSet<LineChunk> horizontalLines;
private final TreeSet<LineChunk> verticalLines;
private final SortedSet<LineChunk> horizontalLines;
private final SortedSet<LineChunk> verticalLines;

public TableBorderBuilder(LineChunk lineChunk) {
vertexes = new HashSet<>();
Expand Down Expand Up @@ -119,6 +119,7 @@ public BoundingBox getBoundingBox() {
}

public static class TableBorderBuildersComparator implements Comparator<TableBorderBuilder> {
@Override
public int compare(TableBorderBuilder builder1, TableBorderBuilder builder2){
int res = Double.compare(builder2.getBoundingBox().getTopY(), builder1.getBoundingBox().getTopY());
if (res != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public class TableRow extends TextInfoChunk {
private Long id;
private List<TableCell> cells;
private final List<TableCell> cells;
private SemanticType semanticType = null;

public TableRow() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ public boolean isBadTable() {
}

public static class TableBordersComparator implements Comparator<TableBorder> {
@Override
public int compare(TableBorder border1, TableBorder border2) {
int res = Double.compare(border2.getBoundingBox().getTopY(), border1.getBoundingBox().getTopY());
if (res != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading
Loading