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 #1392

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 @@ -92,7 +92,7 @@ public boolean equals(Object obj) {

@Override
public int hashCode() {
return Objects.hash(Long.valueOf(this.start), Long.valueOf(this.finish));
return Objects.hash(this.start, this.finish);
}

@Override
Expand Down Expand Up @@ -122,8 +122,8 @@ public static String getStringDuration(final long difference) {
long millis = difference % msInSec;

try (Formatter formatter = new Formatter()) {
formatter.format("%02d:%02d:%02d.%03d", Long.valueOf(hours), Long.valueOf(minutes), Long.valueOf(seconds), //$NON-NLS-1$
Long.valueOf(millis));
formatter.format("%02d:%02d:%02d.%03d", hours, minutes, seconds, //$NON-NLS-1$
millis);
return formatter.toString();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
*/
@XmlRootElement(name = "componentDetails")
class ComponentDetailsImpl implements ComponentDetails {
private final static URI defaultId = URI.create("http://component.verapdf.org#default");
private final static ComponentDetailsImpl defaultInstance = new ComponentDetailsImpl();
private static final URI defaultId = URI.create("http://component.verapdf.org#default");
private static final ComponentDetailsImpl defaultInstance = new ComponentDetailsImpl();
@XmlAttribute
private final URI id;
@XmlAttribute
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/verapdf/core/JAXBCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
public class JAXBCollection<T>
{
@XmlAnyElement (lax = true)
private List<T> items;
private final List<T> items;

public JAXBCollection(Collection<T> contents)
{
Expand All @@ -75,7 +75,7 @@ public JAXBCollection(Collection<T> contents)

public JAXBCollection()
{
this(new ArrayList<T>());
this(new ArrayList<>());
}

public List<T> getItems()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class MapBackedDirectory<K, V> implements Directory<K, V> {
* Creates an empty directory backed by an empty Map
*/
public MapBackedDirectory() {
this(Collections.<K, V>emptyMap());
this(Collections.emptyMap());
}
/**
* @param map
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/org/verapdf/core/MapBackedRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class MapBackedRegistry<K, V> extends MapBackedDirectory<K, V> implements
* Creates an empty registry instance, initialised with an empty map
*/
public MapBackedRegistry() {
this(new HashMap<K, V>());
this(new HashMap<>());
}

/**
Expand Down Expand Up @@ -124,8 +124,8 @@ public V updateItem(final K key, final V value) {
*/
@Override
public void updateItems(final Map<K, V> itemMap) {
for (K key : itemMap.keySet()) {
updateItem(key, itemMap.get(key));
for (Map.Entry<K, V> entry : itemMap.entrySet()) {
updateItem(entry.getKey(), entry.getValue());
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/verapdf/core/XmlSerialiser.java
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ protected static <T> JAXBElement<?> createCollectionElement(String rootName, Col

private static Marshaller marshaller(JAXBContext ctx, boolean format, boolean fragment) throws JAXBException {
Marshaller m = ctx.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.valueOf(format));
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, format);
if (fragment) {
m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public File mapFile(final File orig) throws VeraPDFException {
return doMapFile(orig);
}

abstract protected File doMapFile(final File orig) throws VeraPDFException;
protected abstract File doMapFile(final File orig) throws VeraPDFException;

protected static String addPrefixAndSuffix(final File orig, final FileOutputMapper mapper) {
if (orig == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

final class RelativeDirectoryMapper extends AbstractFileOutputMapper {
static final String defaultRelativePath = ".";
private final static RelativeDirectoryMapper defaultInstance = new RelativeDirectoryMapper();
private static final RelativeDirectoryMapper defaultInstance = new RelativeDirectoryMapper();
private final String relDirPath;

private RelativeDirectoryMapper() {
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/java/org/verapdf/core/utils/VersioningMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
*/

final class VersioningMapper implements FileOutputMapper {
private final static String verPrefixOpen = "_("; //$NON-NLS-1$
private final static String verPrefixClose = ")"; //$NON-NLS-1$
final static VersioningMapper defaultInstance = new VersioningMapper();
private static final String verPrefixOpen = "_("; //$NON-NLS-1$
private static final String verPrefixClose = ")"; //$NON-NLS-1$
static final VersioningMapper defaultInstance = new VersioningMapper();
protected final FileOutputMapper mapper;

private VersioningMapper() {
Expand Down Expand Up @@ -75,9 +75,9 @@ private static File newVersion(final File orig) {
int maxVersion = -1;
for (File version : getVersions(orig)) {
int vers = getVersion(orig, version);
maxVersion = (vers > maxVersion) ? vers : maxVersion;
maxVersion = Math.max(vers, maxVersion);
}
Integer version = Integer.valueOf(maxVersion + 1);
Integer version = maxVersion + 1;
String versionedName = String.format("%s%d%s", verStart(orig), version, verEnd(orig)); //$NON-NLS-1$
return new File(orig.getParentFile(), versionedName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public abstract class AbstractFeaturesExtractor {
}

public final void initialize(ExtractorDetails initialDetails) {
initialize(initialDetails, Collections.<String, String>emptyMap());
initialize(initialDetails, Collections.emptyMap());
}

public final void initialize(ExtractorDetails initialDetails, Map<String, String> initialAttributes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void addNewFeatureTree(FeatureObjectType type, FeatureTreeNode root) {
*/
public List<FeatureTreeNode> getFeatureTreesForType(FeatureObjectType type) {
FeaturesStructure list = this.collection.get(type);
return (list == null || list.list == null) ? Collections.<FeatureTreeNode>emptyList() : list.list;
return (list == null || list.list == null) ? Collections.emptyList() : list.list;
}

/**
Expand Down Expand Up @@ -97,10 +97,10 @@ public void addNewError(FeatureObjectType type, String errorID) {
*/
public List<String> getErrorsForType(FeatureObjectType type) {
FeaturesStructure list = this.collection.get(type);
return (list == null || list.errors == null) ? Collections.<String>emptyList() : list.errors;
return (list == null || list.errors == null) ? Collections.emptyList() : list.errors;
}

private class FeaturesStructure {
private static class FeaturesStructure {
List<FeatureTreeNode> list;
List<String> errors;

Expand All @@ -116,8 +116,8 @@ public boolean equals(Object o) {

FeaturesStructure that = (FeaturesStructure) o;

if (list != null ? !list.equals(that.list) : that.list != null) return false;
return errors != null ? errors.equals(that.errors) : that.errors == null;
if (!Objects.equals(list, that.list)) return false;
return Objects.equals(errors, that.errors);

}

Expand All @@ -136,7 +136,7 @@ public boolean equals(Object o) {

FeatureExtractionResult that = (FeatureExtractionResult) o;

return collection != null ? collection.equals(that.collection) : that.collection == null;
return Objects.equals(collection, that.collection);

}

Expand Down
12 changes: 4 additions & 8 deletions core/src/main/java/org/verapdf/features/FeaturesReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public FeaturesReporter(FeatureExtractorConfig config, List<AbstractFeaturesExtr
}

public FeaturesReporter(FeatureExtractorConfig config) {
this(config, Collections.<AbstractFeaturesExtractor>emptyList());
this(config, Collections.emptyList());
}

/**
Expand All @@ -73,11 +73,7 @@ public FeaturesReporter(FeatureExtractorConfig config) {
* @param extractor object for extract custom features
*/
private void registerFeaturesExtractor(AbstractFeaturesExtractor extractor) {
if (featuresExtractors.get(extractor.getType()) == null) {
featuresExtractors.put(extractor.getType(), new ArrayList<AbstractFeaturesExtractor>());
}

featuresExtractors.get(extractor.getType()).add(extractor);
featuresExtractors.computeIfAbsent(extractor.getType(), k -> new ArrayList<>()).add(extractor);
}

/**
Expand Down Expand Up @@ -127,13 +123,13 @@ public void report(FeaturesObject obj) {
}
}

} catch (FeatureParsingException ignore) {
} catch (FeatureParsingException exception) {
// The method logic should ensure this never happens, so if it does
// it's catastrophic. We'll throw an IllegalStateException with this
// as a cause. The only time it's ignored is when the unthinkable
// happens
throw new IllegalStateException(
"FeaturesReporter.report() illegal state.", ignore);
"FeaturesReporter.report() illegal state.", exception);
// This exception occurs when wrong node creates for feature tree.
// The logic of the method guarantees this doesn't occur.
}
Expand Down
24 changes: 12 additions & 12 deletions core/src/main/java/org/verapdf/features/FontFeaturesData.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,14 @@ public static final class Builder {
private Double italicAngle = null;
private Double ascent = null;
private Double descent = null;
private Double leading = Double.valueOf(0.);
private Double leading = 0.;
private Double capHeight = null;
private Double xHeight = Double.valueOf(0.);
private Double xHeight = 0.;
private Double stemV = null;
private Double stemH = Double.valueOf(0.);
private Double avgWidth = Double.valueOf(0.);
private Double maxWidth = Double.valueOf(0.);
private Double missingWidth = Double.valueOf(0.);
private Double stemH = 0.;
private Double avgWidth = 0.;
private Double maxWidth = 0.;
private Double missingWidth = 0.;
private String charSet = null;

public Builder(InputStream stream) {
Expand Down Expand Up @@ -340,7 +340,7 @@ public Builder leading(Double leading) {
if (leading != null) {
this.leading = leading;
} else {
this.leading = Double.valueOf(0.0);
this.leading = 0.0;
}
return this;
}
Expand All @@ -354,7 +354,7 @@ public Builder xHeight(Double xHeight) {
if (xHeight != null) {
this.xHeight = xHeight;
} else {
this.xHeight = Double.valueOf(0.0);
this.xHeight = 0.0;
}
return this;
}
Expand All @@ -368,7 +368,7 @@ public Builder stemH(Double stemH) {
if (stemH != null) {
this.stemH = stemH;
} else {
this.stemH = Double.valueOf(0.0);
this.stemH = 0.0;
}
return this;
}
Expand All @@ -377,7 +377,7 @@ public Builder avgWidth(Double avgWidth) {
if (avgWidth != null) {
this.avgWidth = avgWidth;
} else {
this.avgWidth = Double.valueOf(0.0);
this.avgWidth = 0.0;
}
return this;
}
Expand All @@ -386,7 +386,7 @@ public Builder maxWidth(Double maxWidth) {
if (maxWidth != null) {
this.maxWidth = maxWidth;
} else {
this.maxWidth = Double.valueOf(0.0);
this.maxWidth = 0.0;
}
return this;
}
Expand All @@ -395,7 +395,7 @@ public Builder missingWidth(Double missingWidth) {
if (missingWidth != null) {
this.missingWidth = missingWidth;
} else {
this.missingWidth = Double.valueOf(0.0);
this.missingWidth = 0.0;
}
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public static class Filter implements Closeable {

Filter(String name, Map<String, String> properties, InputStream stream) {
this.name = name;
this.properties = properties == null ? new HashMap<String, String>() : new HashMap<>(properties);
this.properties = properties == null ? new HashMap<>() : new HashMap<>(properties);
this.stream = stream;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
*/
public class SignatureFeaturesData extends FeaturesData {

private String filter;
private String subFilter;
private String name;
private Calendar signDate;
private String location;
private String reason;
private String contactInfo;
private final String filter;
private final String subFilter;
private final String name;
private final Calendar signDate;
private final String location;
private final String reason;
private final String contactInfo;

public SignatureFeaturesData(InputStream stream, String filter, String subFilter, String name, Calendar signDate, String location, String reason, String contactInfo) {
super(stream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public FeaturesData getData() {
builder.checkSum(efAdapter.getCheckSum());
Long size = efAdapter.getSize();
if (size != null) {
builder.size(Integer.valueOf(size.intValue()));
builder.size(size.intValue());
}
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public enum FeatureType {
STRING(PRESENT, NOT_PRESENT, IS_EQUAL,
NOT_EQUAL, STARTS_WITH, /*ENDS_WITH,*/ CONTAINS);

private EnumSet<SchematronOperation> legalOperations;
private final EnumSet<SchematronOperation> legalOperations;

FeatureType(SchematronOperation op, SchematronOperation... operations) {
this.legalOperations = EnumSet.of(op, operations);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*/
public abstract class FeaturesObject {

protected FeaturesObjectAdapter adapter;
protected final FeaturesObjectAdapter adapter;
protected final List<String> errors = new ArrayList<>();

FeaturesObject(FeaturesObjectAdapter adapter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* @author Maksim Bezrukov
*/
public final class FeaturesStructureContainer {
private static Map<FeatureObjectType, List<Feature>> featuresStructure =
private static final Map<FeatureObjectType, List<Feature>> featuresStructure =
new EnumMap<>(FeatureObjectType.class);

static {
Expand Down Expand Up @@ -64,6 +64,6 @@ private FeaturesStructureContainer() {

public static List<Feature> getFeaturesListForType(FeatureObjectType type) {
List<Feature> res = featuresStructure.get(type);
return res == null ? Collections.<Feature>emptyList() : Collections.unmodifiableList(res);
return res == null ? Collections.emptyList() : Collections.unmodifiableList(res);
}
}
Loading
Loading