Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximPlusov committed Dec 8, 2023
1 parent 0dbaa99 commit fbccb64
Show file tree
Hide file tree
Showing 128 changed files with 324 additions and 342 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
</plugins>

<resources>
<!-- regular resource processsing for everything except logback.xml -->
<!-- regular resource processing for everything except logback.xml -->
<resource>
<directory>src/main/resources</directory>
</resource>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class StringExceptions {
public static final String XREF_STM_NOT_SUPPORTED = "xref streams not supported";
public static final String INVALID_PDF_OBJECT = "invalid pdf object";
public static final String INVALID_PDF_ARRAY = "invalid pdf array";
public static final String INVALID_PDF_DICTONARY = "invalid pdf dictonary";
public static final String INVALID_PDF_DICTIONARY = "invalid pdf dictionary";
public static final String INVALID_PDF_STREAM = "invalid pdf stream";

public static final String DUPLICATE_FACTORY_NAMES = "internal library error";
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/verapdf/as/filters/ASFilterFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
*/
public class ASFilterFactory implements IASFilterFactory{

private ASAtom filterType;
private final ASAtom filterType;

public ASFilterFactory(ASAtom filterType) {
this.filterType = filterType;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/verapdf/as/filters/ASOutFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/
package org.verapdf.as.filters;

import org.verapdf.as.filters.io.ASBufferedInFilter;
import org.verapdf.as.io.ASInputStream;
import org.verapdf.as.io.ASOutputStream;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
/**
* Class provides buffered input from input stream.
* It has two uses. If the ASBufferedInFilter object is used as a buffered
* stream (e. g. in unseekable parsers) then the buffer holds DECODED bytes read
* stream (e.g. in unseekable parsers) then the buffer holds DECODED bytes read
* from inlaying stream.
* Before using the ASBufferedInFilter in this make sure to call initialize()
* method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
*/
public class ASBufferingOutFilter extends ASOutFilter {

private int bufferCapacity;
private final int bufferCapacity;
protected byte [] internalBuffer;
private int bufferWriter;
private int bufferEnd;
private final int bufferEnd;

public ASBufferingOutFilter(ASOutputStream stream) {
this(stream, ASBufferedInFilter.BF_BUFFER_SIZE);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/verapdf/as/io/ASInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public abstract class ASInputStream extends InputStream {
protected boolean isClosed = false;
protected boolean isSourceClosed = false;

protected IntReference resourceUsers = new IntReference(1);
protected final IntReference resourceUsers = new IntReference(1);

public abstract int read() throws IOException;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/verapdf/as/io/ASInputStreamWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
public class ASInputStreamWrapper extends ASInputStream {

private ASInputStream stream;
private final ASInputStream stream;

public ASInputStreamWrapper(ASInputStream stream) {
stream.incrementResourceUsers();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/verapdf/as/io/ASMemoryInStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
*/
public class ASMemoryInStream extends SeekableInputStream {

private int bufferSize;
private final int bufferSize;
private int bufferOffset = 0;
private int currentPosition;
private byte[] buffer;
private boolean copiedBuffer;
private final boolean copiedBuffer;
private int resetPosition = 0;
private IntReference numOfBufferUsers;
private final IntReference numOfBufferUsers;

/**
* Constructor from byte array. Buffer is copied while initializing
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/verapdf/cos/COSBasePair.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
* @author Sergey Shemyakov
*/
public class COSBasePair {
private COSBase first;
private COSBase second;
private final COSBase first;
private final COSBase second;

private COSBasePair(COSBase first, COSBase second) {
this.first = first;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/verapdf/cos/COSBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
public class COSBody {

private Map<COSKey, COSObject> table;
private final Map<COSKey, COSObject> table;

public COSBody() {
this.table = new HashMap<>();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/verapdf/cos/COSDictionary.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class COSDictionary extends COSDirect {
public static final String SIZE = "size";
public static final String DICTIONARY = "dictionary";

private Map<ASAtom, COSObject> entries;
private final Map<ASAtom, COSObject> entries;

protected COSDictionary() {
super();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/verapdf/cos/COSDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class COSDocument {
private StandardSecurityHandler standardSecurityHandler;
private List<COSObject> changedObjects;
private List<COSObject> addedObjects;
private FileResourceHandler resourceHandler;
private final FileResourceHandler resourceHandler;
private String fileName;

private long fileSize;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/verapdf/cos/COSFilters.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class COSFilters extends PDObject {

private static final Logger LOGGER = Logger.getLogger(COSFilters.class.getCanonicalName());

private List<ASAtom> entries;
private final List<ASAtom> entries;

public COSFilters() {
super();
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/org/verapdf/cos/COSIndirect.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,10 @@ protected COSIndirect(final COSObject value, final COSDocument document) {
this.document = document;
this.child = new COSObject();

if (document == null) {
this.child = value;
} else {
if (document != null) {
this.key = this.document.setObject(value);
this.child = value;
}
this.child = value;
}

// Access to base underlying object
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/verapdf/cos/COSName.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.verapdf.cos.visitor.IVisitor;

import java.nio.charset.StandardCharsets;
import java.util.Objects;

/**
* @author Timur Kamalov
Expand Down Expand Up @@ -125,7 +126,7 @@ public boolean equals(Object o) {

COSName cosName = (COSName) o;

return value != null ? value.equals(cosName.value) : cosName.value == null;
return Objects.equals(value, cosName.value);

}
}
3 changes: 2 additions & 1 deletion src/main/java/org/verapdf/cos/COSObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.verapdf.cos.visitor.IVisitor;

import java.util.Collection;
import java.util.Objects;
import java.util.Set;

/**
Expand Down Expand Up @@ -496,7 +497,7 @@ public boolean equals(Object o) {

COSObject cosObject = (COSObject) o;

return base != null ? base.equals(cosObject.base) : cosObject.base == null;
return Objects.equals(base, cosObject.base);

}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/verapdf/cos/COSStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public boolean setData(final ASInputStream stream, FilterFlags flags) {

@Override
public Boolean isStreamKeywordCRLFCompliant() {
return Boolean.valueOf(streamKeywordCRLFCompliant);
return streamKeywordCRLFCompliant;
}

@Override
Expand All @@ -207,7 +207,7 @@ public boolean setStreamKeywordCRLFCompliant(boolean streamKeywordCRLFCompliant)

@Override
public Boolean isEndstreamKeywordCRLFCompliant() {
return Boolean.valueOf(endstreamKeywordCRLFCompliant);
return endstreamKeywordCRLFCompliant;
}

@Override
Expand All @@ -218,7 +218,7 @@ public boolean setEndstreamKeywordCRLFCompliant(boolean endstreamKeywordCRLFComp

@Override
public Long getRealStreamSize() {
return Long.valueOf(realStreamSize);
return realStreamSize;
}

@Override
Expand Down Expand Up @@ -254,7 +254,7 @@ public void setFilterFlags(final FilterFlags flags) {
}

public long getLength() {
return getIntegerKey(ASAtom.LENGTH).longValue();
return getIntegerKey(ASAtom.LENGTH);
}

public void setLength(final long length) {
Expand All @@ -264,7 +264,7 @@ public void setLength(final long length) {
public void setIndirectLength(final long length) {
COSObject obj = getKey(ASAtom.LENGTH);
obj.setInteger(length);
if (obj.isIndirect().booleanValue()) {
if (obj.isIndirect()) {
obj = COSIndirect.construct(obj);
setKey(ASAtom.LENGTH, obj);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class COSFilterAESDecryptionDefault extends ASBufferedInFilter {

private SecretKey key;
private IvParameterSpec initializingVector;
private Cipher aes;
private final Cipher aes;
private boolean isDecryptFinished;
private int decryptedPointer;
private byte[] decryptedBytes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/
public class COSFilterASCII85Decode extends ASBufferedInFilter {

private COSFilterASCIIReader reader;
private final COSFilterASCIIReader reader;
private byte[] fourBytes = new byte[4];
private int fourBytesPointer = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class COSFilterASCIIHexDecode extends ASBufferedInFilter {

private final static byte WS = 17;
public final static byte ER = 127;
private COSFilterASCIIReader reader;
private final COSFilterASCIIReader reader;

private final static byte[] LO_HEX_TABLE = {
WS, ER, ER, ER, ER, ER, ER, ER, ER, WS, WS, ER, WS, WS, ER, ER, // 0 - 15
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/
public class COSFilterFlateDecode extends ASBufferedInFilter {

private Inflater inflater;
private final Inflater inflater;
private int bufferSize;

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/verapdf/cos/filters/COSFilterLZWDecode.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
*/
public class COSFilterLZWDecode extends ASBufferedInFilter {

private Logger LOGGER = Logger.getLogger(COSFilterLZWDecode.class.getCanonicalName());
private final Logger LOGGER = Logger.getLogger(COSFilterLZWDecode.class.getCanonicalName());

private static final int CLEAR_TABLE_MARKER = 256;
private static final int EOD = 257;
Expand All @@ -61,7 +61,7 @@ public class COSFilterLZWDecode extends ASBufferedInFilter {
private List<byte[]> lzwTable;
private byte[] leftoverData;
private int codeLengthBits = 9;
private int earlyChange;
private final int earlyChange;
private long thisWord = -1;
private long previousWord = -1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
*/
public class COSFilterRegistry {

private static Map<ASAtom, IASFilterFactory> registeredFactories;
private static final Map<ASAtom, IASFilterFactory> registeredFactories;
private static final Logger LOGGER = Logger.getLogger(COSFilterRegistry.class.getCanonicalName());

static {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/verapdf/cos/visitor/COSCopier.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
public class COSCopier implements IVisitor {

private COSObject copy;
private final COSObject copy;

public COSCopier(COSObject copy) {
this.copy = copy;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/verapdf/cos/visitor/IndirectWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
public class IndirectWriter extends Writer {

private Map<COSKey, COSKey> renum;
private final Map<COSKey, COSKey> renum;

public IndirectWriter(COSDocument document, String filename, boolean append,
long indirectOffset) throws IOException {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/verapdf/cos/visitor/Writer.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public class Writer implements IVisitor {
private static final Logger LOGGER = Logger.getLogger(Writer.class.getCanonicalName());

protected InternalOutputStream os;
private long incrementalOffset;
private final long incrementalOffset;
protected COSXRefInfo info;

protected COSDocument document;
protected final COSDocument document;

protected List<COSKey> toWrite;
protected List<COSKey> written;
Expand Down Expand Up @@ -242,7 +242,7 @@ private static long getASInputStreamLength(ASInputStream stream) throws IOExcept
// That is the case of unfiltered stream
return ((SeekableInputStream) stream).getStreamLength();
} else {
// That is the case of fitered stream. Optimization can be reached
// That is the case of filtered stream. Optimization can be reached
// if decoded data is stored in memory and not thrown away.
stream.reset();
byte[] buf = new byte[ASBufferedInFilter.BF_BUFFER_SIZE];
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/verapdf/cos/xref/COSXRefInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class COSXRefInfo {

private long startXRef;
private COSXRefSection xref;
private COSTrailer trailer;
private final COSTrailer trailer;

/**
* Creates empty COSXrefInfo object.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/verapdf/cos/xref/COSXRefSection.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
public class COSXRefSection {

private Map<Integer, COSXRefEntry> entries;
private final Map<Integer, COSXRefEntry> entries;

public COSXRefSection() {
this.entries = new TreeMap<>();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/verapdf/external/ICCProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ public Long getNumberOfColorants() {
public double[] getRange() {
COSObject rangeObject = getObject().getKey(ASAtom.RANGE);
if (rangeObject != null && rangeObject.getType() == COSObjType.COS_ARRAY) {
int size = rangeObject.size().intValue();
int size = rangeObject.size();
Long estimatedSize = getNumberOfColorants();
if (estimatedSize != null && size != estimatedSize.intValue()*2) {
LOGGER.log(Level.FINE, "Range array doesn't consist of " + estimatedSize.intValue()*2 + " elements");
Expand All @@ -529,7 +529,7 @@ public double[] getRange() {
LOGGER.log(Level.FINE, "Range array contains non number value");
return null;
}
res[i] = number.getReal().doubleValue();
res[i] = number.getReal();
}
return res;
}
Expand Down
Loading

0 comments on commit fbccb64

Please sign in to comment.