This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-imaging.git


The following commit(s) were added to refs/heads/master by this push:
     new 336b79a  No need to nest in else.
336b79a is described below

commit 336b79a9e95eb6b1d651e357880246ba739073b5
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Fri Mar 5 14:16:26 2021 -0500

    No need to nest in else.
---
 .../org/apache/commons/imaging/ColorTools.java     |   3 +-
 .../commons/imaging/ImageWriteException.java       |  30 ++++---
 .../java/org/apache/commons/imaging/Imaging.java   |  47 ++++++----
 .../org/apache/commons/imaging/PixelDensity.java   |  18 ++--
 .../commons/imaging/common/BasicCParser.java       |   5 +-
 .../commons/imaging/common/RationalNumber.java     |   6 +-
 .../common/bytesource/ByteSourceInputStream.java   |  15 ++--
 .../imaging/common/itu_t4/T4AndT6Compression.java  |   3 +-
 .../imaging/formats/bmp/BmpImageParser.java        | 100 ++++++++++-----------
 .../imaging/formats/bmp/PixelParserRgb.java        |  12 ++-
 .../imaging/formats/bmp/PixelParserRle.java        |   8 +-
 .../imaging/formats/gif/GifImageParser.java        |   5 +-
 .../commons/imaging/formats/icns/IcnsDecoder.java  |  14 ++-
 .../imaging/formats/jpeg/decoder/JpegDecoder.java  |   5 +-
 .../imaging/formats/pcx/PcxImageParser.java        |  59 ++++++------
 .../commons/imaging/formats/png/BitParser.java     |   6 +-
 .../commons/imaging/formats/png/PngColorType.java  |   6 +-
 .../imaging/formats/png/PngImageParser.java        |   6 +-
 .../commons/imaging/formats/png/PngWriter.java     |   3 +-
 .../png/scanlinefilters/ScanlineFilterPaeth.java   |   6 +-
 .../commons/imaging/formats/pnm/FileInfo.java      |   3 +-
 .../commons/imaging/formats/pnm/PamFileInfo.java   |   3 +-
 .../commons/imaging/formats/pnm/PgmFileInfo.java   |   3 +-
 .../imaging/formats/pnm/PnmImageParser.java        |  27 ++++--
 .../commons/imaging/formats/pnm/PpmFileInfo.java   |   3 +-
 .../imaging/formats/tiff/TiffDirectory.java        |  12 +--
 .../commons/imaging/formats/tiff/TiffElement.java  |   6 +-
 .../commons/imaging/formats/tiff/TiffField.java    |  63 ++++++++-----
 .../imaging/formats/tiff/TiffImageMetadata.java    |  19 ++--
 .../commons/imaging/formats/tiff/TiffReader.java   |   6 +-
 .../commons/imaging/formats/tiff/TiffTags.java     |   9 +-
 .../formats/tiff/datareaders/DataReaderStrips.java |   3 +-
 .../formats/tiff/fieldtypes/FieldTypeAscii.java    |  35 ++++----
 .../formats/tiff/fieldtypes/FieldTypeByte.java     |   6 +-
 .../formats/tiff/fieldtypes/FieldTypeDouble.java   |  19 ++--
 .../formats/tiff/fieldtypes/FieldTypeFloat.java    |  19 ++--
 .../formats/tiff/fieldtypes/FieldTypeLong.java     |  19 ++--
 .../formats/tiff/fieldtypes/FieldTypeRational.java |  27 +++---
 .../formats/tiff/fieldtypes/FieldTypeShort.java    |  19 ++--
 .../floatingpoint/PaletteEntryForValue.java        |   6 +-
 .../formats/tiff/taginfos/TagInfoGpsText.java      |   9 +-
 .../formats/tiff/write/TiffImageWriterBase.java    |   9 +-
 .../tiff/write/TiffImageWriterLossless.java        |  17 ++--
 .../formats/tiff/write/TiffOutputDirectory.java    |   6 +-
 .../imaging/formats/xpm/XpmImageParser.java        |  59 ++++++------
 .../imaging/palette/LongestAxisMedianCut.java      |   5 +-
 .../palette/MostPopulatedBoxesMedianCut.java       |   5 +-
 .../formats/jpeg/exif/MicrosoftTagTest.java        |   6 +-
 .../imaging/formats/tiff/TiffCcittTest.java        |   5 +-
 49 files changed, 432 insertions(+), 353 deletions(-)

