commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ki...@apache.org
Subject [commons-imaging] branch master updated: [IMAGING-244]: Use isEmpty instead of comparing size() with integers
Date Sun, 15 Dec 2019 22:50:18 GMT
This is an automated email from the ASF dual-hosted git repository.

kinow 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 b751732  [IMAGING-244]: Use isEmpty instead of comparing size() with integers
     new 8e380e0  Merge pull request #66 from kinow/IMAGING-244
b751732 is described below

commit b751732a354ce908da9e10b30b99262824a4452c
Author: Bruno P. Kinoshita <kinow@apache.org>
AuthorDate: Sun Dec 15 17:00:07 2019 +1300

    [IMAGING-244]: Use isEmpty instead of comparing size() with integers
---
 src/changes/changes.xml                                           | 3 +++
 .../org/apache/commons/imaging/formats/gif/GifImageParser.java    | 8 ++++----
 .../apache/commons/imaging/formats/jpeg/exif/ExifRewriter.java    | 2 +-
 .../org/apache/commons/imaging/formats/jpeg/xmp/JpegRewriter.java | 2 +-
 .../org/apache/commons/imaging/formats/psd/PsdImageParser.java    | 6 +++---
 .../java/org/apache/commons/imaging/formats/tiff/TiffReader.java  | 4 ++--
 .../java/org/apache/commons/imaging/formats/tiff/TiffTags.java    | 2 +-
 src/main/java/org/apache/commons/imaging/palette/ColorGroup.java  | 2 +-
 .../org/apache/commons/imaging/palette/MedianCutQuantizer.java    | 2 +-
 9 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index c2274e0..7e85ac4 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -48,6 +48,9 @@ The <action> type attribute can be add,update,fix,remove.
       <action issue="IMAGING-146" dev="kinow" type="add">
         Add documentation for the color package
       </action>
