xmlgraphics-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spepp...@apache.org
Subject svn commit: r1048990 - in /xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color: ColorUtil.java ColorWithAlternatives.java
Date Tue, 14 Dec 2010 09:15:14 GMT
Author: spepping
Date: Tue Dec 14 09:15:14 2010
New Revision: 1048990

URL: http://svn.apache.org/viewvc?rev=1048990&view=rev
Log:
Suggested changes to ColorUtil.isSameColor

Modified:
    xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorUtil.java
    xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorWithAlternatives.java

Modified: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorUtil.java?rev=1048990&r1=1048989&r2=1048990&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorUtil.java
(original)
+++ xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorUtil.java
Tue Dec 14 09:15:14 2010
@@ -121,16 +121,17 @@ public final class ColorUtil {
 
         //Consider same-ness only between colors of the same class (not subclasses)
         //but consider a ColorWithAlternatives without alternatives to be the same as a Color.
-        boolean skipClassTest = false;
-        if (col1.getClass() == ColorWithAlternatives.class
-                && !((ColorWithAlternatives)col1).hasAlternativeColors()) {
-            skipClassTest = true;
-        }
-        if (col2.getClass() == ColorWithAlternatives.class
-                && !((ColorWithAlternatives)col2).hasAlternativeColors()) {
-            skipClassTest = true;
+        Class<?> cl1 = col1.getClass();
+        if (col1 instanceof ColorWithAlternatives
+                && !((ColorWithAlternatives) col1).hasAlternativeColors()) {
+            cl1 = Color.class;
+        }
+        Class<?> cl2 = col2.getClass();
+        if (col2 instanceof ColorWithAlternatives
+                && !((ColorWithAlternatives) col2).hasAlternativeColors()) {
+            cl2 = Color.class;
         }
-        if (!skipClassTest && col1.getClass() != col2.getClass()) {
+        if (cl1 != cl2) {
             return false;
         }
 
@@ -153,26 +154,9 @@ public final class ColorUtil {
 
         //Compare alternative colors, order is relevant
         if (col1 instanceof ColorWithAlternatives && col2 instanceof ColorWithAlternatives)
{
-            ColorWithAlternatives ca1 = (ColorWithAlternatives)col1;
-            ColorWithAlternatives ca2 = (ColorWithAlternatives)col2;
-            if (ca1.hasAlternativeColors() && !ca2.hasAlternativeColors()) {
-                return false;
-            } else if (!ca1.hasAlternativeColors() && ca2.hasAlternativeColors())
{
-                return false;
-            } if (ca1.hasAlternativeColors()) {
-                Color[] alt1 = ca1.getAlternativeColors();
-                Color[] alt2 = ca2.getAlternativeColors();
-                if (alt1.length != alt2.length) {
-                    return false;
-                }
-                for (int i = 0, c = alt1.length; i < c; i++) {
-                    Color c1 = alt1[i];
-                    Color c2 = alt2[i];
-                    if (!isSameColor(c1, c2)) {
-                        return false;
-                    }
-                }
-            }
+            ColorWithAlternatives ca1 = (ColorWithAlternatives) col1;
+            ColorWithAlternatives ca2 = (ColorWithAlternatives) col2;
+            return ca1.hasSameAlternativeColors(ca2);
         }
 
         return true;

Modified: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorWithAlternatives.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorWithAlternatives.java?rev=1048990&r1=1048989&r2=1048990&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorWithAlternatives.java
(original)
+++ xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorWithAlternatives.java
Tue Dec 14 09:15:14 2010
@@ -164,6 +164,30 @@ public class ColorWithAlternatives exten
         return this.alternativeColors != null && this.alternativeColors.length >
0;
     }
 
+    public boolean hasSameAlternativeColors(ColorWithAlternatives col) {
+        if (!hasAlternativeColors()) {
+            return !col.hasAlternativeColors();
+        }
+        // this.hasAlternativeColors()
+        if (!col.hasAlternativeColors()) {
+            return false;
+        }
+        // this.hasAlternativeColors() && col.hasAlternativeColors()
+        Color[] alt1 = getAlternativeColors();
+        Color[] alt2 = col.getAlternativeColors();
+        if (alt1.length != alt2.length) {
+            return false;
+        }
+        for (int i = 0, c = alt1.length; i < c; i++) {
+            Color c1 = alt1[i];
+            Color c2 = alt2[i];
+            if (!ColorUtil.isSameColor(c1, c2)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
     /**
      * Returns the first alternative color found with the given color space type.
      * @param colorSpaceType the color space type ({@link ColorSpace}.TYPE_*).



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org


Mime
View raw message