[PATCH] Artifacts: ThemeDocument. Removed some zero length checks because we do not store zero length strings in the backing map

Wald Commits scm-commit at wald.intevation.org
Fri Aug 23 11:39:28 CEST 2013


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1377250764 -7200
# Node ID 835e07ee769d755e6061b96ad30c7cd3c3646a91
# Parent  819481cc919517f56a8ad887488a89bdf47afd69
Artifacts: ThemeDocument. Removed some zero length checks because we do not store zero length strings in the backing map.

diff -r 819481cc9195 -r 835e07ee769d artifacts/src/main/java/org/dive4elements/river/themes/ThemeDocument.java
--- a/artifacts/src/main/java/org/dive4elements/river/themes/ThemeDocument.java	Fri Aug 23 11:07:11 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/themes/ThemeDocument.java	Fri Aug 23 11:39:24 2013 +0200
@@ -148,7 +148,7 @@
 
     /** Parse string to be boolean with default if empty or unrecognized. */
     private static boolean parseBoolean(String value, boolean defaultsTo) {
-        if (value == null || value.length() == 0) {
+        if (value == null) {
             return defaultsTo;
         }
         if (value.equals("false")) {
@@ -169,7 +169,7 @@
      * @return \param value as integer or defaultsto if conversion failed.
      */
     private static int parseInteger(String value, int defaultsTo) {
-        if (value == null || value.length() == 0) {
+        if (value == null) {
             return defaultsTo;
         }
 
@@ -192,7 +192,7 @@
      * @return \param value as integer or defaultsto if conversion failed.
      */
     private static double parseDouble(String value, double defaultsTo) {
-        if (value == null || value.length() == 0) {
+        if (value == null) {
             return defaultsTo;
         }
 
@@ -241,7 +241,7 @@
 
     public Font parseTextFont() {
         String font = getValue(LABEL_FONT_FACE);
-        if (font == null || font.length() == 0) {
+        if (font == null) {
             return null;
         }
 
@@ -255,27 +255,24 @@
         return parseRGB(getTextColorString());
     }
 
-    public String getTextColorString() {
-        String textColor = getValue(LABEL_FONT_COLOR);
-        return textColor;
+    private String getTextColorString() {
+        return getValue(LABEL_FONT_COLOR);
     }
 
     public Color parseTextBackground() {
         String color = getLabelBackgroundColorString();
-        if (color == null || color.length() == 0) {
-            return Color.WHITE;
-        }
-        return parseRGB(color);
+        return color != null
+            ? parseRGB(color)
+            : Color.WHITE;
     }
 
     private String getLabelBackgroundColorString() {
         return getValue(LABEL_BGCOLOR);
     }
 
-
     public int parseLineWidth() {
         String size = getValue(LINE_SIZE);
-        if (size == null || size.length() == 0) {
+        if (size == null) {
             return 0;
         }
 
@@ -292,7 +289,7 @@
         String dash = getValue(LINE_STYLE);
 
         float[] def = {10};
-        if (dash == null || dash.length() == 0) {
+        if (dash == null) {
             return def;
         }
 
@@ -336,7 +333,7 @@
 
     public int parseTextStyle() {
         String style = getValue(LABEL_FONT_STYLE);
-        if (style == null || style.length() == 0) {
+        if (style == null) {
             return Font.PLAIN;
         }
 
@@ -379,14 +376,14 @@
         return parseDouble(bandWidth, 0);
     }
 
-    public static Color parseColor(String colorString) {
-        if (colorString == null || colorString.length() == 0) {
+    private static Color parseColor(String colorString) {
+        if (colorString == null) {
             return null;
         }
-        else if (colorString.indexOf("#") == 0) {
+        if (colorString.indexOf("#") == 0) {
             return parseHexColor(colorString);
         }
-        else if (colorString.indexOf(",") >= 0) {
+        if (colorString.indexOf(",") >= 0) {
             return parseRGB(colorString);
         }
 
@@ -401,12 +398,10 @@
      *
      * @return a Color or null, if <i>hex</i> is empty.
      */
-    public static Color parseHexColor(String hex) {
-        if (hex == null) {
-            return null;
-        }
-
-        return Color.decode(hex);
+    private static Color parseHexColor(String hex) {
+        return hex != null
+            ? Color.decode(hex)
+            : null;
     }
 
 
@@ -427,7 +422,7 @@
 
     public int parseTextSize() {
         String size = getValue(LABEL_FONT_SIZE);
-        if (size == null || size.length() == 0) {
+        if (size == null) {
             return 10;
         }
 
@@ -435,6 +430,7 @@
             return Integer.parseInt(size);
         }
         catch (NumberFormatException nfe) {
+            // Do nothing
         }
         return 10;
     }
@@ -449,17 +445,16 @@
             return null;
         }
         String rgb[] = rgbtext.split(",");
-        Color c = null;
         try {
-            c = new Color(
-                    Integer.parseInt(rgb[0].trim()),
-                    Integer.parseInt(rgb[1].trim()),
-                    Integer.parseInt(rgb[2].trim()));
+            return new Color(
+                Integer.parseInt(rgb[0].trim()),
+                Integer.parseInt(rgb[1].trim()),
+                Integer.parseInt(rgb[2].trim()));
         }
         catch (NumberFormatException nfe) {
-            c = null;
+            // Do nothing
         }
-        return c;
+        return null;
     }
 
     public String getLineColorString() {
@@ -525,21 +520,28 @@
 
     /**
      * Gets color from color field.
-     * @param theme    the theme document.
      * @return color.
      */
     public Color parseLineColorField() {
         String lineColorStr = getLineColorString();
-        logger.debug("parseLineColorField: lineColorStr = " +
-                (lineColorStr == null ? "null" : lineColorStr));
+        if (logger.isDebugEnabled()) {
+            logger.debug("parseLineColorField: lineColorStr = " +
+                (lineColorStr == null
+                     ? "null"
+                     : lineColorStr));
+        }
         return parseColor(lineColorStr);
     }
 
 
     public Color parseAreaLineColorField() {
         String lineColorStr = getAreaLineColorString();
-        logger.debug("parseLineColorField: lineColorStr = " +
-                (lineColorStr == null ? "null" : lineColorStr));
+        if (logger.isDebugEnabled()) {
+            logger.debug("parseLineColorField: lineColorStr = " +
+                (lineColorStr == null
+                    ? "null"
+                    : lineColorStr));
+        }
         return parseColor(lineColorStr);
     }
 
@@ -567,14 +569,21 @@
      * @return String representation of the MapserverStyle
      */
     public String createDynamicMapserverStyle(
-            float from, float to, float step, CallMeta meta)
-    {
+        float    from,
+        float    to,
+        float    step,
+        CallMeta meta
+    ) {
         MapserverStyle ms = new MapserverStyle();
 
         String strStartColor = getValue(WSPLGEN_STARTCOLOR);
-        Color startColor = strStartColor != null ? parseColor(strStartColor) : new Color(178, 201, 215);
+        Color startColor = strStartColor != null
+            ? parseColor(strStartColor)
+            : new Color(178, 201, 215);
         String strEndColor = getValue(WSPLGEN_ENDCOLOR);
-        Color endColor = strEndColor != null? parseColor(strEndColor) : new Color(2, 27, 42);
+        Color endColor = strEndColor != null
+            ? parseColor(strEndColor)
+            : new Color(2, 27, 42);
 
         to = to != 0 ? to : 9999;
         step = step != 0 ? step : to;
@@ -643,10 +652,8 @@
             return Resources.getMsg(meta, MSG_ISOBATH_CLASS,
                     new Object[] {val, val + step});
         }
-        else {
-            return Resources.getMsg(meta, MSG_ISOBATH_LASTCLASS,
-                    new Object[] {val});
-        }
+        return Resources.getMsg(meta, MSG_ISOBATH_LASTCLASS,
+                new Object[] {val});
     }
 
 
@@ -654,7 +661,7 @@
         String symbol    = getSymbol();
         String backcolor = getLabelBackgroundColorString();
         String linecolor = getLineColorString();
-        if (linecolor == null || "".equals(linecolor)) {
+        if (linecolor == null) {
             logger.warn("createMapserverStyle: linecolor String is empty");
             linecolor = "0,128,255";
         }
@@ -668,7 +675,7 @@
         Style s = new Style();
         s.setOutlineColor(linecolor.replace(",", " "));
 
-        if (backcolor != null && backcolor.length() > 0) {
+        if (backcolor != null) {
             s.setColor(backcolor.replace(",", " "));
         }
 
@@ -679,7 +686,7 @@
         String textcolor = getTextColorString();
         int    textsize  = parseTextSize();
 
-        if (textcolor != null && textcolor.length() > 0 && textsize > 0) {
+        if (textcolor != null && textsize > 0) {
             Label l = new Label();
             l.setColor(textcolor.replace(",", " "));
             l.setSize(textsize);


More information about the Dive4elements-commits mailing list