You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by eb...@apache.org on 2013/11/26 17:18:58 UTC

svn commit: r1545710 - in /commons/proper/imaging/trunk: pmd-ruleset.xml pom.xml src/conf/pmd-ruleset.xml src/main/java/org/apache/commons/imaging/ColorTools.java

Author: ebourg
Date: Tue Nov 26 16:18:58 2013
New Revision: 1545710

URL: http://svn.apache.org/r1545710
Log:
Adjust PMD rules

Added:
    commons/proper/imaging/trunk/src/conf/pmd-ruleset.xml
      - copied, changed from r1545174, commons/proper/imaging/trunk/pmd-ruleset.xml
Removed:
    commons/proper/imaging/trunk/pmd-ruleset.xml
Modified:
    commons/proper/imaging/trunk/pom.xml
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/ColorTools.java

Modified: commons/proper/imaging/trunk/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/pom.xml?rev=1545710&r1=1545709&r2=1545710&view=diff
==============================================================================
--- commons/proper/imaging/trunk/pom.xml (original)
+++ commons/proper/imaging/trunk/pom.xml Tue Nov 26 16:18:58 2013
@@ -261,7 +261,7 @@
         <configuration>
           <targetJdk>${maven.compile.target}</targetJdk>
           <rulesets>
-            <ruleset>${basedir}/pmd-ruleset.xml</ruleset>
+            <ruleset>${basedir}/src/conf/pmd-ruleset.xml</ruleset>
           </rulesets>
         </configuration>
       </plugin>

Copied: commons/proper/imaging/trunk/src/conf/pmd-ruleset.xml (from r1545174, commons/proper/imaging/trunk/pmd-ruleset.xml)
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/conf/pmd-ruleset.xml?p2=commons/proper/imaging/trunk/src/conf/pmd-ruleset.xml&p1=commons/proper/imaging/trunk/pmd-ruleset.xml&r1=1545174&r2=1545710&rev=1545710&view=diff
==============================================================================
--- commons/proper/imaging/trunk/pmd-ruleset.xml (original)
+++ commons/proper/imaging/trunk/src/conf/pmd-ruleset.xml Tue Nov 26 16:18:58 2013
@@ -65,6 +65,8 @@
   <rule ref="rulesets/java/migrating.xml"/>
   <rule ref="rulesets/java/optimizations.xml">
     <exclude name="AvoidInstantiatingObjectsInLoops"/>
+    <exclude name="LocalVariableCouldBeFinal"/>
+    <exclude name="MethodArgumentCouldBeFinal"/>
     <exclude name="RedundantFieldInitializer"/>
     <exclude name="PrematureDeclaration"/>
   </rule>

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/ColorTools.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/ColorTools.java?rev=1545710&r1=1545709&r2=1545710&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/ColorTools.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/ColorTools.java Tue Nov 26 16:18:58 2013
@@ -92,32 +92,32 @@ public class ColorTools {
     }
 
     public ColorModel deriveColorModel(final BufferedImage bi, final ColorSpace cs,
-            final boolean force_no_alpha) throws ImagingOpException {
-        return deriveColorModel(bi.getColorModel(), cs, force_no_alpha);
+            final boolean forceNoAlpha) throws ImagingOpException {
+        return deriveColorModel(bi.getColorModel(), cs, forceNoAlpha);
     }
 