diff --git a/src/main/java/org/apache/commons/imaging/ColorTools.java 
b/src/main/java/org/apache/commons/imaging/ColorTools.java
index 31a4582..c34c051 100644
--- a/src/main/java/org/apache/commons/imaging/ColorTools.java
+++ b/src/main/java/org/apache/commons/imaging/ColorTools.java
@@ -109,7 +109,8 @@ public class ColorTools {
             return new ComponentColorModel(cs, ccm.hasAlpha(),
                     ccm.isAlphaPremultiplied(), ccm.getTransparency(),
                     ccm.getTransferType());
-        } else if (colorModel instanceof DirectColorModel) {
+        }
+        if (colorModel instanceof DirectColorModel) {
             final DirectColorModel dcm = (DirectColorModel) colorModel;
 
             final int oldMask = dcm.getRedMask() | dcm.getGreenMask()
diff --git a/src/main/java/org/apache/commons/imaging/ImageWriteException.java 
b/src/main/java/org/apache/commons/imaging/ImageWriteException.java
index fae0e27..db8fde0 100644
--- a/src/main/java/org/apache/commons/imaging/ImageWriteException.java
+++ b/src/main/java/org/apache/commons/imaging/ImageWriteException.java
@@ -39,26 +39,34 @@ public class ImageWriteException extends ImagingException {
     private static String getType(final Object value) {
         if (value == null) {
             return "null";
-        } else if (value instanceof Object[]) {
+        }
+        if (value instanceof Object[]) {
             return "[Object[]: " + ((Object[]) value).length + "]";
-        } else if (value instanceof char[]) {
+        }
+        if (value instanceof char[]) {
             return "[char[]: " + ((char[]) value).length + "]";
-        } else if (value instanceof byte[]) {
+        }
+        if (value instanceof byte[]) {
             return "[byte[]: " + ((byte[]) value).length + "]";
-        } else if (value instanceof short[]) {
+        }
+        if (value instanceof short[]) {
             return "[short[]: " + ((short[]) value).length + "]";
-        } else if (value instanceof int[]) {
+        }
+        if (value instanceof int[]) {
             return "[int[]: " + ((int[]) value).length + "]";
-        } else if (value instanceof long[]) {
+        }
+        if (value instanceof long[]) {
             return "[long[]: " + ((long[]) value).length + "]";
-        } else if (value instanceof float[]) {
+        }
+        if (value instanceof float[]) {
             return "[float[]: " + ((float[]) value).length + "]";
-        } else if (value instanceof double[]) {
+        }
+        if (value instanceof double[]) {
             return "[double[]: " + ((double[]) value).length + "]";
-        } else if (value instanceof boolean[]) {
+        }
+        if (value instanceof boolean[]) {
             return "[boolean[]: " + ((boolean[]) value).length + "]";
-        } else {
-            return value.getClass().getName();
         }
+        return value.getClass().getName();
     }
 }
diff --git a/src/main/java/org/apache/commons/imaging/Imaging.java 
b/src/main/java/org/apache/commons/imaging/Imaging.java
index f0a04a7..b5b6f88 100644
--- a/src/main/java/org/apache/commons/imaging/Imaging.java
+++ b/src/main/java/org/apache/commons/imaging/Imaging.java
@@ -278,33 +278,47 @@ public final class Imaging {
             // } else if (b1 == 0x00 && b2 == 0x00) // too similar to TGA
             // {
             // return ImageFormat.IMAGE_FORMAT_ICO;
-            } else if (compareBytePair(MAGIC_NUMBERS_PNG, bytePair)) {
+            }
+            if (compareBytePair(MAGIC_NUMBERS_PNG, bytePair)) {
                 return ImageFormats.PNG;
-            } else if (compareBytePair(MAGIC_NUMBERS_JPEG, bytePair)) {
+            }
+            if (compareBytePair(MAGIC_NUMBERS_JPEG, bytePair)) {
                 return ImageFormats.JPEG;
-            } else if (compareBytePair(MAGIC_NUMBERS_BMP, bytePair)) {
+            }
+            if (compareBytePair(MAGIC_NUMBERS_BMP, bytePair)) {
                 return ImageFormats.BMP;
-            } else if (compareBytePair(MAGIC_NUMBERS_TIFF_MOTOROLA, bytePair)) 
{
+            }
+            if (compareBytePair(MAGIC_NUMBERS_TIFF_MOTOROLA, bytePair)) {
                 return ImageFormats.TIFF;
-            } else if (compareBytePair(MAGIC_NUMBERS_TIFF_INTEL, bytePair)) {
+            }
+            if (compareBytePair(MAGIC_NUMBERS_TIFF_INTEL, bytePair)) {
                 return ImageFormats.TIFF;
-            } else if (compareBytePair(MAGIC_NUMBERS_PSD, bytePair)) {
+            }
+            if (compareBytePair(MAGIC_NUMBERS_PSD, bytePair)) {
                 return ImageFormats.PSD;
-            } else if (compareBytePair(MAGIC_NUMBERS_PAM, bytePair)) {
+            }
+            if (compareBytePair(MAGIC_NUMBERS_PAM, bytePair)) {
                 return ImageFormats.PAM;
-            } else if (compareBytePair(MAGIC_NUMBERS_PBM_A, bytePair)) {
+            }
+            if (compareBytePair(MAGIC_NUMBERS_PBM_A, bytePair)) {
                 return ImageFormats.PBM;
-            } else if (compareBytePair(MAGIC_NUMBERS_PBM_B, bytePair)) {
+            }
+            if (compareBytePair(MAGIC_NUMBERS_PBM_B, bytePair)) {
                 return ImageFormats.PBM;
-            } else if (compareBytePair(MAGIC_NUMBERS_PGM_A, bytePair)) {
+            }
+            if (compareBytePair(MAGIC_NUMBERS_PGM_A, bytePair)) {
                 return ImageFormats.PGM;
-            } else if (compareBytePair(MAGIC_NUMBERS_PGM_B, bytePair)) {
+            }
+            if (compareBytePair(MAGIC_NUMBERS_PGM_B, bytePair)) {
                 return ImageFormats.PGM;
-            } else if (compareBytePair(MAGIC_NUMBERS_PPM_A, bytePair)) {
+            }
+            if (compareBytePair(MAGIC_NUMBERS_PPM_A, bytePair)) {
                 return ImageFormats.PPM;
-            } else if (compareBytePair(MAGIC_NUMBERS_PPM_B, bytePair)) {
+            }
+            if (compareBytePair(MAGIC_NUMBERS_PPM_B, bytePair)) {
                 return ImageFormats.PPM;
-            } else if (compareBytePair(MAGIC_NUMBERS_JBIG2_1, bytePair)) {
+            }
+            if (compareBytePair(MAGIC_NUMBERS_JBIG2_1, bytePair)) {
                 final int i3 = is.read();
                 final int i4 = is.read();
                 if ((i3 < 0) || (i4 < 0)) {
@@ -1551,11 +1565,10 @@ public final class Imaging {
                 break;
             }
         }
-        if (imageParser != null) {
-            imageParser.writeImage(src, os, params);
-        } else {
+        if (imageParser == null) {
             throw new ImageWriteException("Unknown Format: " + format);
         }
+        imageParser.writeImage(src, os, params);
     }
 
 }
diff --git a/src/main/java/org/apache/commons/imaging/PixelDensity.java 
b/src/main/java/org/apache/commons/imaging/PixelDensity.java
index 872eda7..2297d19 100644
--- a/src/main/java/org/apache/commons/imaging/PixelDensity.java
+++ b/src/main/java/org/apache/commons/imaging/PixelDensity.java
@@ -81,48 +81,42 @@ public final class PixelDensity {
     public double horizontalDensityInches() {
         if (isInInches()) {
             return horizontalDensity;
-        } else {
-            return horizontalDensity * PIXEL_PER_INCH / unitLength;
         }
+        return horizontalDensity * PIXEL_PER_INCH / unitLength;
     }
 
     public double verticalDensityInches() {
         if (isInInches()) {
             return verticalDensity;
-        } else {
-            return verticalDensity * PIXEL_PER_INCH / unitLength;
         }
+        return verticalDensity * PIXEL_PER_INCH / unitLength;
     }
 
     public double horizontalDensityMetres() {
         if (isInMetres()) {
             return horizontalDensity;
-        } else {
-            return horizontalDensity * PIXEL_PER_METRE / unitLength;
         }
+        return horizontalDensity * PIXEL_PER_METRE / unitLength;
     }
 
     public double verticalDensityMetres() {
         if (isInMetres()) {
             return verticalDensity;
-        } else {
-            return verticalDensity * PIXEL_PER_METRE / unitLength;
         }
+        return verticalDensity * PIXEL_PER_METRE / unitLength;
     }
 
     public double horizontalDensityCentimetres() {
         if (isInCentimetres()) {
             return horizontalDensity;
-        } else {
-            return horizontalDensity * PIXEL_PER_CENTIMETRE / unitLength;
         }
+        return horizontalDensity * PIXEL_PER_CENTIMETRE / unitLength;
     }
 
     public double verticalDensityCentimetres() {
         if (isInCentimetres()) {
             return verticalDensity;
-        } else {
-            return verticalDensity * PIXEL_PER_CENTIMETRE / unitLength;
         }
+        return verticalDensity * PIXEL_PER_CENTIMETRE / unitLength;
     }
 }
diff --git a/src/main/java/org/apache/commons/imaging/common/BasicCParser.java 
b/src/main/java/org/apache/commons/imaging/common/BasicCParser.java
index c9ebc48..572f019 100644
--- a/src/main/java/org/apache/commons/imaging/common/BasicCParser.java
+++ b/src/main/java/org/apache/commons/imaging/common/BasicCParser.java
@@ -70,12 +70,11 @@ public class BasicCParser {
                     break;
                 }
             } else if (inIdentifier) {
-                if (Character.isLetterOrDigit(c) || c == '_') {
-                    token.append((char) c);
-                } else {
+                if (!Character.isLetterOrDigit(c) && (c != '_')) {
                     is.unread(c);
                     return token.toString();
                 }
+                token.append((char) c);
             } else {
                 if (c == '"') {
                     token.append('"');
diff --git 
a/src/main/java/org/apache/commons/imaging/common/RationalNumber.java 
b/src/main/java/org/apache/commons/imaging/common/RationalNumber.java
index 639301a..89888c4 100644
--- a/src/main/java/org/apache/commons/imaging/common/RationalNumber.java
+++ b/src/main/java/org/apache/commons/imaging/common/RationalNumber.java
@@ -147,7 +147,8 @@ public class RationalNumber extends Number {
     public static RationalNumber valueOf(double value) {
         if (value >= Integer.MAX_VALUE) {
             return new RationalNumber(Integer.MAX_VALUE, 1);
-        } else if (value <= -Integer.MAX_VALUE) {
+        }
+        if (value <= -Integer.MAX_VALUE) {
             return new RationalNumber(-Integer.MAX_VALUE, 1);
         }
 
@@ -162,7 +163,8 @@ public class RationalNumber extends Number {
 
         if (value == 0) {
             return new RationalNumber(0, 1);
-        } else if (value >= 1) {
+        }
+        if (value >= 1) {
             final int approx = (int) value;
             if (approx < value) {
                 l = new RationalNumber(approx, 1);
diff --git 
a/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceInputStream.java
 
b/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceInputStream.java
index 902f8d6..837fbc4 100644
--- 
a/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceInputStream.java
+++ 
b/src/main/java/org/apache/commons/imaging/common/bytesource/ByteSourceInputStream.java
@@ -68,17 +68,17 @@ public class ByteSourceInputStream extends ByteSource {
         final int read = is.read(readBuffer);
         if (read < 1) {
             return null;
-        } else if (read < BLOCK_SIZE) {
+        }
+        if (read < BLOCK_SIZE) {
             // return a copy.
             final byte[] result = new byte[read];
             System.arraycopy(readBuffer, 0, result, 0, read);
             return new CacheBlock(result);
-        } else {
-            // return current buffer.
-            final byte[] result = readBuffer;
-            readBuffer = null;
-            return new CacheBlock(result);
         }
+        // return current buffer.
+        final byte[] result = readBuffer;
+        readBuffer = null;
+        return new CacheBlock(result);
     }
 
     private CacheBlock getFirstBlock() throws IOException {
@@ -126,7 +126,8 @@ public class ByteSourceInputStream extends ByteSource {
             if ((off < 0) || (off > array.length) || (len < 0)
                     || ((off + len) > array.length) || ((off + len) < 0)) {
                 throw new IndexOutOfBoundsException();
-            } else if (len == 0) {
+            }
+            if (len == 0) {
                 return 0;
             }
 
diff --git 
a/src/main/java/org/apache/commons/imaging/common/itu_t4/T4AndT6Compression.java
 
b/src/main/java/org/apache/commons/imaging/common/itu_t4/T4AndT6Compression.java
index 4a5c6a3..ddc856e 100644
--- 
a/src/main/java/org/apache/commons/imaging/common/itu_t4/T4AndT6Compression.java
+++ 
b/src/main/java/org/apache/commons/imaging/common/itu_t4/T4AndT6Compression.java
@@ -660,7 +660,8 @@ public final class T4AndT6Compression {
             if (entries[middle].value <= value
                     && ((middle + 1) >= entries.length || value < 
entries[middle + 1].value)) {
                 return entries[middle];
-            } else if (entries[middle].value > value) {
+            }
+            if (entries[middle].value > value) {
                 last = middle - 1;
             } else {
                 first = middle + 1;
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/bmp/BmpImageParser.java 
b/src/main/java/org/apache/commons/imaging/formats/bmp/BmpImageParser.java
index 09d5600..5f1c1b4 100644
--- a/src/main/java/org/apache/commons/imaging/formats/bmp/BmpImageParser.java
+++ b/src/main/java/org/apache/commons/imaging/formats/bmp/BmpImageParser.java
@@ -136,57 +136,56 @@ public class BmpImageParser extends ImageParser {
         int profileSize = 0;
         int reservedV5 = 0;
 
-        if (bitmapHeaderSize >= 40) {
-            // BITMAPINFOHEADER
-            width = read4Bytes("Width", is, "Not a Valid BMP File", 
getByteOrder());
-            height = read4Bytes("Height", is, "Not a Valid BMP File", 
getByteOrder());
-            planes = read2Bytes("Planes", is, "Not a Valid BMP File", 
getByteOrder());
-            bitsPerPixel = read2Bytes("Bits Per Pixel", is, "Not a Valid BMP 
File", getByteOrder());
-            compression = read4Bytes("Compression", is, "Not a Valid BMP 
File", getByteOrder());
-            bitmapDataSize = read4Bytes("Bitmap Data Size", is, "Not a Valid 
BMP File", getByteOrder());
-            hResolution = read4Bytes("HResolution", is, "Not a Valid BMP 
File", getByteOrder());
-            vResolution = read4Bytes("VResolution", is, "Not a Valid BMP 
File", getByteOrder());
-            colorsUsed = read4Bytes("ColorsUsed", is, "Not a Valid BMP File", 
getByteOrder());
-            colorsImportant = read4Bytes("ColorsImportant", is, "Not a Valid 
BMP File", getByteOrder());
-            if (bitmapHeaderSize >= 52 || compression == BI_BITFIELDS) {
-                // 52 = BITMAPV2INFOHEADER, now undocumented
-                // see http://en.wikipedia.org/wiki/BMP_file_format
-                redMask = read4Bytes("RedMask", is, "Not a Valid BMP File", 
getByteOrder());
-                greenMask = read4Bytes("GreenMask", is, "Not a Valid BMP 
File", getByteOrder());
-                blueMask = read4Bytes("BlueMask", is, "Not a Valid BMP File", 
getByteOrder());
-            }
-            if (bitmapHeaderSize >= 56) {
-                // 56 = the now undocumented BITMAPV3HEADER sometimes used by
-                // Photoshop
-                // see http://forums.adobe.com/thread/751592?tstart=1
-                alphaMask = read4Bytes("AlphaMask", is, "Not a Valid BMP 
File", getByteOrder());
-            }
-            if (bitmapHeaderSize >= 108) {
-                // BITMAPV4HEADER
-                colorSpaceType = read4Bytes("ColorSpaceType", is, "Not a Valid 
BMP File", getByteOrder());
-                colorSpace.red.x = read4Bytes("ColorSpaceRedX", is, "Not a 
Valid BMP File", getByteOrder());
-                colorSpace.red.y = read4Bytes("ColorSpaceRedY", is, "Not a 
Valid BMP File", getByteOrder());
-                colorSpace.red.z = read4Bytes("ColorSpaceRedZ", is, "Not a 
Valid BMP File", getByteOrder());
-                colorSpace.green.x = read4Bytes("ColorSpaceGreenX", is, "Not a 
Valid BMP File", getByteOrder());
-                colorSpace.green.y = read4Bytes("ColorSpaceGreenY", is, "Not a 
Valid BMP File", getByteOrder());
-                colorSpace.green.z = read4Bytes("ColorSpaceGreenZ", is, "Not a 
Valid BMP File", getByteOrder());
-                colorSpace.blue.x = read4Bytes("ColorSpaceBlueX", is, "Not a 
Valid BMP File", getByteOrder());
-                colorSpace.blue.y = read4Bytes("ColorSpaceBlueY", is, "Not a 
Valid BMP File", getByteOrder());
-                colorSpace.blue.z = read4Bytes("ColorSpaceBlueZ", is, "Not a 
Valid BMP File", getByteOrder());
-                gammaRed = read4Bytes("GammaRed", is, "Not a Valid BMP File", 
getByteOrder());
-                gammaGreen = read4Bytes("GammaGreen", is, "Not a Valid BMP 
File", getByteOrder());
-                gammaBlue = read4Bytes("GammaBlue", is, "Not a Valid BMP 
File", getByteOrder());
-            }
-            if (bitmapHeaderSize >= 124) {
-                // BITMAPV5HEADER
-                intent = read4Bytes("Intent", is, "Not a Valid BMP File", 
getByteOrder());
-                profileData = read4Bytes("ProfileData", is, "Not a Valid BMP 
File", getByteOrder());
-                profileSize = read4Bytes("ProfileSize", is, "Not a Valid BMP 
File", getByteOrder());
-                reservedV5 = read4Bytes("Reserved", is, "Not a Valid BMP 
File", getByteOrder());
-            }
-        } else {
+        if (bitmapHeaderSize < 40) {
             throw new ImageReadException("Invalid/unsupported BMP file");
         }
+        // BITMAPINFOHEADER
+        width = read4Bytes("Width", is, "Not a Valid BMP File", 
getByteOrder());
+        height = read4Bytes("Height", is, "Not a Valid BMP File", 
getByteOrder());
+        planes = read2Bytes("Planes", is, "Not a Valid BMP File", 
getByteOrder());
+        bitsPerPixel = read2Bytes("Bits Per Pixel", is, "Not a Valid BMP 
File", getByteOrder());
+        compression = read4Bytes("Compression", is, "Not a Valid BMP File", 
getByteOrder());
+        bitmapDataSize = read4Bytes("Bitmap Data Size", is, "Not a Valid BMP 
File", getByteOrder());
+        hResolution = read4Bytes("HResolution", is, "Not a Valid BMP File", 
getByteOrder());
+        vResolution = read4Bytes("VResolution", is, "Not a Valid BMP File", 
getByteOrder());
+        colorsUsed = read4Bytes("ColorsUsed", is, "Not a Valid BMP File", 
getByteOrder());
+        colorsImportant = read4Bytes("ColorsImportant", is, "Not a Valid BMP 
File", getByteOrder());
+        if (bitmapHeaderSize >= 52 || compression == BI_BITFIELDS) {
+            // 52 = BITMAPV2INFOHEADER, now undocumented
+            // see http://en.wikipedia.org/wiki/BMP_file_format
+            redMask = read4Bytes("RedMask", is, "Not a Valid BMP File", 
getByteOrder());
+            greenMask = read4Bytes("GreenMask", is, "Not a Valid BMP File", 
getByteOrder());
+            blueMask = read4Bytes("BlueMask", is, "Not a Valid BMP File", 
getByteOrder());
+        }
+        if (bitmapHeaderSize >= 56) {
+            // 56 = the now undocumented BITMAPV3HEADER sometimes used by
+            // Photoshop
+            // see http://forums.adobe.com/thread/751592?tstart=1
+            alphaMask = read4Bytes("AlphaMask", is, "Not a Valid BMP File", 
getByteOrder());
+        }
+        if (bitmapHeaderSize >= 108) {
+            // BITMAPV4HEADER
+            colorSpaceType = read4Bytes("ColorSpaceType", is, "Not a Valid BMP 
File", getByteOrder());
+            colorSpace.red.x = read4Bytes("ColorSpaceRedX", is, "Not a Valid 
BMP File", getByteOrder());
+            colorSpace.red.y = read4Bytes("ColorSpaceRedY", is, "Not a Valid 
BMP File", getByteOrder());
+            colorSpace.red.z = read4Bytes("ColorSpaceRedZ", is, "Not a Valid 
BMP File", getByteOrder());
+            colorSpace.green.x = read4Bytes("ColorSpaceGreenX", is, "Not a 
Valid BMP File", getByteOrder());
+            colorSpace.green.y = read4Bytes("ColorSpaceGreenY", is, "Not a 
Valid BMP File", getByteOrder());
+            colorSpace.green.z = read4Bytes("ColorSpaceGreenZ", is, "Not a 
Valid BMP File", getByteOrder());
+            colorSpace.blue.x = read4Bytes("ColorSpaceBlueX", is, "Not a Valid 
BMP File", getByteOrder());
+            colorSpace.blue.y = read4Bytes("ColorSpaceBlueY", is, "Not a Valid 
BMP File", getByteOrder());
+            colorSpace.blue.z = read4Bytes("ColorSpaceBlueZ", is, "Not a Valid 
BMP File", getByteOrder());
+            gammaRed = read4Bytes("GammaRed", is, "Not a Valid BMP File", 
getByteOrder());
+            gammaGreen = read4Bytes("GammaGreen", is, "Not a Valid BMP File", 
getByteOrder());
+            gammaBlue = read4Bytes("GammaBlue", is, "Not a Valid BMP File", 
getByteOrder());
+        }
+        if (bitmapHeaderSize >= 124) {
+            // BITMAPV5HEADER
+            intent = read4Bytes("Intent", is, "Not a Valid BMP File", 
getByteOrder());
+            profileData = read4Bytes("ProfileData", is, "Not a Valid BMP 
File", getByteOrder());
+            profileSize = read4Bytes("ProfileSize", is, "Not a Valid BMP 
File", getByteOrder());
+            reservedV5 = read4Bytes("Reserved", is, "Not a Valid BMP File", 
getByteOrder());
+        }
 
         if (LOGGER.isLoggable(Level.FINE)) {
             debugNumber("identifier1", identifier1, 1);
@@ -434,7 +433,8 @@ public class BmpImageParser extends ImageParser {
                     + bhi.bitmapDataOffset + " (expected: "
                     + expectedDataOffset + ", paletteLength: " + paletteLength
                     + ", headerSize: " + headerSize + ")");
-        } else if (extraBytes > 0) {
+        }
+        if (extraBytes > 0) {
             readBytes("BitmapDataOffset", is, extraBytes, "Not a Valid BMP 
File");
         }
 
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/bmp/PixelParserRgb.java 
b/src/main/java/org/apache/commons/imaging/formats/bmp/PixelParserRgb.java
index 2b17145..e1ab6b6 100644
--- a/src/main/java/org/apache/commons/imaging/formats/bmp/PixelParserRgb.java
+++ b/src/main/java/org/apache/commons/imaging/formats/bmp/PixelParserRgb.java
@@ -55,7 +55,8 @@ class PixelParserRgb extends PixelParserSimple {
             cachedBitCount -= bhi.bitsPerPixel;
 
             return getColorTableRGB(sample);
-        } else if (bhi.bitsPerPixel == 8) { // always grayscale?
+        }
+        if (bhi.bitsPerPixel == 8) { // always grayscale?
             final int sample = 0xff & imageData[bytecount + 0];
 
             final int rgb = getColorTableRGB(sample);
@@ -63,7 +64,8 @@ class PixelParserRgb extends PixelParserSimple {
             bytecount += 1;
 
             return rgb;
-        } else if (bhi.bitsPerPixel == 16) {
+        }
+        if (bhi.bitsPerPixel == 16) {
             final int data = read2Bytes("Pixel", is, "BMP Image Data", 
ByteOrder.LITTLE_ENDIAN);
 
             final int blue = (0x1f & (data >> 0)) << 3;
@@ -76,7 +78,8 @@ class PixelParserRgb extends PixelParserSimple {
             bytecount += 2;
 
             return rgb;
-        } else if (bhi.bitsPerPixel == 24) {
+        }
+        if (bhi.bitsPerPixel == 24) {
             final int blue = 0xff & imageData[bytecount + 0];
             final int green = 0xff & imageData[bytecount + 1];
             final int red = 0xff & imageData[bytecount + 2];
@@ -87,7 +90,8 @@ class PixelParserRgb extends PixelParserSimple {
             bytecount += 3;
 
             return rgb;
-        } else if (bhi.bitsPerPixel == 32) {
+        }
+        if (bhi.bitsPerPixel == 32) {
             final int blue = 0xff & imageData[bytecount + 0];
             final int green = 0xff & imageData[bytecount + 1];
             final int red = 0xff & imageData[bytecount + 2];
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/bmp/PixelParserRle.java 
b/src/main/java/org/apache/commons/imaging/formats/bmp/PixelParserRle.java
index 535fe57..ba30102 100644
--- a/src/main/java/org/apache/commons/imaging/formats/bmp/PixelParserRle.java
+++ b/src/main/java/org/apache/commons/imaging/formats/bmp/PixelParserRle.java
@@ -34,12 +34,12 @@ class PixelParserRle extends PixelParser {
     private int getSamplesPerByte() throws ImageReadException {
         if (bhi.bitsPerPixel == 8) {
             return 1;
-        } else if (bhi.bitsPerPixel == 4) {
+        }
+        if (bhi.bitsPerPixel == 4) {
             return 2;
-        } else {
-            throw new ImageReadException("BMP RLE: bad BitsPerPixel: "
-                    + bhi.bitsPerPixel);
         }
+        throw new ImageReadException("BMP RLE: bad BitsPerPixel: "
+                + bhi.bitsPerPixel);
     }
 
     private int[] convertDataToSamples(final int data) throws 
ImageReadException {
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/gif/GifImageParser.java 
b/src/main/java/org/apache/commons/imaging/formats/gif/GifImageParser.java
index ce7503d..b7a5a25 100644
--- a/src/main/java/org/apache/commons/imaging/formats/gif/GifImageParser.java
+++ b/src/main/java/org/apache/commons/imaging/formats/gif/GifImageParser.java
@@ -786,11 +786,10 @@ public class GifImageParser extends ImageParser 
implements XmpEmbeddable {
                             y = 2 + (theRow * 4);
                         } else {
                             theRow -= rowsInPass3;
-                            if (theRow < (rowsInPass4)) {
-                                y = 1 + (theRow * 2);
-                            } else {
+                            if (theRow >= (rowsInPass4)) {
                                 throw new ImageReadException("Gif: Strange 
Row");
                             }
+                            y = 1 + (theRow * 2);
                         }
                     }
                 }
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/icns/IcnsDecoder.java 
b/src/main/java/org/apache/commons/imaging/formats/icns/IcnsDecoder.java
index 2e97496..be6b12c 100644
--- a/src/main/java/org/apache/commons/imaging/formats/icns/IcnsDecoder.java
+++ b/src/main/java/org/apache/commons/imaging/formats/icns/IcnsDecoder.java
@@ -156,11 +156,10 @@ final class IcnsDecoder {
         // 1 bit icon types have image data followed by mask data in the same
         // entry
         final int totalBytes = (image.getWidth() * image.getHeight() + 7) / 8;
-        if (maskData.length >= 2 * totalBytes) {
-            position = totalBytes;
-        } else {
+        if (maskData.length < 2 * totalBytes) {
             throw new ImageReadException("1 BPP mask underrun parsing ICNS 
file");
         }
+        position = totalBytes;
 
         for (int y = 0; y < image.getHeight(); y++) {
             for (int x = 0; x < image.getWidth(); x++) {
@@ -249,13 +248,12 @@ final class IcnsDecoder {
                                   * imageType.getBitsPerPixel() + 7) / 8;
         byte[] imageData;
         if (imageElement.data.length < expectedSize) {
-            if (imageType.getBitsPerPixel() == 32) {
-                imageData = Rle24Compression.decompress(
-                  imageType.getWidth(), imageType.getHeight(),
-                  imageElement.data);
-            } else {
+            if (imageType.getBitsPerPixel() != 32) {
                 throw new ImageReadException("Short image data but not a 32 
bit compressed type");
             }
+            imageData = Rle24Compression.decompress(
+              imageType.getWidth(), imageType.getHeight(),
+              imageElement.data);
         } else {
             imageData = imageElement.data;
         }
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java
 
b/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java
index 92a9e8b..88fe216 100644
--- 
a/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java
+++ 
b/src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java
@@ -380,11 +380,10 @@ public class JpegDecoder extends BinaryFileParser 
implements JpegUtils.Visitor {
                         final int r = rrrr;
 
                         if (ssss == 0) {
-                            if (r == 15) {
-                                k += 16;
-                            } else {
+                            if (r != 15) {
                                 break;
                             }
+                            k += 16;
                         } else {
                             k += r;
 
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/pcx/PcxImageParser.java 
b/src/main/java/org/apache/commons/imaging/formats/pcx/PcxImageParser.java
index 7128927..5f90a8c 100644
--- a/src/main/java/org/apache/commons/imaging/formats/pcx/PcxImageParser.java
+++ b/src/main/java/org/apache/commons/imaging/formats/pcx/PcxImageParser.java
@@ -392,7 +392,8 @@ public class PcxImageParser extends ImageParser {
                     palette, 0, false, -1, DataBuffer.TYPE_BYTE);
             return new BufferedImage(colorModel, raster,
                     colorModel.isAlphaPremultiplied(), new Properties());
-        } else if (pcxHeader.bitsPerPixel == 1 && 2 <= pcxHeader.nPlanes
+        }
+        if (pcxHeader.bitsPerPixel == 1 && 2 <= pcxHeader.nPlanes
                 && pcxHeader.nPlanes <= 4) {
             final IndexColorModel colorModel = new 
IndexColorModel(pcxHeader.nPlanes,
                     1 << pcxHeader.nPlanes, pcxHeader.colormap, 0, false, -1,
@@ -415,7 +416,8 @@ public class PcxImageParser extends ImageParser {
                 image.getRaster().setDataElements(0, y, xSize, 1, unpacked);
             }
             return image;
-        } else if (pcxHeader.bitsPerPixel == 8 && pcxHeader.nPlanes == 3) {
+        }
+        if (pcxHeader.bitsPerPixel == 8 && pcxHeader.nPlanes == 3) {
             final byte[][] image = new byte[3][];
             image[0] = new byte[xSize * ySize];
             image[1] = new byte[xSize * ySize];
@@ -438,38 +440,37 @@ public class PcxImageParser extends ImageParser {
                     Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
             return new BufferedImage(colorModel, raster,
                     colorModel.isAlphaPremultiplied(), new Properties());
-        } else if ((pcxHeader.bitsPerPixel == 24 && pcxHeader.nPlanes == 1)
-                || (pcxHeader.bitsPerPixel == 32 && pcxHeader.nPlanes == 1)) {
-            final int rowLength = 3 * xSize;
-            final byte[] image = new byte[rowLength * ySize];
-            for (int y = 0; y < ySize; y++) {
-                rleReader.read(is, scanline);
-                if (pcxHeader.bitsPerPixel == 24) {
-                    System.arraycopy(scanline, 0, image, y * rowLength,
-                            rowLength);
-                } else {
-                    for (int x = 0; x < xSize; x++) {
-                        image[y * rowLength + 3 * x] = scanline[4 * x];
-                        image[y * rowLength + 3 * x + 1] = scanline[4 * x + 1];
-                        image[y * rowLength + 3 * x + 2] = scanline[4 * x + 2];
-                    }
-                }
-            }
-            final DataBufferByte dataBuffer = new DataBufferByte(image, 
image.length);
-            final WritableRaster raster = Raster.createInterleavedRaster(
-                    dataBuffer, xSize, ySize, rowLength, 3,
-                    new int[] { 2, 1, 0 }, null);
-            final ColorModel colorModel = new ComponentColorModel(
-                    ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false,
-                    Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
-            return new BufferedImage(colorModel, raster,
-                    colorModel.isAlphaPremultiplied(), new Properties());
-        } else {
+        }
+        if (((pcxHeader.bitsPerPixel != 24) || (pcxHeader.nPlanes != 1)) && 
((pcxHeader.bitsPerPixel != 32) || (pcxHeader.nPlanes != 1))) {
             throw new ImageReadException(
                     "Invalid/unsupported image with bitsPerPixel "
                             + pcxHeader.bitsPerPixel + " and planes "
                             + pcxHeader.nPlanes);
         }
+        final int rowLength = 3 * xSize;
+        final byte[] image = new byte[rowLength * ySize];
+        for (int y = 0; y < ySize; y++) {
+            rleReader.read(is, scanline);
+            if (pcxHeader.bitsPerPixel == 24) {
+                System.arraycopy(scanline, 0, image, y * rowLength,
+                        rowLength);
+            } else {
+                for (int x = 0; x < xSize; x++) {
+                    image[y * rowLength + 3 * x] = scanline[4 * x];
+                    image[y * rowLength + 3 * x + 1] = scanline[4 * x + 1];
+                    image[y * rowLength + 3 * x + 2] = scanline[4 * x + 2];
+                }
+            }
+        }
+        final DataBufferByte dataBuffer = new DataBufferByte(image, 
image.length);
+        final WritableRaster raster = Raster.createInterleavedRaster(
+                dataBuffer, xSize, ySize, rowLength, 3,
+                new int[] { 2, 1, 0 }, null);
+        final ColorModel colorModel = new ComponentColorModel(
+                ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false,
+                Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
+        return new BufferedImage(colorModel, raster,
+                colorModel.isAlphaPremultiplied(), new Properties());
     }
 
     @Override
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/png/BitParser.java 
b/src/main/java/org/apache/commons/imaging/formats/png/BitParser.java
index a8a1548..e8515eb 100644
--- a/src/main/java/org/apache/commons/imaging/formats/png/BitParser.java
+++ b/src/main/java/org/apache/commons/imaging/formats/png/BitParser.java
@@ -37,14 +37,16 @@ class BitParser {
 
         if (bitDepth == 8) {
             return 0xff & bytes[sampleIndexBytes];
-        } else if (bitDepth < 8) {
+        }
+        if (bitDepth < 8) {
             int b = 0xff & bytes[sampleIndexBytes];
             final int bitsToShift = 8 - ((pixelIndexBits & 7) + bitDepth);
             b >>= bitsToShift;
 
             final int bitmask = (1 << bitDepth) - 1;
             return b & bitmask;
-        } else if (bitDepth == 16) {
+        }
+        if (bitDepth == 16) {
             return (((0xff & bytes[sampleIndexBytes]) << 8) | (0xff & 
bytes[sampleIndexBytes + 1]));
         }
 
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/png/PngColorType.java 
b/src/main/java/org/apache/commons/imaging/formats/png/PngColorType.java
index da1c61d..62af93d 100644
--- a/src/main/java/org/apache/commons/imaging/formats/png/PngColorType.java
+++ b/src/main/java/org/apache/commons/imaging/formats/png/PngColorType.java
@@ -79,10 +79,10 @@ public enum PngColorType {
                 return PngColorType.GREYSCALE_WITH_ALPHA;
             }
             return PngColorType.GREYSCALE;
-        } else if (alpha) {
+        }
+        if (alpha) {
             return PngColorType.TRUE_COLOR_WITH_ALPHA;
-        } else {
-            return PngColorType.TRUE_COLOR;
         }
+        return PngColorType.TRUE_COLOR;
     }
 }
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/png/PngImageParser.java 
b/src/main/java/org/apache/commons/imaging/formats/png/PngImageParser.java
index 77037e9..f1bd401 100644
--- a/src/main/java/org/apache/commons/imaging/formats/png/PngImageParser.java
+++ b/src/main/java/org/apache/commons/imaging/formats/png/PngImageParser.java
@@ -374,7 +374,8 @@ public class PngImageParser extends ImageParser  implements 
XmpEmbeddable {
         if (pHYss.size() > 1) {
             throw new ImageReadException("PNG contains more than one pHYs: "
                     + pHYss.size());
-        } else if (pHYss.size() == 1) {
+        }
+        if (pHYss.size() == 1) {
             pngChunkpHYs = (PngChunkPhys) pHYss.get(0);
         }
 
@@ -384,7 +385,8 @@ public class PngImageParser extends ImageParser  implements 
XmpEmbeddable {
         if (sCALs.size() > 1) {
             throw new ImageReadException("PNG contains more than one sCAL:"
                     + sCALs.size());
-        } else if (sCALs.size() == 1) {
+        }
+        if (sCALs.size() == 1) {
             final PngChunkScal pngChunkScal = (PngChunkScal) sCALs.get(0);
             if (pngChunkScal.unitSpecifier == 1) {
                 physicalScale = 
PhysicalScale.createFromMeters(pngChunkScal.unitsPerPixelXAxis,
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java 
b/src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java
index 89333ad..627501e 100644
--- a/src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java
+++ b/src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java
@@ -392,7 +392,8 @@ class PngWriter {
             if (forceIndexedColor && forceTrueColor) {
                 throw new ImageWriteException(
                         "Params: Cannot force both indexed and true color 
modes");
-            } else if (forceIndexedColor) {
+            }
+            if (forceIndexedColor) {
                 pngColorType = PngColorType.INDEXED_COLOR;
             } else if (forceTrueColor) {
                 pngColorType = (hasAlpha ? PngColorType.TRUE_COLOR_WITH_ALPHA 
: PngColorType.TRUE_COLOR);
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/png/scanlinefilters/ScanlineFilterPaeth.java
 
b/src/main/java/org/apache/commons/imaging/formats/png/scanlinefilters/ScanlineFilterPaeth.java
index df66c5d..7334678 100644
--- 
a/src/main/java/org/apache/commons/imaging/formats/png/scanlinefilters/ScanlineFilterPaeth.java
+++ 
b/src/main/java/org/apache/commons/imaging/formats/png/scanlinefilters/ScanlineFilterPaeth.java
@@ -37,11 +37,11 @@ public class ScanlineFilterPaeth implements ScanlineFilter {
         // ; breaking ties in order a,b,c.
         if ((pa <= pb) && (pa <= pc)) {
             return a;
-        } else if (pb <= pc) {
+        }
+        if (pb <= pc) {
             return b;
-        } else {
-            return c;
         }
+        return c;
     }
 
     @Override
diff --git a/src/main/java/org/apache/commons/imaging/formats/pnm/FileInfo.java 
b/src/main/java/org/apache/commons/imaging/formats/pnm/FileInfo.java
index 90b6711..59dbd2a 100644
--- a/src/main/java/org/apache/commons/imaging/formats/pnm/FileInfo.java
+++ b/src/main/java/org/apache/commons/imaging/formats/pnm/FileInfo.java
@@ -73,7 +73,8 @@ abstract class FileInfo {
         if (sample < 0) {
             // Even netpbm tools break for files like this
             throw new IOException("Negative pixel values are invalid in PNM 
files");
-        } else if (sample > max) {
+        }
+        if (sample > max) {
             // invalid values -> black
             sample = 0;
         }
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/pnm/PamFileInfo.java 
b/src/main/java/org/apache/commons/imaging/formats/pnm/PamFileInfo.java
index 651bb2d..7912e9b 100644
--- a/src/main/java/org/apache/commons/imaging/formats/pnm/PamFileInfo.java
+++ b/src/main/java/org/apache/commons/imaging/formats/pnm/PamFileInfo.java
@@ -40,7 +40,8 @@ class PamFileInfo extends FileInfo {
         if (maxval <= 0) {
             throw new ImageReadException("PAM maxVal " + maxval
                     + " is out of range [1;65535]");
-        } else if (maxval <= 255) {
+        }
+        if (maxval <= 255) {
             scale = 255f;
             bytesPerSample = 1;
         } else if (maxval <= 65535) {
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/pnm/PgmFileInfo.java 
b/src/main/java/org/apache/commons/imaging/formats/pnm/PgmFileInfo.java
index ef066e7..68faf4b 100644
--- a/src/main/java/org/apache/commons/imaging/formats/pnm/PgmFileInfo.java
+++ b/src/main/java/org/apache/commons/imaging/formats/pnm/PgmFileInfo.java
@@ -34,7 +34,8 @@ class PgmFileInfo extends FileInfo {
         if (max <= 0) {
             throw new ImageReadException("PGM maxVal " + max
                     + " is out of range [1;65535]");
-        } else if (max <= 255) {
+        }
+        if (max <= 255) {
             scale = 255f;
             bytesPerSample = 1;
         } else if (max <= 65535) {
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java 
b/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
index 180d43a..53d2ceb 100644
--- a/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
+++ b/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
@@ -115,18 +115,23 @@ public class PnmImageParser extends ImageParser {
 
             if (identifier2 == PnmConstants.PBM_TEXT_CODE) {
                 return new PbmFileInfo(width, height, false);
-            } else if (identifier2 == PnmConstants.PBM_RAW_CODE) {
+            }
+            if (identifier2 == PnmConstants.PBM_RAW_CODE) {
                 return new PbmFileInfo(width, height, true);
-            } else if (identifier2 == PnmConstants.PGM_TEXT_CODE) {
+            }
+            if (identifier2 == PnmConstants.PGM_TEXT_CODE) {
                 final int maxgray = Integer.parseInt(wsr.readtoWhiteSpace());
                 return new PgmFileInfo(width, height, false, maxgray);
-            } else if (identifier2 == PnmConstants.PGM_RAW_CODE) {
+            }
+            if (identifier2 == PnmConstants.PGM_RAW_CODE) {
                 final int maxgray = Integer.parseInt(wsr.readtoWhiteSpace());
                 return new PgmFileInfo(width, height, true, maxgray);
-            } else if (identifier2 == PnmConstants.PPM_TEXT_CODE) {
+            }
+            if (identifier2 == PnmConstants.PPM_TEXT_CODE) {
                 final int max = Integer.parseInt(wsr.readtoWhiteSpace());
                 return new PpmFileInfo(width, height, false, max);
-            } else if (identifier2 == PnmConstants.PPM_RAW_CODE) {
+            }
+            if (identifier2 == PnmConstants.PPM_RAW_CODE) {
                 final int max = Integer.parseInt(wsr.readtoWhiteSpace());
                 return new PpmFileInfo(width, height, true, max);
             }
@@ -191,13 +196,17 @@ public class PnmImageParser extends ImageParser {
 
             if (!seenWidth) {
                 throw new ImageReadException("PAM header has no WIDTH");
-            } else if (!seenHeight) {
+            }
+            if (!seenHeight) {
                 throw new ImageReadException("PAM header has no HEIGHT");
-            } else if (!seenDepth) {
+            }
+            if (!seenDepth) {
                 throw new ImageReadException("PAM header has no DEPTH");
-            } else if (!seenMaxVal) {
+            }
+            if (!seenMaxVal) {
                 throw new ImageReadException("PAM header has no MAXVAL");
-            } else if (!seenTupleType) {
+            }
+            if (!seenTupleType) {
                 throw new ImageReadException("PAM header has no TUPLTYPE");
             }
 
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/pnm/PpmFileInfo.java 
b/src/main/java/org/apache/commons/imaging/formats/pnm/PpmFileInfo.java
index 599164f..b6923c5 100644
--- a/src/main/java/org/apache/commons/imaging/formats/pnm/PpmFileInfo.java
+++ b/src/main/java/org/apache/commons/imaging/formats/pnm/PpmFileInfo.java
@@ -33,7 +33,8 @@ class PpmFileInfo extends FileInfo {
         super(width, height, rawbits);
         if (max <= 0) {
             throw new ImageReadException("PPM maxVal " + max + " is out of 
range [1;65535]");
-        } else if (max <= 255) {
+        }
+        if (max <= 255) {
             scale = 255f;
             bytesPerSample = 1;
         } else if (max <= 65535) {
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/tiff/TiffDirectory.java 
b/src/main/java/org/apache/commons/imaging/formats/tiff/TiffDirectory.java
index 207f554..52423c1 100644
--- a/src/main/java/org/apache/commons/imaging/formats/tiff/TiffDirectory.java
+++ b/src/main/java/org/apache/commons/imaging/formats/tiff/TiffDirectory.java
@@ -802,11 +802,11 @@ public class TiffDirectory extends TiffElement {
 
         if ((tileOffsets != null) && (tileByteCounts != null)) {
             return getRawImageDataElements(tileOffsets, tileByteCounts);
-        } else if ((stripOffsets != null) && (stripByteCounts != null)) {
+        }
+        if ((stripOffsets != null) && (stripByteCounts != null)) {
             return getRawImageDataElements(stripOffsets, stripByteCounts);
-        } else {
-            throw new ImageReadException("Couldn't find image data.");
         }
+        throw new ImageReadException("Couldn't find image data.");
     }
 
     public boolean imageDataInStrips() throws ImageReadException {
@@ -817,11 +817,11 @@ public class TiffDirectory extends TiffElement {
 
         if ((tileOffsets != null) && (tileByteCounts != null)) {
             return false;
-        } else if ((stripOffsets != null) && (stripByteCounts != null)) {
+        }
+        if ((stripOffsets != null) && (stripByteCounts != null)) {
             return true;
-        } else {
-            throw new ImageReadException("Couldn't find image data.");
         }
+        throw new ImageReadException("Couldn't find image data.");
     }
 
     public ImageDataElement getJpegRawImageDataElement() throws 
ImageReadException {
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/tiff/TiffElement.java 
b/src/main/java/org/apache/commons/imaging/formats/tiff/TiffElement.java
index 6ef897f..4439173 100644
--- a/src/main/java/org/apache/commons/imaging/formats/tiff/TiffElement.java
+++ b/src/main/java/org/apache/commons/imaging/formats/tiff/TiffElement.java
@@ -24,11 +24,11 @@ public abstract class TiffElement {
     public static final Comparator<TiffElement> COMPARATOR = (e1, e2) -> {
         if (e1.offset < e2.offset) {
             return -1;
-        } else if (e1.offset > e2.offset) {
+        }
+        if (e1.offset > e2.offset) {
             return 1;
-        } else {
-            return 0;
         }
+        return 0;
     };
 
     public TiffElement(final long offset, final int length) {
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/tiff/TiffField.java 
b/src/main/java/org/apache/commons/imaging/formats/tiff/TiffField.java
index 18ca287..ccab4a8 100644
--- a/src/main/java/org/apache/commons/imaging/formats/tiff/TiffField.java
+++ b/src/main/java/org/apache/commons/imaging/formats/tiff/TiffField.java
@@ -179,12 +179,15 @@ public class TiffField {
 
         if (o instanceof Number) {
             return o.toString();
-        } else if (o instanceof String) {
+        }
+        if (o instanceof String) {
             return "'" + o.toString().trim() + "'";
-        } else if (o instanceof Date) {
+        }
+        if (o instanceof Date) {
             final DateFormat df = new 
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.ENGLISH);
             return df.format((Date) o);
-        } else if (o instanceof Object[]) {
+        }
+        if (o instanceof Object[]) {
             final Object[] objects = (Object[]) o;
             final StringBuilder result = new StringBuilder();
 
@@ -216,7 +219,8 @@ public class TiffField {
         // }
         // return result.toString();
         // }
-        } else if (o instanceof short[]) {
+        }
+        if (o instanceof short[]) {
             final short[] values = (short[]) o;
             final StringBuilder result = new StringBuilder();
 
@@ -233,7 +237,8 @@ public class TiffField {
                 result.append(sval);
             }
             return result.toString();
-        } else if (o instanceof int[]) {
+        }
+        if (o instanceof int[]) {
             final int[] values = (int[]) o;
             final StringBuilder result = new StringBuilder();
 
@@ -250,7 +255,8 @@ public class TiffField {
                 result.append(iVal);
             }
             return result.toString();
-        } else if (o instanceof long[]) {
+        }
+        if (o instanceof long[]) {
             final long[] values = (long[]) o;
             final StringBuilder result = new StringBuilder();
 
@@ -267,7 +273,8 @@ public class TiffField {
                 result.append(lVal);
             }
             return result.toString();
-        } else if (o instanceof double[]) {
+        }
+        if (o instanceof double[]) {
             final double[] values = (double[]) o;
             final StringBuilder result = new StringBuilder();
 
@@ -284,7 +291,8 @@ public class TiffField {
                 result.append(dVal);
             }
             return result.toString();
-        } else if (o instanceof byte[]) {
+        }
+        if (o instanceof byte[]) {
             final byte[] values = (byte[]) o;
             final StringBuilder result = new StringBuilder();
 
@@ -301,7 +309,8 @@ public class TiffField {
                 result.append(bVal);
             }
             return result.toString();
-        } else if (o instanceof char[]) {
+        }
+        if (o instanceof char[]) {
             final char[] values = (char[]) o;
             final StringBuilder result = new StringBuilder();
 
@@ -318,7 +327,8 @@ public class TiffField {
                 result.append(cVal);
             }
             return result.toString();
-        } else if (o instanceof float[]) {
+        }
+        if (o instanceof float[]) {
             final float[] values = (float[]) o;
             final StringBuilder result = new StringBuilder();
 
@@ -435,21 +445,24 @@ public class TiffField {
 
         if (o instanceof Number) {
             return new int[] { ((Number) o).intValue() };
-        } else if (o instanceof Number[]) {
+        }
+        if (o instanceof Number[]) {
             final Number[] numbers = (Number[]) o;
             final int[] result = new int[numbers.length];
             for (int i = 0; i < numbers.length; i++) {
                 result[i] = numbers[i].intValue();
             }
             return result;
-        } else if (o instanceof short[]) {
+        }
+        if (o instanceof short[]) {
             final short[] numbers = (short[]) o;
             final int[] result = new int[numbers.length];
             for (int i = 0; i < numbers.length; i++) {
                 result[i] = 0xffff & numbers[i];
             }
             return result;
-        } else if (o instanceof int[]) {
+        }
+        if (o instanceof int[]) {
             final int[] numbers = (int[]) o;
             final int[] result = new int[numbers.length];
             System.arraycopy(numbers, 0, result, 0, numbers.length);
@@ -468,35 +481,40 @@ public class TiffField {
 
         if (o instanceof Number) {
             return new double[] { ((Number) o).doubleValue() };
-        } else if (o instanceof Number[]) {
+        }
+        if (o instanceof Number[]) {
             final Number[] numbers = (Number[]) o;
             final double[] result = new double[numbers.length];
             for (int i = 0; i < numbers.length; i++) {
                 result[i] = numbers[i].doubleValue();
             }
             return result;
-        } else if (o instanceof short[]) {
+        }
+        if (o instanceof short[]) {
             final short[] numbers = (short[]) o;
             final double[] result = new double[numbers.length];
             for (int i = 0; i < numbers.length; i++) {
                 result[i] = numbers[i];
             }
             return result;
-        } else if (o instanceof int[]) {
+        }
+        if (o instanceof int[]) {
             final int[] numbers = (int[]) o;
             final double[] result = new double[numbers.length];
             for (int i = 0; i < numbers.length; i++) {
                 result[i] = numbers[i];
             }
             return result;
-        } else if (o instanceof float[]) {
+        }
+        if (o instanceof float[]) {
             final float[] numbers = (float[]) o;
             final double[] result = new double[numbers.length];
             for (int i = 0; i < numbers.length; i++) {
                 result[i] = numbers[i];
             }
             return result;
-        } else if (o instanceof double[]) {
+        }
+        if (o instanceof double[]) {
             final double[] numbers = (double[]) o;
             final double[] result = new double[numbers.length];
             System.arraycopy(numbers, 0, result, 0, numbers.length);
@@ -515,21 +533,24 @@ public class TiffField {
 
         if (o instanceof Number) {
             return ((Number) o).intValue();
-        } else if (o instanceof Number[]) {
+        }
+        if (o instanceof Number[]) {
             final Number[] numbers = (Number[]) o;
             int sum = 0;
             for (final Number number : numbers) {
                 sum += number.intValue();
             }
             return sum;
-        } else if (o instanceof short[]) {
+        }
+        if (o instanceof short[]) {
             final short[] numbers = (short[]) o;
             int sum = 0;
             for (final short number : numbers) {
                 sum += number;
             }
             return sum;
-        } else if (o instanceof int[]) {
+        }
+        if (o instanceof int[]) {
             final int[] numbers = (int[]) o;
             int sum = 0;
             for (final int number : numbers) {
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/tiff/TiffImageMetadata.java 
b/src/main/java/org/apache/commons/imaging/formats/tiff/TiffImageMetadata.java
index ef7e8b4..5f61d61 100644
--- 
a/src/main/java/org/apache/commons/imaging/formats/tiff/TiffImageMetadata.java
+++ 
b/src/main/java/org/apache/commons/imaging/formats/tiff/TiffImageMetadata.java
@@ -118,7 +118,8 @@ public class TiffImageMetadata extends GenericImageMetadata 
{
                     if (null != dstDir.findField(srcField.getTag())) {
                         // ignore duplicate tags in a directory.
                         continue;
-                    } else if (srcField.getTagInfo().isOffset()) {
+                    }
+                    if (srcField.getTagInfo().isOffset()) {
                         // ignore offset fields.
                         continue;
                     }
@@ -546,12 +547,12 @@ public class TiffImageMetadata extends 
GenericImageMetadata {
 
             if (longitudeRef.trim().equalsIgnoreCase("e")) {
                 return result;
-            } else if (longitudeRef.trim().equalsIgnoreCase("w")) {
+            }
+            if (longitudeRef.trim().equalsIgnoreCase("w")) {
                 return -result;
-            } else {
-                throw new ImageReadException("Unknown longitude ref: \""
-                        + longitudeRef + "\"");
             }
+            throw new ImageReadException("Unknown longitude ref: \""
+                    + longitudeRef + "\"");
         }
 
         public double getLatitudeAsDegreesNorth() throws ImageReadException {
@@ -561,12 +562,12 @@ public class TiffImageMetadata extends 
GenericImageMetadata {
 
             if (latitudeRef.trim().equalsIgnoreCase("n")) {
                 return result;
-            } else if (latitudeRef.trim().equalsIgnoreCase("s")) {
+            }
+            if (latitudeRef.trim().equalsIgnoreCase("s")) {
                 return -result;
-            } else {
-                throw new ImageReadException("Unknown latitude ref: \""
-                        + latitudeRef + "\"");
             }
+            throw new ImageReadException("Unknown latitude ref: \""
+                    + latitudeRef + "\"");
         }
 
     }
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/tiff/TiffReader.java 
b/src/main/java/org/apache/commons/imaging/formats/tiff/TiffReader.java
index 48f0ed0..68029fc 100644
--- a/src/main/java/org/apache/commons/imaging/formats/tiff/TiffReader.java
+++ b/src/main/java/org/apache/commons/imaging/formats/tiff/TiffReader.java
@@ -63,11 +63,11 @@ public class TiffReader extends BinaryFileParser {
     private ByteOrder getTiffByteOrder(final int byteOrderByte) throws 
ImageReadException {
         if (byteOrderByte == 'I') {
             return ByteOrder.LITTLE_ENDIAN; // Intel
-        } else if (byteOrderByte == 'M') {
+        }
+        if (byteOrderByte == 'M') {
             return ByteOrder.BIG_ENDIAN; // Motorola
-        } else {
-            throw new ImageReadException("Invalid TIFF byte order " + (0xff & 
byteOrderByte));
         }
+        throw new ImageReadException("Invalid TIFF byte order " + (0xff & 
byteOrderByte));
     }
 
     private TiffHeader readTiffHeader(final InputStream is) throws 
ImageReadException, IOException {
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/tiff/TiffTags.java 
b/src/main/java/org/apache/commons/imaging/formats/tiff/TiffTags.java
index 7608abd..53f4226 100644
--- a/src/main/java/org/apache/commons/imaging/formats/tiff/TiffTags.java
+++ b/src/main/java/org/apache/commons/imaging/formats/tiff/TiffTags.java
@@ -136,7 +136,8 @@ final class TiffTags {
             if (tagInfo.directoryType == 
TiffDirectoryType.EXIF_DIRECTORY_UNKNOWN) {
                 // pass
                 continue;
-            } else if (directoryType == tagInfo.directoryType.directoryType) {
+            }
+            if (directoryType == tagInfo.directoryType.directoryType) {
                 return tagInfo;
             }
         }
@@ -146,10 +147,12 @@ final class TiffTags {
             if (tagInfo.directoryType == 
TiffDirectoryType.EXIF_DIRECTORY_UNKNOWN) {
                 // pass
                 continue;
-            } else if (directoryType >= 0
+            }
+            if (directoryType >= 0
                     && tagInfo.directoryType.isImageDirectory()) {
                 return tagInfo;
-            } else if (directoryType < 0
+            }
+            if (directoryType < 0
                     && !tagInfo.directoryType.isImageDirectory()) {
                 return tagInfo;
             }
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/DataReaderStrips.java
 
b/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/DataReaderStrips.java
index c337559..39269bc 100644
--- 
a/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/DataReaderStrips.java
+++ 
b/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/DataReaderStrips.java
@@ -167,7 +167,8 @@ public final class DataReaderStrips extends ImageDataReader 
{
                 }
             }
             return;
-        } else if ((bitsPerPixel == 24  || bitsPerPixel==32) && 
allSamplesAreOneByte
+        }
+        if ((bitsPerPixel == 24  || bitsPerPixel==32) && allSamplesAreOneByte
             && photometricInterpreter instanceof PhotometricInterpreterRgb) {
             int k = 0;
             int nRows = pixelsPerStrip / width;
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeAscii.java
 
b/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeAscii.java
index ed764ec..e211dd2 100644
--- 
a/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeAscii.java
+++ 
b/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeAscii.java
@@ -73,30 +73,31 @@ public class FieldTypeAscii extends FieldType {
             System.arraycopy(bytes, 0, result, 0, bytes.length);
             result[result.length - 1] = 0;
             return result;
-        } else if (o instanceof String) {
+        }
+        if (o instanceof String) {
             final byte[] bytes = ((String) o).getBytes(StandardCharsets.UTF_8);
             final byte[] result = new byte[bytes.length + 1];
             System.arraycopy(bytes, 0, result, 0, bytes.length);
             result[result.length - 1] = 0;
             return result;
-        } else if (o instanceof String[]) {
-            final String[] strings = (String[]) o;
-            int totalLength = 0;
-            for (final String string : strings) {
-                final byte[] bytes = string.getBytes(StandardCharsets.UTF_8);
-                totalLength += (bytes.length + 1);
-            }
-            final byte[] result = new byte[totalLength];
-            int position = 0;
-            for (final String string : strings) {
-                final byte[] bytes = string.getBytes(StandardCharsets.UTF_8);
-                System.arraycopy(bytes, 0, result, position, bytes.length);
-                position += (bytes.length + 1);
-            }
-            return result;
-        } else {
+        }
+        if (!(o instanceof String[])) {
             throw new ImageWriteException("Unknown data type: " + o);
         }
+        final String[] strings = (String[]) o;
+        int totalLength = 0;
+        for (final String string : strings) {
+            final byte[] bytes = string.getBytes(StandardCharsets.UTF_8);
+            totalLength += (bytes.length + 1);
+        }
+        final byte[] result = new byte[totalLength];
+        int position = 0;
+        for (final String string : strings) {
+            final byte[] bytes = string.getBytes(StandardCharsets.UTF_8);
+            System.arraycopy(bytes, 0, result, position, bytes.length);
+            position += (bytes.length + 1);
+        }
+        return result;
     }
 
 }
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeByte.java
 
b/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeByte.java
index 797855d..e5c913a 100644
--- 
a/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeByte.java
+++ 
b/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeByte.java
@@ -39,11 +39,11 @@ public class FieldTypeByte extends FieldType {
     public byte[] writeData(final Object o, final ByteOrder byteOrder) throws 
ImageWriteException {
         if (o instanceof Byte) {
             return new byte[] { ((Byte) o).byteValue(), };
-        } else if (o instanceof byte[]) {
+        }
+        if (o instanceof byte[]) {
             return (byte[]) o;
-        } else {
-            throw new ImageWriteException("Invalid data", o);
         }
+        throw new ImageWriteException("Invalid data", o);
     }
 
 }
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeDouble.java
 
b/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeDouble.java
index c7ca989..a8c6ba7 100644
--- 
a/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeDouble.java
+++ 
b/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeDouble.java
@@ -42,19 +42,20 @@ public class FieldTypeDouble extends FieldType {
         if (o instanceof Double) {
             return ByteConversions.toBytes(((Double) o).doubleValue(),
                     byteOrder);
-        } else if (o instanceof double[]) {
+        }
+        if (o instanceof double[]) {
             final double[] numbers = (double[]) o;
             return ByteConversions.toBytes(numbers, byteOrder);
-        } else if (o instanceof Double[]) {
-            final Double[] numbers = (Double[]) o;
-            final double[] values = new double[numbers.length];
-            for (int i = 0; i < values.length; i++) {
-                values[i] = numbers[i].doubleValue();
-            }
-            return ByteConversions.toBytes(values, byteOrder);
-        } else {
+        }
+        if (!(o instanceof Double[])) {
             throw new ImageWriteException("Invalid data", o);
         }
+        final Double[] numbers = (Double[]) o;
+        final double[] values = new double[numbers.length];
+        for (int i = 0; i < values.length; i++) {
+            values[i] = numbers[i].doubleValue();
+        }
+        return ByteConversions.toBytes(values, byteOrder);
     }
 
 }
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeFloat.java
 
b/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeFloat.java
index 0be8510..5b28e23 100644
--- 
a/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeFloat.java
+++ 
b/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeFloat.java
@@ -41,19 +41,20 @@ public class FieldTypeFloat extends FieldType {
     public byte[] writeData(final Object o, final ByteOrder byteOrder) throws 
ImageWriteException {
         if (o instanceof Float) {
             return ByteConversions.toBytes(((Float) o).floatValue(), 
byteOrder);
-        } else if (o instanceof float[]) {
+        }
+        if (o instanceof float[]) {
             final float[] numbers = (float[]) o;
             return ByteConversions.toBytes(numbers, byteOrder);
-        } else if (o instanceof Float[]) {
-            final Float[] numbers = (Float[]) o;
-            final float[] values = new float[numbers.length];
-            for (int i = 0; i < values.length; i++) {
-                values[i] = numbers[i].floatValue();
-            }
-            return ByteConversions.toBytes(values, byteOrder);
-        } else {
+        }
+        if (!(o instanceof Float[])) {
             throw new ImageWriteException("Invalid data", o);
         }
+        final Float[] numbers = (Float[]) o;
+        final float[] values = new float[numbers.length];
+        for (int i = 0; i < values.length; i++) {
+            values[i] = numbers[i].floatValue();
+        }
+        return ByteConversions.toBytes(values, byteOrder);
     }
 
 }
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeLong.java
 
b/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeLong.java
index 2ed9435..7b0d82f 100644
--- 
a/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeLong.java
+++ 
b/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeLong.java
@@ -41,19 +41,20 @@ public class FieldTypeLong extends FieldType {
     public byte[] writeData(final Object o, final ByteOrder byteOrder) throws 
ImageWriteException {
         if (o instanceof Integer) {
             return ByteConversions.toBytes((Integer) o, byteOrder);
-        } else if (o instanceof int[]) {
+        }
+        if (o instanceof int[]) {
             final int[] numbers = (int[]) o;
             return ByteConversions.toBytes(numbers, byteOrder);
-        } else if (o instanceof Integer[]) {
-            final Integer[] numbers = (Integer[]) o;
-            final int[] values = new int[numbers.length];
-            for (int i = 0; i < values.length; i++) {
-                values[i] = numbers[i];
-            }
-            return ByteConversions.toBytes(values, byteOrder);
-        } else {
+        }
+        if (!(o instanceof Integer[])) {
             throw new ImageWriteException("Invalid data", o);
         }
+        final Integer[] numbers = (Integer[]) o;
+        final int[] values = new int[numbers.length];
+        for (int i = 0; i < values.length; i++) {
+            values[i] = numbers[i];
+        }
+        return ByteConversions.toBytes(values, byteOrder);
     }
 
 }
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeRational.java
 
b/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeRational.java
index ebda8a2..a18ca7e 100644
--- 
a/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeRational.java
+++ 
b/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeRational.java
@@ -42,13 +42,16 @@ public class FieldTypeRational extends FieldType {
     public byte[] writeData(final Object o, final ByteOrder byteOrder) throws 
ImageWriteException {
         if (o instanceof RationalNumber) {
             return ByteConversions.toBytes((RationalNumber) o, byteOrder);
-        } else if (o instanceof RationalNumber[]) {
+        }
+        if (o instanceof RationalNumber[]) {
             return ByteConversions.toBytes((RationalNumber[]) o, byteOrder);
-        } else if (o instanceof Number) {
+        }
+        if (o instanceof Number) {
             final Number number = (Number) o;
             final RationalNumber rationalNumber = 
RationalNumber.valueOf(number.doubleValue());
             return ByteConversions.toBytes(rationalNumber, byteOrder);
-        } else if (o instanceof Number[]) {
+        }
+        if (o instanceof Number[]) {
             final Number[] numbers = (Number[]) o;
             final RationalNumber[] rationalNumbers = new 
RationalNumber[numbers.length];
             for (int i = 0; i < numbers.length; i++) {
@@ -56,16 +59,16 @@ public class FieldTypeRational extends FieldType {
                 rationalNumbers[i] = 
RationalNumber.valueOf(number.doubleValue());
             }
             return ByteConversions.toBytes(rationalNumbers, byteOrder);
-        } else if (o instanceof double[]) {
-            final double[] numbers = (double[]) o;
-            final RationalNumber[] rationalNumbers = new 
RationalNumber[numbers.length];
-            for (int i = 0; i < numbers.length; i++) {
-                final double number = numbers[i];
-                rationalNumbers[i] = RationalNumber.valueOf(number);
-            }
-            return ByteConversions.toBytes(rationalNumbers, byteOrder);
-        } else {
+        }
+        if (!(o instanceof double[])) {
             throw new ImageWriteException("Invalid data", o);
         }
+        final double[] numbers = (double[]) o;
+        final RationalNumber[] rationalNumbers = new 
RationalNumber[numbers.length];
+        for (int i = 0; i < numbers.length; i++) {
+            final double number = numbers[i];
+            rationalNumbers[i] = RationalNumber.valueOf(number);
+        }
+        return ByteConversions.toBytes(rationalNumbers, byteOrder);
     }
 }
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeShort.java
 
b/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeShort.java
index 893be90..d1e7c79 100644
--- 
a/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeShort.java
+++ 
b/src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeShort.java
@@ -40,19 +40,20 @@ public class FieldTypeShort extends FieldType {
     public byte[] writeData(final Object o, final ByteOrder byteOrder) throws 
ImageWriteException {
         if (o instanceof Short) {
             return ByteConversions.toBytes(((Short) o).shortValue(), 
byteOrder);
-        } else if (o instanceof short[]) {
+        }
+        if (o instanceof short[]) {
             final short[] numbers = (short[]) o;
             return ByteConversions.toBytes(numbers, byteOrder);
-        } else if (o instanceof Short[]) {
-            final Short[] numbers = (Short[]) o;
-            final short[] values = new short[numbers.length];
-            for (int i = 0; i < values.length; i++) {
-                values[i] = numbers[i].shortValue();
-            }
-            return ByteConversions.toBytes(values, byteOrder);
-        } else {
+        }
+        if (!(o instanceof Short[])) {
             throw new ImageWriteException("Invalid data", o);
         }
+        final Short[] numbers = (Short[]) o;
+        final short[] values = new short[numbers.length];
+        for (int i = 0; i < values.length; i++) {
+            values[i] = numbers[i].shortValue();
+        }
+        return ByteConversions.toBytes(values, byteOrder);
     }
 
 }
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/tiff/photometricinterpreters/floatingpoint/PaletteEntryForValue.java
 
b/src/main/java/org/apache/commons/imaging/formats/tiff/photometricinterpreters/floatingpoint/PaletteEntryForValue.java
index 61157b7..c597186 100644
--- 
a/src/main/java/org/apache/commons/imaging/formats/tiff/photometricinterpreters/floatingpoint/PaletteEntryForValue.java
+++ 
b/src/main/java/org/apache/commons/imaging/formats/tiff/photometricinterpreters/floatingpoint/PaletteEntryForValue.java
@@ -62,7 +62,8 @@ public class PaletteEntryForValue implements PaletteEntry {
     public int getARGB(final float f) {
         if (isNull && Float.isNaN(f)) {
             return iColor;
-        } else if (f == value) {
+        }
+        if (f == value) {
             return iColor;
         }
         return 0;
@@ -72,7 +73,8 @@ public class PaletteEntryForValue implements PaletteEntry {
     public Color getColor(final float f) {
         if (isNull && Float.isNaN(f)) {
             return color;
-        } else if (f == value) {
+        }
+        if (f == value) {
             return color;
         }
         return null;
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoGpsText.java
 
b/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoGpsText.java
index ed63be6..bb97ae6 100644
--- 
a/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoGpsText.java
+++ 
b/src/main/java/org/apache/commons/imaging/formats/tiff/taginfos/TagInfoGpsText.java
@@ -124,17 +124,18 @@ public final class TagInfoGpsText extends TagInfo {
             final Object object = FieldType.ASCII.getValue(entry);
             if (object instanceof String) {
                 return (String) object;
-            } else if (object instanceof String[]) {
+            }
+            if (object instanceof String[]) {
                 // Use of arrays with the ASCII type
                 // should be extremely rare, and use of
                 // ASCII type in GPS fields should be
                 // forbidden. So assume the 2 never happen
                 // together and return incomplete strings if they do.
                 return ((String[]) object)[0];
-            } else {
-                throw new ImageReadException("Unexpected ASCII type decoded");
             }
-        } else if (entry.getFieldType() == FieldType.UNDEFINED) {
+            throw new ImageReadException("Unexpected ASCII type decoded");
+        }
+        if (entry.getFieldType() == FieldType.UNDEFINED) {
             /* later */
         } else if (entry.getFieldType() == FieldType.BYTE) {
             /* later */
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterBase.java
 
b/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterBase.java
index 45e11b4..ce09074 100644
--- 
a/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterBase.java
+++ 
b/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterBase.java
@@ -207,7 +207,8 @@ public abstract class TiffImageWriterBase {
             // perhaps we should just discard field?
             throw new ImageWriteException(
                     "Output set has Interoperability Directory Offset field, 
but no Interoperability Directory");
-        } else if (interoperabilityDirectory != null) {
+        }
+        if (interoperabilityDirectory != null) {
             if (exifDirectory == null) {
                 exifDirectory = outputSet.addExifDirectory();
             }
@@ -229,7 +230,8 @@ public abstract class TiffImageWriterBase {
             // perhaps we should just discard field?
             throw new ImageWriteException(
                     "Output set has Exif Directory Offset field, but no Exif 
Directory");
-        } else if (exifDirectory != null) {
+        }
+        if (exifDirectory != null) {
             if (exifDirectoryOffsetField == null) {
                 exifDirectoryOffsetField = TiffOutputField.createOffsetField(
                         ExifTagConstants.EXIF_TAG_EXIF_OFFSET, byteOrder);
@@ -243,7 +245,8 @@ public abstract class TiffImageWriterBase {
             // perhaps we should just discard field?
             throw new ImageWriteException(
                     "Output set has GPS Directory Offset field, but no GPS 
Directory");
-        } else if (gpsDirectory != null) {
+        }
+        if (gpsDirectory != null) {
             if (gpsDirectoryOffsetField == null) {
                 gpsDirectoryOffsetField = TiffOutputField.createOffsetField(
                         ExifTagConstants.EXIF_TAG_GPSINFO, byteOrder);
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossless.java
 
b/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossless.java
index edd77dc..b982ea3 100644
--- 
a/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossless.java
+++ 
b/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossless.java
@@ -145,7 +145,8 @@ public class TiffImageWriterLossless extends 
TiffImageWriterBase {
         final int oldLength = exifBytes.length;
         if (analysis.isEmpty()) {
             throw new ImageWriteException("Couldn't analyze old tiff data.");
-        } else if (analysis.size() == 1) {
+        }
+        if (analysis.size() == 1) {
             final TiffElement onlyElement = analysis.get(0);
             if (onlyElement.offset == TIFF_HEADER_SIZE
                     && onlyElement.offset + onlyElement.length
@@ -197,13 +198,12 @@ public class TiffImageWriterLossless extends 
TiffImageWriterBase {
         while (!unusedElements.isEmpty()) {
             final TiffElement element = unusedElements.get(0);
             final long elementEnd = element.offset + element.length;
-            if (elementEnd == overflowIndex) {
-                // discarding a tail element. should only happen once.
-                overflowIndex -= element.length;
-                unusedElements.remove(0);
-            } else {
+            if (elementEnd != overflowIndex) {
                 break;
             }
+            // discarding a tail element. should only happen once.
+            overflowIndex -= element.length;
+            unusedElements.remove(0);
         }
 
         Collections.sort(unusedElements, ELEMENT_SIZE_COMPARATOR);
@@ -223,11 +223,10 @@ public class TiffImageWriterLossless extends 
TiffImageWriterBase {
             // item.
             TiffElement bestFit = null;
             for (final TiffElement element : unusedElements) {
-                if (element.length >= outputItemLength) {
-                    bestFit = element;
-                } else {
+                if (element.length < outputItemLength) {
                     break;
                 }
+                bestFit = element;
             }
             if (null == bestFit) {
                 // we couldn't place this item. overflow.
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffOutputDirectory.java
 
b/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffOutputDirectory.java
index afdc763..a9a1515 100644
--- 
a/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffOutputDirectory.java
+++ 
b/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffOutputDirectory.java
@@ -77,11 +77,11 @@ public final class TiffOutputDirectory extends 
TiffOutputItem {
     public static final Comparator<TiffOutputDirectory> COMPARATOR = (o1, o2) 
-> {
         if (o1.type < o2.type) {
             return -1;
-        } else if (o1.type > o2.type) {
+        }
+        if (o1.type > o2.type) {
             return 1;
-        } else {
-            return 0;
         }
+        return 0;
     };
     private JpegImageData jpegImageData;
     private TiffImageData tiffImageData;
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/xpm/XpmImageParser.java 
b/src/main/java/org/apache/commons/imaging/formats/xpm/XpmImageParser.java
index e7dffcf..fc39bdf 100644
--- a/src/main/java/org/apache/commons/imaging/formats/xpm/XpmImageParser.java
+++ b/src/main/java/org/apache/commons/imaging/formats/xpm/XpmImageParser.java
@@ -220,15 +220,17 @@ public class XpmImageParser extends ImageParser {
         int getBestARGB() {
             if (haveColor) {
                 return colorArgb;
-            } else if (haveGray) {
+            }
+            if (haveGray) {
                 return grayArgb;
-            } else if (haveGray4Level) {
+            }
+            if (haveGray4Level) {
                 return gray4LevelArgb;
-            } else if (haveMono) {
+            }
+            if (haveMono) {
                 return monoArgb;
-            } else {
-                return 0x00000000;
             }
+            return 0x00000000;
         }
     }
 
@@ -275,12 +277,12 @@ public class XpmImageParser extends ImageParser {
         }
         if (",".equals(token)) {
             return true;
-        } else if ("}".equals(token)) {
+        }
+        if ("}".equals(token)) {
             return false;
-        } else {
-            throw new ImageReadException("Parsing XPM file failed, "
-                    + "no ',' or '}' found where expected");
         }
+        throw new ImageReadException("Parsing XPM file failed, "
+                + "no ',' or '}' found where expected");
     }
 
     private XpmHeader parseXpmValuesSection(final String row)
@@ -303,12 +305,11 @@ public class XpmImageParser extends ImageParser {
                 yHotSpot = Integer.parseInt(tokens[5]);
             }
             if (tokens.length == 5 || tokens.length == 7) {
-                if ("XPMEXT".equals(tokens[tokens.length - 1])) {
-                    xpmExt = true;
-                } else {
+                if (!"XPMEXT".equals(tokens[tokens.length - 1])) {
                     throw new ImageReadException("Parsing XPM file failed, "
                             + "can't parse <Values> section XPMEXT");
                 }
+                xpmExt = true;
             }
             return new XpmHeader(width, height, numColors, numCharsPerPixel,
                     xHotSpot, yHotSpot, xpmExt);
@@ -326,39 +327,43 @@ public class XpmImageParser extends ImageParser {
                 final int green = Integer.parseInt(color.substring(1, 2), 16);
                 final int blue = Integer.parseInt(color.substring(2, 3), 16);
                 return 0xff000000 | (red << 20) | (green << 12) | (blue << 4);
-            } else if (color.length() == 6) {
+            }
+            if (color.length() == 6) {
                 return 0xff000000 | Integer.parseInt(color, 16);
-            } else if (color.length() == 9) {
+            }
+            if (color.length() == 9) {
                 final int red = Integer.parseInt(color.substring(0, 1), 16);
                 final int green = Integer.parseInt(color.substring(3, 4), 16);
                 final int blue = Integer.parseInt(color.substring(6, 7), 16);
                 return 0xff000000 | (red << 16) | (green << 8) | blue;
-            } else if (color.length() == 12) {
+            }
+            if (color.length() == 12) {
                 final int red = Integer.parseInt(color.substring(0, 1), 16);
                 final int green = Integer.parseInt(color.substring(4, 5), 16);
                 final int blue = Integer.parseInt(color.substring(8, 9), 16);
                 return 0xff000000 | (red << 16) | (green << 8) | blue;
-            } else if (color.length() == 24) {
+            }
+            if (color.length() == 24) {
                 final int red = Integer.parseInt(color.substring(0, 1), 16);
                 final int green = Integer.parseInt(color.substring(8, 9), 16);
                 final int blue = Integer.parseInt(color.substring(16, 17), 16);
                 return 0xff000000 | (red << 16) | (green << 8) | blue;
-            } else {
-                return 0x00000000;
             }
-        } else if (color.charAt(0) == '%') {
+            return 0x00000000;
+        }
+        if (color.charAt(0) == '%') {
             throw new ImageReadException("HSV colors are not implemented "
                     + "even in the XPM specification!");
-        } else if ("None".equals(color)) {
-            return 0x00000000;
-        } else {
-            loadColorNames();
-            final String colorLowercase = color.toLowerCase(Locale.ENGLISH);
-            if (colorNames.containsKey(colorLowercase)) {
-                return colorNames.get(colorLowercase);
-            }
+        }
+        if ("None".equals(color)) {
             return 0x00000000;
         }
+        loadColorNames();
+        final String colorLowercase = color.toLowerCase(Locale.ENGLISH);
+        if (colorNames.containsKey(colorLowercase)) {
+            return colorNames.get(colorLowercase);
+        }
+        return 0x00000000;
     }
 
     private void populatePaletteEntry(final PaletteEntry paletteEntry, final 
String key, final String color) throws ImageReadException {
diff --git 
a/src/main/java/org/apache/commons/imaging/palette/LongestAxisMedianCut.java 
b/src/main/java/org/apache/commons/imaging/palette/LongestAxisMedianCut.java
index d5d5107..0c62797 100644
--- a/src/main/java/org/apache/commons/imaging/palette/LongestAxisMedianCut.java
+++ b/src/main/java/org/apache/commons/imaging/palette/LongestAxisMedianCut.java
@@ -70,11 +70,10 @@ public class LongestAxisMedianCut implements MedianCut {
 
             newCount += colorCount.count;
 
-            if (newCount < countHalf) {
-                oldCount = newCount;
-            } else {
+            if (newCount >= countHalf) {
                 break;
             }
+            oldCount = newCount;
         }
 
         if (medianIndex == colorCounts.size() - 1) {
diff --git 
a/src/main/java/org/apache/commons/imaging/palette/MostPopulatedBoxesMedianCut.java
 
b/src/main/java/org/apache/commons/imaging/palette/MostPopulatedBoxesMedianCut.java
index c323343..91e0f37 100644
--- 
a/src/main/java/org/apache/commons/imaging/palette/MostPopulatedBoxesMedianCut.java
+++ 
b/src/main/java/org/apache/commons/imaging/palette/MostPopulatedBoxesMedianCut.java
@@ -60,11 +60,10 @@ public class MostPopulatedBoxesMedianCut implements 
MedianCut {
 
                 newCount += colorCount.count;
 
-                if (newCount < countHalf) {
-                    oldCount = newCount;
-                } else {
+                if (newCount >= countHalf) {
                     break;
                 }
+                oldCount = newCount;
             }
             if (medianIndex == colorCounts.size() - 1) {
                 medianIndex--;
diff --git 
a/src/test/java/org/apache/commons/imaging/formats/jpeg/exif/MicrosoftTagTest.java
 
b/src/test/java/org/apache/commons/imaging/formats/jpeg/exif/MicrosoftTagTest.java
index 9ffcd14..93ee728 100644
--- 
a/src/test/java/org/apache/commons/imaging/formats/jpeg/exif/MicrosoftTagTest.java
+++ 
b/src/test/java/org/apache/commons/imaging/formats/jpeg/exif/MicrosoftTagTest.java
@@ -68,11 +68,11 @@ public class MicrosoftTagTest extends ExifBaseTest {
     private TiffImageMetadata toTiffMetadata(final ImageMetadata metadata) 
throws Exception {
         if (metadata instanceof JpegImageMetadata) {
             return ((JpegImageMetadata)metadata).getExif();
-        } else if (metadata instanceof TiffImageMetadata) {
+        }
+        if (metadata instanceof TiffImageMetadata) {
             return ((TiffImageMetadata)metadata);
-        } else {
-            throw new Exception("bad metadata format");
         }
+        throw new Exception("bad metadata format");
     }
 
     private byte[] cleanImage(final File imageWithExif) throws 
ImageReadException, ImageWriteException, IOException {
diff --git 
a/src/test/java/org/apache/commons/imaging/formats/tiff/TiffCcittTest.java 
b/src/test/java/org/apache/commons/imaging/formats/tiff/TiffCcittTest.java
index f24b187..569f29e 100644
--- a/src/test/java/org/apache/commons/imaging/formats/tiff/TiffCcittTest.java
+++ b/src/test/java/org/apache/commons/imaging/formats/tiff/TiffCcittTest.java
@@ -258,12 +258,11 @@ public class TiffCcittTest extends TiffBaseTest {
     private static boolean nextCombination(final int[] sequence, final int 
max) {
         int i;
         for (i = 0; i < sequence.length; i++) {
-            if (sequence[i] == max) {
-                sequence[i] = 0;
-            } else {
+            if (sequence[i] != max) {
                 sequence[i]++;
                 break;
             }
+            sequence[i] = 0;
         }
         return i < sequence.length;
     }

Reply via email to