Intellij suggested changes from static code analysis.

This commit is contained in:
Koen De Groote 2020-01-28 16:18:07 +01:00
parent b6773f6983
commit aff31ebd1b
8 changed files with 46 additions and 47 deletions

View File

@ -129,8 +129,7 @@ public class Time {
* @see #toString(String) * @see #toString(String)
*/ */
public String toString() { public String toString() {
return "" + getMinutes() + ":" return getMinutes() + ":" + (getSeconds() < 10 ? "0" : "") + getSeconds();
+ (getSeconds() < 10 ? "0" : "") + getSeconds();
} }
/** /**

View File

@ -44,12 +44,12 @@ import java.util.Vector;
* The format is expressed in a string as follows: * The format is expressed in a string as follows:
* <DL> * <DL>
* <DD>m (or any multiple of m's) * <DD>m (or any multiple of m's)
* <DT>the minutes part (padded with 0's, if number has less digits than * <DT>the minutes part (padded with 0's, if number has less digits than
* the number of m's) * the number of m's)
* m -&gt; 0,1,...,59,60,61,... * m -&gt; 0,1,...,59,60,61,...
* mm -&gt; 00,01,...,59,60,61,... * mm -&gt; 00,01,...,59,60,61,...
* <DD>s or ss * <DD>s or ss
* <DT>the seconds part (padded with 0's, if number has less digits than * <DT>the seconds part (padded with 0's, if number has less digits than
* the number of s's) * the number of s's)
* s -&gt; 0,1,...,59 * s -&gt; 0,1,...,59
* ss -&gt; 00,01,...,59 * ss -&gt; 00,01,...,59
@ -62,7 +62,7 @@ import java.util.Vector;
* <P> * <P>
* Known bugs: * Known bugs:
* <P> * <P>
* The last character in the formatString is not escaped, while it should be. * The last character in the formatString is not escaped, while it should be.
* The first character after an escaped character is escaped while is shouldn't * The first character after an escaped character is escaped while is shouldn't
* be. * be.
* <P> * <P>
@ -81,15 +81,15 @@ public class TimeFormat extends Format {
final static String SECOND = "s"; final static String SECOND = "s";
final static String TIME = "S"; final static String TIME = "S";
final static String ESCAPE = "\\"; final static String ESCAPE = "\\";
/** /**
* The default time format * The default time format
*/ */
private final static TimeFormat DEFAULT_FORMAT = new TimeFormat("m:ss"); private final static TimeFormat DEFAULT_FORMAT = new TimeFormat("m:ss");
protected String formatString = null; protected String formatString = null;
/** /**
* Main method for testing ONLY * Main method for testing ONLY
*/ */
@ -122,7 +122,7 @@ public class TimeFormat extends Format {
} }
else else
time = new Time(); time = new Time();
System.out.println("Time is \"" + out.format(time) + System.out.println("Time is \"" + out.format(time) +
"\" according to format \"" + out.formatString + "\""); "\" according to format \"" + out.formatString + "\"");
} }
@ -147,18 +147,18 @@ public class TimeFormat extends Format {
String previous = null; String previous = null;
String current = null; String current = null;
int previousCount = 0; int previousCount = 0;
while (tok.hasMoreElements()) { while (tok.hasMoreElements()) {
current = tok.nextToken(); current = tok.nextToken();
if (previous != null && previous.equals(ESCAPE)) { if (previous != null && previous.equals(ESCAPE)) {
// Handle escaping of s, S or m // Handle escaping of s, S or m
current = ((current != null) ? current : "") current = ((current != null) ? current : "")
+ (tok.hasMoreElements() ? tok.nextToken() : ""); + (tok.hasMoreElements() ? tok.nextToken() : "");
previous = null; previous = null;
previousCount = 0; previousCount = 0;
} }
// Skip over first, // Skip over first,
// or if current is the same, increase count, and try again // or if current is the same, increase count, and try again
if (previous == null || previous.equals(current)) { if (previous == null || previous.equals(current)) {
@ -173,12 +173,12 @@ public class TimeFormat extends Format {
formatter.add(new SecondsFormatter(previousCount)); formatter.add(new SecondsFormatter(previousCount));
else if (previous.equals(TIME)) else if (previous.equals(TIME))
formatter.add(new SecondsFormatter(-1)); formatter.add(new SecondsFormatter(-1));
else else
formatter.add(new TextFormatter(previous)); formatter.add(new TextFormatter(previous));
previousCount = 1; previousCount = 1;
previous = current; previous = current;
} }
} }
@ -197,7 +197,7 @@ public class TimeFormat extends Format {
// Debug // Debug
/* /*
for (int i = 0; i < formatter.size(); i++) { for (int i = 0; i < formatter.size(); i++) {
System.out.println("Formatter " + formatter.get(i).getClass() System.out.println("Formatter " + formatter.get(i).getClass()
+ ": length=" + ((TimeFormatter) formatter.get(i)).digits); + ": length=" + ((TimeFormatter) formatter.get(i)).digits);
} }
*/ */
@ -206,7 +206,7 @@ public class TimeFormat extends Format {
} }
/** /**
* DUMMY IMPLEMENTATION!! * DUMMY IMPLEMENTATION!!
* Not locale specific. * Not locale specific.
*/ */
@ -259,9 +259,9 @@ public class TimeFormat extends Format {
/** DUMMY IMPLEMENTATION!! */ /** DUMMY IMPLEMENTATION!! */
public Object parseObject(String pStr, ParsePosition pStatus) { public Object parseObject(String pStr, ParsePosition pStatus) {
Time t = parse(pStr); Time t = parse(pStr);
pStatus.setIndex(pStr.length()); // Not 100% pStatus.setIndex(pStr.length()); // Not 100%
return t; return t;
} }
@ -270,7 +270,7 @@ public class TimeFormat extends Format {
* <p> * <p>
* Will bug on some formats. It's safest to always use delimiters between * Will bug on some formats. It's safest to always use delimiters between
* the minutes (m) and seconds (s) part. * the minutes (m) and seconds (s) part.
* *
*/ */
public Time parse(String pStr) { public Time parse(String pStr) {
Time time = new Time(); Time time = new Time();
@ -286,7 +286,7 @@ public class TimeFormat extends Format {
&& (pos + skip < pStr.length()) ; i++) { && (pos + skip < pStr.length()) ; i++) {
// Go to next offset // Go to next offset
pos += skip; pos += skip;
if (formatter[i] instanceof MinutesFormatter) { if (formatter[i] instanceof MinutesFormatter) {
// Parse MINUTES // Parse MINUTES
if ((i + 1) < formatter.length if ((i + 1) < formatter.length
@ -327,9 +327,9 @@ public class TimeFormat extends Format {
else { else {
// Cannot possibly know how long? // Cannot possibly know how long?
skip = 0; skip = 0;
continue; continue;
} }
// Get seconds // Get seconds
sec = Integer.parseInt(pStr.substring(pos, skip)); sec = Integer.parseInt(pStr.substring(pos, skip));
// System.out.println("Only seconds: " + sec); // System.out.println("Only seconds: " + sec);
@ -343,7 +343,7 @@ public class TimeFormat extends Format {
&& formatter[i + 1] instanceof TextFormatter) { && formatter[i + 1] instanceof TextFormatter) {
// Skip until next format element // Skip until next format element
skip = pStr.indexOf(((TextFormatter) formatter[i + 1]).text, pos); skip = pStr.indexOf(((TextFormatter) formatter[i + 1]).text, pos);
} }
else if ((i + 1) >= formatter.length) { else if ((i + 1) >= formatter.length) {
// Skip until end of string // Skip until end of string
@ -359,7 +359,7 @@ public class TimeFormat extends Format {
else if (formatter[i] instanceof TextFormatter) { else if (formatter[i] instanceof TextFormatter) {
skip = formatter[i].digits; skip = formatter[i].digits;
} }
} }
// Set the minutes part if we should // Set the minutes part if we should
@ -390,7 +390,7 @@ class SecondsFormatter extends TimeFormatter {
SecondsFormatter(int pDigits) { SecondsFormatter(int pDigits) {
digits = pDigits; digits = pDigits;
} }
String format(Time t) { String format(Time t) {
// Negative number of digits, means all seconds, no padding // Negative number of digits, means all seconds, no padding
if (digits < 0) { if (digits < 0) {
@ -404,7 +404,7 @@ class SecondsFormatter extends TimeFormatter {
// Else return it with leading 0's // Else return it with leading 0's
//return StringUtil.formatNumber(t.getSeconds(), digits); //return StringUtil.formatNumber(t.getSeconds(), digits);
return StringUtil.pad("" + t.getSeconds(), digits, "0", true); return StringUtil.pad(String.valueOf(t.getSeconds()), digits, "0", true);
} }
} }
@ -425,7 +425,7 @@ class MinutesFormatter extends TimeFormatter {
// Else return it with leading 0's // Else return it with leading 0's
//return StringUtil.formatNumber(t.getMinutes(), digits); //return StringUtil.formatNumber(t.getMinutes(), digits);
return StringUtil.pad("" + t.getMinutes(), digits, "0", true); return StringUtil.pad(String.valueOf(t.getMinutes()), digits, "0", true);
} }
} }

View File

@ -200,11 +200,10 @@ public final class TIFFUtilities {
} }
public static List<TIFFPage> getPages(ImageInputStream imageInput) throws IOException { public static List<TIFFPage> getPages(ImageInputStream imageInput) throws IOException {
ArrayList<TIFFPage> pages = new ArrayList<TIFFPage>();
CompoundDirectory IFDs = (CompoundDirectory) new TIFFReader().read(imageInput); CompoundDirectory IFDs = (CompoundDirectory) new TIFFReader().read(imageInput);
int pageCount = IFDs.directoryCount(); final int pageCount = IFDs.directoryCount();
List<TIFFPage> pages = new ArrayList<>(pageCount);
for (int pageIndex = 0; pageIndex < pageCount; pageIndex++) { for (int pageIndex = 0; pageIndex < pageCount; pageIndex++) {
pages.add(new TIFFPage(IFDs.getDirectory(pageIndex), imageInput)); pages.add(new TIFFPage(IFDs.getDirectory(pageIndex), imageInput));
} }

View File

@ -84,7 +84,7 @@ abstract class DIBImageReader extends ImageReaderBase {
protected void resetMembers() { protected void resetMembers() {
directory = null; directory = null;
headers.clear(); headers.clear();
descriptors.clear(); descriptors.clear();
@ -551,7 +551,7 @@ abstract class DIBImageReader extends ImageReaderBase {
if (abortRequested()) { if (abortRequested()) {
processReadAborted(); processReadAborted();
break; break;
} }
processImageProgress(100 * y / (float) pBitmap.getHeight()); processImageProgress(100 * y / (float) pBitmap.getHeight());
} }
@ -591,7 +591,7 @@ abstract class DIBImageReader extends ImageReaderBase {
return directory.getEntry(pImageIndex); return directory.getEntry(pImageIndex);
} }
/// Test code below, ignore.. :-) /// Test code below, ignore.. :-)
public static void main(final String[] pArgs) throws IOException { public static void main(final String[] pArgs) throws IOException {
if (pArgs.length == 0) { if (pArgs.length == 0) {
@ -701,10 +701,10 @@ abstract class DIBImageReader extends ImageReaderBase {
} }
}); });
button.setText("" + image.getWidth() + "x" + button.setText(image.getWidth() + "x" +
image.getHeight() + ": " image.getHeight() + ": "
+ ((image.getColorModel() instanceof IndexColorModel) ? + ((image.getColorModel() instanceof IndexColorModel) ?
"" + ((IndexColorModel) image.getColorModel()).getMapSize() : String.valueOf(((IndexColorModel) image.getColorModel()).getMapSize()) :
"TrueColor")); "TrueColor"));
pParent.add(button); pParent.add(button);

View File

@ -60,10 +60,10 @@ public abstract class AbstractEntry implements Entry {
} }
/** /**
* Returns a format-native identifier. * Returns a format-native identifier.
* For example {@code "2:00"} for IPTC "Record Version" field, or {@code "0x040c"} for PSD "Thumbnail" resource. * For example {@code "2:00"} for IPTC "Record Version" field, or {@code "0x040c"} for PSD "Thumbnail" resource.
* This default implementation simply returns {@code String.valueOf(getIdentifier())}. * This default implementation simply returns {@code String.valueOf(getIdentifier())}.
* *
* @return a format-native identifier. * @return a format-native identifier.
*/ */
protected String getNativeIdentifier() { protected String getNativeIdentifier() {
@ -174,7 +174,7 @@ public abstract class AbstractEntry implements Entry {
} }
AbstractEntry other = (AbstractEntry) pOther; AbstractEntry other = (AbstractEntry) pOther;
return identifier.equals(other.identifier) && ( return identifier.equals(other.identifier) && (
value == null && other.value == null || value != null && valueEquals(other) value == null && other.value == null || value != null && valueEquals(other)
); );

View File

@ -144,7 +144,7 @@ public final class XMPReader extends MetadataReader {
parseAttributesForKnownElements(subsubdirs, node); parseAttributesForKnownElements(subsubdirs, node);
if (!subsubdirs.isEmpty()) { if (!subsubdirs.isEmpty()) {
List<Entry> entries = new ArrayList<Entry>(); List<Entry> entries = new ArrayList<>(subsubdirs.size());
for (Map.Entry<String, List<Entry>> entry : subsubdirs.entrySet()) { for (Map.Entry<String, List<Entry>> entry : subsubdirs.entrySet()) {
entries.addAll(entry.getValue()); entries.addAll(entry.getValue());
@ -161,7 +161,7 @@ public final class XMPReader extends MetadataReader {
} }
} }
List<Directory> entries = new ArrayList<Directory>(); List<Directory> entries = new ArrayList<Directory>(subdirs.size());
// TODO: Should we still allow asking for a subdirectory by item id? // TODO: Should we still allow asking for a subdirectory by item id?
for (Map.Entry<String, List<Entry>> entry : subdirs.entrySet()) { for (Map.Entry<String, List<Entry>> entry : subdirs.entrySet()) {

View File

@ -340,7 +340,7 @@ public final class ThumbsDBImageReader extends ImageReaderBase {
// TODO: Rethink this... // TODO: Rethink this...
// Seems to be up to Windows and the installed programs what formats // Seems to be up to Windows and the installed programs what formats
// are supported... // are supported...
// Some thumbs are just icons, and it might be better to use ImageIO to create thumbs for these... :-/ // Some thumbs are just icons, and it might be better to use ImageIO to create thumbs for these... :-/
// At least this seems fine for now // At least this seems fine for now
String extension = FileUtil.getExtension(pFileName); String extension = FileUtil.getExtension(pFileName);
if (StringUtil.isEmpty(extension)) { if (StringUtil.isEmpty(extension)) {
@ -351,7 +351,7 @@ public final class ThumbsDBImageReader extends ImageReaderBase {
return !"psd".equals(extension) && !"svg".equals(extension) && catalog != null && catalog.getIndex(pFileName) != -1; return !"psd".equals(extension) && !"svg".equals(extension) && catalog != null && catalog.getIndex(pFileName) != -1;
} }
/// Test code below /// Test code below
public static void main(String[] pArgs) throws IOException { public static void main(String[] pArgs) throws IOException {
ThumbsDBImageReader reader = new ThumbsDBImageReader(); ThumbsDBImageReader reader = new ThumbsDBImageReader();
@ -421,7 +421,7 @@ public final class ThumbsDBImageReader extends ImageReaderBase {
return SIZE; return SIZE;
} }
}); });
label.setText("" + image.getWidth() + "x" + image.getHeight() + ": " + pName); label.setText(image.getWidth() + "x" + image.getHeight() + ": " + pName);
label.setToolTipText(image.toString()); label.setToolTipText(image.toString());
pParent.add(label); pParent.add(label);
} }

View File

@ -1144,10 +1144,11 @@ public final class TIFFImageMetadata extends AbstractMetadata {
throw new IIOInvalidTreeException("Expected \"TIFFIFD\" node", ifdNode); throw new IIOInvalidTreeException("Expected \"TIFFIFD\" node", ifdNode);
} }
List<Entry> entries = new ArrayList<>();
NodeList nodes = ifdNode.getChildNodes(); NodeList nodes = ifdNode.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) { final int size = nodes.getLength();
List<Entry> entries = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
entries.add(toEntry(nodes.item(i))); entries.add(toEntry(nodes.item(i)));
} }