-    public ColorModel deriveColorModel(final ColorModel old_cm, final ColorSpace cs,
-            final boolean force_no_alpha) throws ImagingOpException {
+    public ColorModel deriveColorModel(final ColorModel colorModel, final ColorSpace cs,
+            final boolean forceNoAlpha) throws ImagingOpException {
 
-        if (old_cm instanceof ComponentColorModel) {
-            final ComponentColorModel ccm = (ComponentColorModel) old_cm;
+        if (colorModel instanceof ComponentColorModel) {
+            final ComponentColorModel ccm = (ComponentColorModel) colorModel;
             // ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
-            if (force_no_alpha) {
+            if (forceNoAlpha) {
                 return new ComponentColorModel(cs, false, false,
                         Transparency.OPAQUE, ccm.getTransferType());
             }
             return new ComponentColorModel(cs, ccm.hasAlpha(),
                     ccm.isAlphaPremultiplied(), ccm.getTransparency(),
                     ccm.getTransferType());
-        } else if (old_cm instanceof DirectColorModel) {
-            final DirectColorModel dcm = (DirectColorModel) old_cm;
+        } else if (colorModel instanceof DirectColorModel) {
+            final DirectColorModel dcm = (DirectColorModel) colorModel;
 
-            final int old_mask = dcm.getRedMask() | dcm.getGreenMask()
+            final int oldMask = dcm.getRedMask() | dcm.getGreenMask()
                     | dcm.getBlueMask() | dcm.getAlphaMask();
 
-            final int old_bits = count_bits_in_mask(old_mask);
+            final int oldBits = countBitsInMask(oldMask);
 
-            return new DirectColorModel(cs, old_bits, dcm.getRedMask(),
+            return new DirectColorModel(cs, oldBits, dcm.getRedMask(),
                     dcm.getGreenMask(), dcm.getBlueMask(), dcm.getAlphaMask(),
                     dcm.isAlphaPremultiplied(), dcm.getTransferType());
         }
@@ -130,7 +130,7 @@ public class ColorTools {
         //
         // int old_masks[] = pcm.getMasks();
         // // System.out.println("old_mask: " + old_mask);
-        // int old_bits = count_bits_in_mask(old_masks);
+        // int old_bits = countBitsInMask(old_masks);
         // // System.out.println("old_bits: " + old_bits);
         //
         // // PackedColorModel(ColorSpace space, int bits, int rmask, int gmask,
@@ -145,7 +145,7 @@ public class ColorTools {
         throw new ImagingOpException("Could not clone unknown ColorModel Type.");
     }
 
-    private int count_bits_in_mask(int i) {
+    private int countBitsInMask(int i) {
         int count = 0;
         while (i != 0) {
             count += (i & 1);
@@ -176,37 +176,25 @@ public class ColorTools {
     }
 
     public BufferedImage convertTosRGB(final BufferedImage bi) {
-        ColorSpace cs_sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
-
         final ColorModel srgbCM = ColorModel.getRGBdefault();
-        cs_sRGB = srgbCM.getColorSpace();
-
-        return convertToColorSpace(bi, cs_sRGB);
+        return convertToColorSpace(bi, srgbCM.getColorSpace());
     }
 
-    protected BufferedImage convertFromColorSpace(final BufferedImage bi,
-            final ColorSpace from) {
-        ColorSpace cs_sRGB;
-
+    protected BufferedImage convertFromColorSpace(final BufferedImage bi, final ColorSpace from) {
         final ColorModel srgbCM = ColorModel.getRGBdefault();
-        cs_sRGB = srgbCM.getColorSpace();
-
-        return convertBetweenColorSpaces(bi, from, cs_sRGB);
-
+        return convertBetweenColorSpaces(bi, from, srgbCM.getColorSpace());
     }
 
-    public BufferedImage convertBetweenICCProfiles(final BufferedImage bi,
-            final ICC_Profile from, final ICC_Profile to) {
-        final ICC_ColorSpace cs_from = new ICC_ColorSpace(from);
-        final ICC_ColorSpace cs_to = new ICC_ColorSpace(to);
+    public BufferedImage convertBetweenICCProfiles(BufferedImage bi, ICC_Profile from, ICC_Profile to) {
+        final ICC_ColorSpace csFrom = new ICC_ColorSpace(from);
+        final ICC_ColorSpace csTo = new ICC_ColorSpace(to);
 
-        return convertBetweenColorSpaces(bi, cs_from, cs_to);
+        return convertBetweenColorSpaces(bi, csFrom, csTo);
     }
 
     public BufferedImage convertToICCProfile(final BufferedImage bi, final ICC_Profile to) {
-        final ICC_ColorSpace cs_to = new ICC_ColorSpace(to);
-
-        return convertToColorSpace(bi, cs_to);
+        final ICC_ColorSpace csTo = new ICC_ColorSpace(to);
+        return convertToColorSpace(bi, csTo);
     }
 
     public BufferedImage convertBetweenColorSpacesX2(BufferedImage bi,
@@ -215,7 +203,7 @@ public class ColorTools {
                 RenderingHints.VALUE_RENDER_QUALITY);
         hints.put(RenderingHints.KEY_COLOR_RENDERING,
                 RenderingHints.VALUE_COLOR_RENDER_QUALITY);
-        hints.put(RenderingHints.KEY_DITHERING,
+        hints.put(RenderingHints.KEY_DITHERING, 
                 RenderingHints.VALUE_DITHER_ENABLE);
 
         // bi = relabelColorSpace(bi, cs);



Re: svn commit: r1545710 - in /commons/proper/imaging/trunk: pmd-ruleset.xml pom.xml src/conf/pmd-ruleset.xml src/main/java/org/apache/commons/imaging/ColorTools.java

Posted by Gary Gregory <ga...@gmail.com>.
On Tue, Nov 26, 2013 at 1:40 PM, Emmanuel Bourg <eb...@apache.org> wrote:

> Le 26/11/2013 19:18, Gary Gregory a écrit :
>
> > I disagree, final everywhere is a good thing, please see
> > http://garygregory.wordpress.com/2013/01/26/the-final-kiss-in-java/
>
> Well, I guess we agree to disagree then :) Final everywhere is absurd
> imho, there are many cases where it's useless and increase the verbosity
> of the code, for example:
>
>     public ImageReadException(final String message) {
>         super(message);
>     }
>

Au contraire, final says that the reference to message is guaranteed to be
unchanged.

It is obvious in a one liner such as this one, but consistency is kind IMO.
When I see method after method that declare params as final (read only), I
can turn on my radar when I see one declared as read-write (by not using
final).

Gary


>
> Emmanuel Bourg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: svn commit: r1545710 - in /commons/proper/imaging/trunk: pmd-ruleset.xml pom.xml src/conf/pmd-ruleset.xml src/main/java/org/apache/commons/imaging/ColorTools.java

Posted by Emmanuel Bourg <eb...@apache.org>.
Le 26/11/2013 19:18, Gary Gregory a écrit :

> I disagree, final everywhere is a good thing, please see
> http://garygregory.wordpress.com/2013/01/26/the-final-kiss-in-java/

Well, I guess we agree to disagree then :) Final everywhere is absurd
imho, there are many cases where it's useless and increase the verbosity
of the code, for example:

    public ImageReadException(final String message) {
        super(message);
    }

Emmanuel Bourg


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1545710 - in /commons/proper/imaging/trunk: pmd-ruleset.xml pom.xml src/conf/pmd-ruleset.xml src/main/java/org/apache/commons/imaging/ColorTools.java

Posted by Gary Gregory <ga...@gmail.com>.
On Tue, Nov 26, 2013 at 12:58 PM, Emmanuel Bourg <eb...@apache.org> wrote:

> Le 26/11/2013 17:48, Damjan Jovanovic a écrit :
>
> > Why are we excluding those? Final variables are a good thing.
>
> Yes but final everywhere is a bit extreme and makes the code too verbose.
>

I disagree, final everywhere is a good thing, please see
http://garygregory.wordpress.com/2013/01/26/the-final-kiss-in-java/

Gary


>
> Emmanuel Bourg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: svn commit: r1545710 - in /commons/proper/imaging/trunk: pmd-ruleset.xml pom.xml src/conf/pmd-ruleset.xml src/main/java/org/apache/commons/imaging/ColorTools.java

Posted by Emmanuel Bourg <eb...@apache.org>.
Le 26/11/2013 17:48, Damjan Jovanovic a écrit :

> Why are we excluding those? Final variables are a good thing.

Yes but final everywhere is a bit extreme and makes the code too verbose.

Emmanuel Bourg


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1545710 - in /commons/proper/imaging/trunk: pmd-ruleset.xml pom.xml src/conf/pmd-ruleset.xml src/main/java/org/apache/commons/imaging/ColorTools.java

Posted by Damjan Jovanovic <da...@apache.org>.
On Tue, Nov 26, 2013 at 6:18 PM,  <eb...@apache.org> wrote:
> Author: ebourg
> Date: Tue Nov 26 16:18:58 2013
> New Revision: 1545710
>
> URL: http://svn.apache.org/r1545710
> Log:
> Adjust PMD rules
>

> Copied: commons/proper/imaging/trunk/src/conf/pmd-ruleset.xml (from r1545174, commons/proper/imaging/trunk/pmd-ruleset.xml)
> URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/conf/pmd-ruleset.xml?p2=commons/proper/imaging/trunk/src/conf/pmd-ruleset.xml&p1=commons/proper/imaging/trunk/pmd-ruleset.xml&r1=1545174&r2=1545710&rev=1545710&view=diff
> ==============================================================================
> --- commons/proper/imaging/trunk/pmd-ruleset.xml (original)
> +++ commons/proper/imaging/trunk/src/conf/pmd-ruleset.xml Tue Nov 26 16:18:58 2013
> @@ -65,6 +65,8 @@
>    <rule ref="rulesets/java/migrating.xml"/>
>    <rule ref="rulesets/java/optimizations.xml">
>      <exclude name="AvoidInstantiatingObjectsInLoops"/>
> +    <exclude name="LocalVariableCouldBeFinal"/>
> +    <exclude name="MethodArgumentCouldBeFinal"/>
>      <exclude name="RedundantFieldInitializer"/>
>      <exclude name="PrematureDeclaration"/>
>    </rule>
>

Why are we excluding those? Final variables are a good thing.

Damjan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org