+      <action issue="IMAGING-244" dev="kinow" type="add">
+        Use isEmpty instead of comparing size() with integers
+      </action>
       <action issue="IMAGING-243" dev="kinow" type="add" due-to="Andreas Menze">
         PNG Writer Indexed Color with semi-transparent Pixels and Better Compression
       </action>
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 de6142c..cffa321 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
@@ -670,13 +670,13 @@ public class GifImageParser extends ImageParser {
     private List<GifImageData> findAllImageData(GifImageContents imageContents) throws
ImageReadException {
         final List<ImageDescriptor> descriptors = findAllBlocks(imageContents.blocks,
IMAGE_SEPARATOR);
 
-        if (descriptors.size() == 0) {
+        if (descriptors.isEmpty()) {
             throw new ImageReadException("GIF: Couldn't read Image Descriptor");
         }
 
         final List<GraphicControlExtension> gcExtensions = findAllBlocks(imageContents.blocks,
GRAPHIC_CONTROL_EXTENSION);
 
-        if (gcExtensions.size() != 0 && gcExtensions.size() != descriptors.size())
{
+        if (!gcExtensions.isEmpty() && gcExtensions.size() != descriptors.size())
{
             throw new ImageReadException("GIF: Invalid amount of Graphic Control Extensions");
         }
 
@@ -687,7 +687,7 @@ public class GifImageParser extends ImageParser {
                 throw new ImageReadException(String.format("GIF: Couldn't read Image Descriptor
of image number %d", i));
             }
 
-            final GraphicControlExtension gce = gcExtensions.size() == 0 ? null : gcExtensions.get(i);
+            final GraphicControlExtension gce = gcExtensions.isEmpty() ? null : gcExtensions.get(i);
 
             imageData.add(new GifImageData(descriptor, gce));
         }
@@ -1141,7 +1141,7 @@ public class GifImageParser extends ImageParser {
                 result.add(xml);
             }
 
-            if (result.size() < 1) {
+            if (result.isEmpty()) {
                 return null;
             }
             if (result.size() > 1) {
diff --git a/src/main/java/org/apache/commons/imaging/formats/jpeg/exif/ExifRewriter.java
b/src/main/java/org/apache/commons/imaging/formats/jpeg/exif/ExifRewriter.java
index a712223..d347f59 100644
--- a/src/main/java/org/apache/commons/imaging/formats/jpeg/exif/ExifRewriter.java
+++ b/src/main/java/org/apache/commons/imaging/formats/jpeg/exif/ExifRewriter.java
@@ -392,7 +392,7 @@ public class ExifRewriter extends BinaryFileParser {
         TiffImageWriterBase writer;
         // Just use first APP1 segment for now.
         // Multiple APP1 segments are rare and poorly supported.
-        if (jfifPieces.exifPieces.size() > 0) {
+        if (!jfifPieces.exifPieces.isEmpty()) {
             JFIFPieceSegment exifPiece = null;
             exifPiece = (JFIFPieceSegment) jfifPieces.exifPieces.get(0);
 
diff --git a/src/main/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegRewriter.java b/src/main/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegRewriter.java
index fa2f501..62261e6 100644
--- a/src/main/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegRewriter.java
+++ b/src/main/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegRewriter.java
@@ -288,7 +288,7 @@ public class JpegRewriter extends BinaryFileParser {
 
         final List<JFIFPiece> result = new ArrayList<>(segments);
         if (lastAppIndex == -1) {
-            if (segments.size() < 1) {
+            if (segments.isEmpty()) {
                 throw new ImageWriteException("JPEG file has no APP segments.");
             }
             result.addAll(1, newSegments);
diff --git a/src/main/java/org/apache/commons/imaging/formats/psd/PsdImageParser.java b/src/main/java/org/apache/commons/imaging/formats/psd/PsdImageParser.java
index fca8d5d..75687f1 100644
--- a/src/main/java/org/apache/commons/imaging/formats/psd/PsdImageParser.java
+++ b/src/main/java/org/apache/commons/imaging/formats/psd/PsdImageParser.java
@@ -387,7 +387,7 @@ public class PsdImageParser extends ImageParser {
         final List<ImageResourceBlock> blocks = readImageResourceBlocks(byteSource,
                 new int[] { IMAGE_RESOURCE_ID_ICC_PROFILE, }, 1);
 
-        if ((blocks == null) || (blocks.size() < 1)) {
+        if ((blocks == null) || (blocks.isEmpty())) {
             return null;
         }
 
@@ -688,7 +688,7 @@ public class PsdImageParser extends ImageParser {
         final List<ImageResourceBlock> blocks = readImageResourceBlocks(byteSource,
                 new int[] { IMAGE_RESOURCE_ID_XMP, }, -1);
 
-        if ((blocks == null) || (blocks.size() < 1)) {
+        if ((blocks == null) || (blocks.isEmpty())) {
             return null;
         }
 
@@ -706,7 +706,7 @@ public class PsdImageParser extends ImageParser {
             xmpBlocks.addAll(blocks);
 //        }
 
-        if (xmpBlocks.size() < 1) {
+        if (xmpBlocks.isEmpty()) {
             return null;
         }
         if (xmpBlocks.size() > 1) {
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 befca84..11945b9 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
@@ -377,7 +377,7 @@ public class TiffReader extends BinaryFileParser {
         final Collector collector = new FirstDirectoryCollector(readImageData);
         read(byteSource, params, formatCompliance, collector);
         final TiffContents contents = collector.getContents();
-        if (contents.directories.size() < 1) {
+        if (contents.directories.isEmpty()) {
             throw new ImageReadException(
                     "Image did not contain any directories.");
         }
@@ -392,7 +392,7 @@ public class TiffReader extends BinaryFileParser {
         final Collector collector = new Collector(params);
         readDirectories(byteSource, formatCompliance, collector);
         final TiffContents contents = collector.getContents();
-        if (contents.directories.size() < 1) {
+        if (contents.directories.isEmpty()) {
             throw new ImageReadException(
                     "Image did not contain any directories.");
         }
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 076031a..7608abd 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
@@ -127,7 +127,7 @@ final class TiffTags {
     private static TagInfo getTag(final int directoryType, final List<TagInfo> possibleMatches)
{
         // Please keep this method in sync with TiffImageMetadata's findField()
 
-        if (possibleMatches.size() < 1) {
+        if (possibleMatches.isEmpty()) {
             return null;
         }
 
diff --git a/src/main/java/org/apache/commons/imaging/palette/ColorGroup.java b/src/main/java/org/apache/commons/imaging/palette/ColorGroup.java
index 3db565d..eef21d9 100644
--- a/src/main/java/org/apache/commons/imaging/palette/ColorGroup.java
+++ b/src/main/java/org/apache/commons/imaging/palette/ColorGroup.java
@@ -50,7 +50,7 @@ class ColorGroup {
         this.colorCounts = colorCounts;
         this.ignoreAlpha = ignoreAlpha;
 
-        if (colorCounts.size() < 1) {
+        if (colorCounts.isEmpty()) {
             throw new ImageWriteException("empty color_group");
         }
 
diff --git a/src/main/java/org/apache/commons/imaging/palette/MedianCutQuantizer.java b/src/main/java/org/apache/commons/imaging/palette/MedianCutQuantizer.java
index cb8e1ba..735104f 100644
--- a/src/main/java/org/apache/commons/imaging/palette/MedianCutQuantizer.java
+++ b/src/main/java/org/apache/commons/imaging/palette/MedianCutQuantizer.java
@@ -130,7 +130,7 @@ public class MedianCutQuantizer {
 
             colorGroup.paletteIndex = i;
 
-            if (colorGroup.colorCounts.size() < 1) {
+            if (colorGroup.colorCounts.isEmpty()) {
                 throw new ImageWriteException("empty color_group: "
                         + colorGroup);
             }


Mime
View raw message