myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tandrasc...@apache.org
Subject [myfaces] branch master updated: refactored
Date Tue, 13 Aug 2019 09:13:02 GMT
This is an automated email from the ASF dual-hosted git repository.

tandraschko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces.git


The following commit(s) were added to refs/heads/master by this push:
     new 6187457  refactored
6187457 is described below

commit 61874577ea63e27f8f65cac3ffedaf851a760b28
Author: Thomas Andraschko <tandraschko@apache.org>
AuthorDate: Tue Aug 13 11:12:54 2019 +0200

    refactored
---
 .../javax/faces/convert/BigDecimalConverter.java   |  55 +++----
 .../javax/faces/convert/BigIntegerConverter.java   |  59 +++----
 .../java/javax/faces/convert/BooleanConverter.java |  59 +++----
 .../java/javax/faces/convert/ByteConverter.java    |  59 +++----
 .../javax/faces/convert/CharacterConverter.java    |  59 +++----
 .../java/javax/faces/convert/DoubleConverter.java  |  58 +++----
 .../java/javax/faces/convert/FloatConverter.java   |  59 +++----
 .../java/javax/faces/convert/IntegerConverter.java |  59 +++----
 .../java/javax/faces/convert/LongConverter.java    |  57 +++----
 .../java/javax/faces/convert/NumberConverter.java  | 178 ++++++++++-----------
 .../java/javax/faces/convert/ShortConverter.java   |  59 +++----
 11 files changed, 344 insertions(+), 417 deletions(-)

diff --git a/api/src/main/java/javax/faces/convert/BigDecimalConverter.java b/api/src/main/java/javax/faces/convert/BigDecimalConverter.java
index ac8110f..91ab748 100755
--- a/api/src/main/java/javax/faces/convert/BigDecimalConverter.java
+++ b/api/src/main/java/javax/faces/convert/BigDecimalConverter.java
@@ -46,56 +46,53 @@ public class BigDecimalConverter
     @Override
     public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String
value)
     {
-        if (facesContext == null)
+        if (facesContext == null || uiComponent == null)
         {
-            throw new NullPointerException("facesContext");
+            throw new NullPointerException(); // should never happen
         }
-        if (uiComponent == null)
+
+        if (value == null)
         {
-            throw new NullPointerException("uiComponent");
+            return null;
         }
-
-        if (value != null)
+        
+        value = value.trim();
+        if (value.length() < 1)
+        {
+            return null;
+        }
+        
+        try
         {
-            value = value.trim();
-            if (value.length() > 0)
-            {
-                try
-                {
-                    return new BigDecimal(value.trim());
-                }
-                catch (NumberFormatException e)
-                {
-                    throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
-                                   DECIMAL_ID,
-                                   new Object[]{value,new BigDecimal(4815.16).toString(),
-                                                _MessageUtils.getLabel(facesContext, uiComponent)}),
e);
-                }
-            }
+            return new BigDecimal(value.trim());
+        }
+        catch (NumberFormatException e)
+        {
+            throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
+                           DECIMAL_ID,
+                           new Object[]{value,new BigDecimal(4815.16).toString(),
+                                        _MessageUtils.getLabel(facesContext, uiComponent)}),
e);
         }
-        return null;
     }
 
     @Override
     public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object
value)
     {
-        if (facesContext == null)
+        if (facesContext == null || uiComponent == null)
         {
-            throw new NullPointerException("facesContext");
-        }
-        if (uiComponent == null)
-        {
-            throw new NullPointerException("uiComponent");
+            throw new NullPointerException(); // should never happen
         }
 
         if (value == null)
         {
             return "";
         }
+
         if (value instanceof String)
         {
-            return (String)value;
+            return (String) value;
         }
+        
         try
         {
             return ((BigDecimal)value).toString();
diff --git a/api/src/main/java/javax/faces/convert/BigIntegerConverter.java b/api/src/main/java/javax/faces/convert/BigIntegerConverter.java
index 375c419..a8f9d14 100755
--- a/api/src/main/java/javax/faces/convert/BigIntegerConverter.java
+++ b/api/src/main/java/javax/faces/convert/BigIntegerConverter.java
@@ -29,72 +29,65 @@ import java.math.BigInteger;
  * see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF
Specification</a>
  */
 @JSFConverter
-public class BigIntegerConverter
-        implements Converter
+public class BigIntegerConverter implements Converter
 {
-    // FIELDS
     public static final String CONVERTER_ID = "javax.faces.BigInteger";
     public static final String STRING_ID = "javax.faces.converter.STRING";
     public static final String BIGINTEGER_ID = "javax.faces.converter.BigIntegerConverter.BIGINTEGER";
 
-    // CONSTRUCTORS
     public BigIntegerConverter()
     {
     }
 
-    // METHODS
     @Override
     public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String
value)
     {
-        if (facesContext == null)
+        if (facesContext == null || uiComponent == null)
         {
-            throw new NullPointerException("facesContext");
+            throw new NullPointerException(); // should never happen
         }
-        if (uiComponent == null)
+
+        if (value == null)
         {
-            throw new NullPointerException("uiComponent");
+            return null;
         }
-
-        if (value != null)
+        
+        value = value.trim();
+        if (value.length() < 1)
+        {
+            return null;
+        }
+        
+        try
         {
-            value = value.trim();
-            if (value.length() > 0)
-            {
-                try
-                {
-                    return new BigInteger(value.trim());
-                }
-                catch (NumberFormatException e)
-                {
-                    throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
-                                   BIGINTEGER_ID,
-                                   new Object[]{value,"2345",_MessageUtils.getLabel(facesContext,
uiComponent)}), e);
-                }
-            }
+            return new BigInteger(value.trim());
+        }
+        catch (NumberFormatException e)
+        {
+            throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
+                           BIGINTEGER_ID,
+                           new Object[]{value,"2345",_MessageUtils.getLabel(facesContext,
uiComponent)}), e);
         }
-        return null;
     }
 
     @Override
     public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object
value)
     {
-        if (facesContext == null)
-        {
-            throw new NullPointerException("facesContext");
-        }
-        if (uiComponent == null)
+        if (facesContext == null || uiComponent == null)
         {
-            throw new NullPointerException("uiComponent");
+            throw new NullPointerException(); // should never happen
         }
 
         if (value == null)
         {
             return "";
         }
+
         if (value instanceof String)
         {
-            return (String)value;
+            return (String) value;
         }
+
         try
         {
             return ((BigInteger)value).toString();
diff --git a/api/src/main/java/javax/faces/convert/BooleanConverter.java b/api/src/main/java/javax/faces/convert/BooleanConverter.java
index 66e80cd..e011fa2 100755
--- a/api/src/main/java/javax/faces/convert/BooleanConverter.java
+++ b/api/src/main/java/javax/faces/convert/BooleanConverter.java
@@ -27,72 +27,65 @@ import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFConvert
  * see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF
Specification</a>
  */
 @JSFConverter
-public class BooleanConverter
-        implements Converter
+public class BooleanConverter implements Converter
 {
-    // FIELDS
     public static final String CONVERTER_ID = "javax.faces.Boolean";
     public static final String STRING_ID = "javax.faces.converter.STRING";
     public static final String BOOLEAN_ID = "javax.faces.converter.BooleanConverter.BOOLEAN";
 
-    // CONSTRUCTORS
     public BooleanConverter()
     {
     }
 
-    // METHODS
     @Override
     public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String
value)
     {
-        if (facesContext == null)
+        if (facesContext == null || uiComponent == null)
         {
-            throw new NullPointerException("facesContext");
+            throw new NullPointerException(); // should never happen
         }
-        if (uiComponent == null)
+
+        if (value == null)
         {
-            throw new NullPointerException("uiComponent");
+            return null;
         }
-
-        if (value != null)
+        
+        value = value.trim();
+        if (value.length() < 1)
+        {
+            return null;
+        }
+        
+        try
         {
-            value = value.trim();
-            if (value.length() > 0)
-            {
-                try
-                {
-                    return Boolean.valueOf(value);
-                }
-                catch (Exception e)
-                {
-                    throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
-                                       BOOLEAN_ID,
-                                       new Object[]{value,_MessageUtils.getLabel(facesContext,
uiComponent)}), e);
-                }
-            }
+            return Boolean.valueOf(value);
+        }
+        catch (Exception e)
+        {
+            throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
+                               BOOLEAN_ID,
+                               new Object[]{value,_MessageUtils.getLabel(facesContext, uiComponent)}),
e);
         }
-        return null;
     }
 
     @Override
     public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object
value)
     {
-        if (facesContext == null)
+        if (facesContext == null || uiComponent == null)
         {
-            throw new NullPointerException("facesContext");
-        }
-        if (uiComponent == null)
-        {
-            throw new NullPointerException("uiComponent");
+            throw new NullPointerException(); // should never happen
         }
 
         if (value == null)
         {
             return "";
         }
+
         if (value instanceof String)
         {
-            return (String)value;
+            return (String) value;
         }
+        
         try
         {
             return ((Boolean)value).toString();
diff --git a/api/src/main/java/javax/faces/convert/ByteConverter.java b/api/src/main/java/javax/faces/convert/ByteConverter.java
index f136202..84654a0 100755
--- a/api/src/main/java/javax/faces/convert/ByteConverter.java
+++ b/api/src/main/java/javax/faces/convert/ByteConverter.java
@@ -27,72 +27,65 @@ import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFConvert
  * see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF
Specification</a>
  */
 @JSFConverter
-public class ByteConverter
-        implements Converter
+public class ByteConverter implements Converter
 {
-    // FIELDS
     public static final String CONVERTER_ID = "javax.faces.Byte";
     public static final String STRING_ID = "javax.faces.converter.STRING";
     public static final String BYTE_ID = "javax.faces.converter.ByteConverter.BYTE";
 
-    // CONSTRUCTORS
     public ByteConverter()
     {
     }
 
-    // METHODS
     @Override
     public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String
value)
     {
-        if (facesContext == null)
+        if (facesContext == null || uiComponent == null)
         {
-            throw new NullPointerException("facesContext");
+            throw new NullPointerException(); // should never happen
         }
-        if (uiComponent == null)
+
+        if (value == null)
         {
-            throw new NullPointerException("uiComponent");
+            return null;
         }
-
-        if (value != null)
+        
+        value = value.trim();
+        if (value.length() < 1)
+        {
+            return null;
+        }
+        
+        try
         {
-            value = value.trim();
-            if (value.length() > 0)
-            {
-                try
-                {
-                    return Byte.valueOf(value);
-                }
-                catch (NumberFormatException e)
-                {
-                    throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
-                                   BYTE_ID,
-                                   new Object[]{value,"156",_MessageUtils.getLabel(facesContext,
uiComponent)}), e);
-                }
-            }
+            return Byte.valueOf(value);
+        }
+        catch (NumberFormatException e)
+        {
+            throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
+                           BYTE_ID,
+                           new Object[]{value,"156",_MessageUtils.getLabel(facesContext,
uiComponent)}), e);
         }
-        return null;
     }
 
     @Override
     public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object
value)
     {
-        if (facesContext == null)
+        if (facesContext == null || uiComponent == null)
         {
-            throw new NullPointerException("facesContext");
-        }
-        if (uiComponent == null)
-        {
-            throw new NullPointerException("uiComponent");
+            throw new NullPointerException(); // should never happen
         }
 
         if (value == null)
         {
             return "";
         }
+
         if (value instanceof String)
         {
-            return (String)value;
+            return (String) value;
         }
+        
         try
         {
             return Byte.toString(((Number)value).byteValue());
diff --git a/api/src/main/java/javax/faces/convert/CharacterConverter.java b/api/src/main/java/javax/faces/convert/CharacterConverter.java
index 1897768..94067a1 100755
--- a/api/src/main/java/javax/faces/convert/CharacterConverter.java
+++ b/api/src/main/java/javax/faces/convert/CharacterConverter.java
@@ -27,72 +27,65 @@ import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFConvert
  * see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF
Specification</a>
  */
 @JSFConverter
-public class CharacterConverter
-        implements Converter
+public class CharacterConverter implements Converter
 {
-    // FIELDS
     public static final String CONVERTER_ID = "javax.faces.Character";
     public static final String STRING_ID = "javax.faces.converter.STRING";
     public static final String CHARACTER_ID = "javax.faces.converter.CharacterConverter.CHARACTER";
 
-    // CONSTRUCTORS
     public CharacterConverter()
     {
     }
 
-    // METHODS
     @Override
     public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String
value)
     {
-        if (facesContext == null)
+        if (facesContext == null || uiComponent == null)
         {
-            throw new NullPointerException("facesContext");
+            throw new NullPointerException(); // should never happen
         }
-        if (uiComponent == null)
+
+        if (value == null)
         {
-            throw new NullPointerException("uiComponent");
+            return null;
         }
-
-        if (value != null)
+        
+        value = value.trim();
+        if (value.length() < 1)
+        {
+            return null;
+        }
+        
+        try
         {
-            value = value.trim();
-            if (value.length() > 0)
-            {
-                try
-                {
-                    return Character.valueOf(value.charAt(0));
-                }
-                catch(Exception e)
-                {
-                    throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
-                                        CHARACTER_ID,
-                                        new Object[]{value,_MessageUtils.getLabel(facesContext,
uiComponent)}), e);
-                }
-            }
+            return Character.valueOf(value.charAt(0));
+        }
+        catch(Exception e)
+        {
+            throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
+                                CHARACTER_ID,
+                                new Object[]{value,_MessageUtils.getLabel(facesContext, uiComponent)}),
e);
         }
-        return null;
     }
 
     @Override
     public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object
value)
     {
-        if (facesContext == null)
+        if (facesContext == null || uiComponent == null)
         {
-            throw new NullPointerException("facesContext");
-        }
-        if (uiComponent == null)
-        {
-            throw new NullPointerException("uiComponent");
+            throw new NullPointerException(); // should never happen
         }
 
         if (value == null)
         {
             return "";
         }
+
         if (value instanceof String)
         {
-            return (String)value;
+            return (String) value;
         }
+        
         try
         {
             return ((Character)value).toString();
diff --git a/api/src/main/java/javax/faces/convert/DoubleConverter.java b/api/src/main/java/javax/faces/convert/DoubleConverter.java
index 0bf461b..ad64c21 100755
--- a/api/src/main/java/javax/faces/convert/DoubleConverter.java
+++ b/api/src/main/java/javax/faces/convert/DoubleConverter.java
@@ -32,48 +32,44 @@ import java.util.Locale;
 @JSFConverter
 public class DoubleConverter implements Converter
 {
-    // API FIELDS
     public static final String CONVERTER_ID = "javax.faces.Double";
     public static final String STRING_ID = "javax.faces.converter.STRING";
     public static final String DOUBLE_ID = "javax.faces.converter.DoubleConverter.DOUBLE";
 
-    // CONSTRUCTORS
     public DoubleConverter()
     {
     }
 
-    // METHODS
     @Override
     public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String
value)
     {
-        if (facesContext == null)
+        if (facesContext == null || uiComponent == null)
         {
-            throw new NullPointerException("facesContext");
+            throw new NullPointerException(); // should never happen
         }
-        if (uiComponent == null)
+
+        if (value == null)
         {
-            throw new NullPointerException("uiComponent");
+            return null;
         }
-
-        if (value != null)
+        
+        value = value.trim();
+        if (value.length() < 1)
         {
-            value = value.trim();
-            if (value.length() > 0)
-            {
-                try
-                {
-                    value = fixLocale(facesContext, value);
-                    return Double.valueOf(value);
-                }
-                catch (NumberFormatException e)
-                {
-                    throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
-                                   DOUBLE_ID,
-                                   new Object[]{value,"4214",_MessageUtils.getLabel(facesContext,
uiComponent)}), e);
-                }
-            }
+            return null;
+        }
+        
+        try
+        {
+            value = fixLocale(facesContext, value);
+            return Double.valueOf(value);
+        }
+        catch (NumberFormatException e)
+        {
+            throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
+                           DOUBLE_ID,
+                           new Object[]{value,"4214",_MessageUtils.getLabel(facesContext,
uiComponent)}), e);
         }
-        return null;
     }
 
     /**
@@ -132,23 +128,21 @@ public class DoubleConverter implements Converter
     @Override
     public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object
value)
     {
-        if (facesContext == null)
+        if (facesContext == null || uiComponent == null)
         {
-            throw new NullPointerException("facesContext");
-        }
-        if (uiComponent == null)
-        {
-            throw new NullPointerException("uiComponent");
+            throw new NullPointerException(); // should never happen
         }
 
         if (value == null)
         {
             return "";
         }
+
         if (value instanceof String)
         {
-            return (String)value;
+            return (String) value;
         }
+
         try
         {
             return Double.toString(((Number)value).doubleValue());
diff --git a/api/src/main/java/javax/faces/convert/FloatConverter.java b/api/src/main/java/javax/faces/convert/FloatConverter.java
index 12d82d2..6c649c5 100755
--- a/api/src/main/java/javax/faces/convert/FloatConverter.java
+++ b/api/src/main/java/javax/faces/convert/FloatConverter.java
@@ -27,75 +27,68 @@ import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFConvert
  * see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF
Specification</a>
  */
 @JSFConverter
-public class FloatConverter
-        implements Converter
+public class FloatConverter implements Converter
 {
-    // FIELDS
     public static final String CONVERTER_ID = "javax.faces.Float";
     public static final String STRING_ID = "javax.faces.converter.STRING";
     public static final String FLOAT_ID = "javax.faces.converter.FloatConverter.FLOAT";
 
-    // CONSTRUCTORS
     public FloatConverter()
     {
     }
 
-    // METHODS
     @Override
     public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String
value)
     {
-        if (facesContext == null)
+        if (facesContext == null || uiComponent == null)
         {
-            throw new NullPointerException("facesContext");
+            throw new NullPointerException(); // should never happen
         }
-        if (uiComponent == null)
+
+        if (value == null)
+        {
+            return null;
+        }
+        
+        value = value.trim();
+        if (value.length() < 1)
         {
-            throw new NullPointerException("uiComponent");
+            return null;
         }
 
-        if (value != null)
+        try
         {
-            value = value.trim();
-            if (value.length() > 0)
-            {
-                try
-                {
-                    return Float.valueOf(value);
-                }
-                catch (NumberFormatException e)
-                {
-                    throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
-                                   FLOAT_ID,
-                                   new Object[]{value,"50000",_MessageUtils.getLabel(facesContext,
uiComponent)}), e);
-                }
-            }
+            return Float.valueOf(value);
+        }
+        catch (NumberFormatException e)
+        {
+            throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
+                           FLOAT_ID,
+                           new Object[]{value,"50000",_MessageUtils.getLabel(facesContext,
uiComponent)}), e);
         }
-        return null;
     }
 
     @Override
     public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object
value)
     {
-        if (facesContext == null)
-        {
-            throw new NullPointerException("facesContext");
-        }
-        if (uiComponent == null)
+        if (facesContext == null || uiComponent == null)
         {
-            throw new NullPointerException("uiComponent");
+            throw new NullPointerException(); // should never happen
         }
 
         if (value == null)
         {
             return "";
         }
+
         if (value instanceof String)
         {
-            return (String)value;
+            return (String) value;
         }
+
         try
         {
-            return Float.toString(((Number)value).floatValue());
+            return Float.toString(((Number) value).floatValue());
         }
         catch (Exception e)
         {
diff --git a/api/src/main/java/javax/faces/convert/IntegerConverter.java b/api/src/main/java/javax/faces/convert/IntegerConverter.java
index d11e7bb..f04e11f 100755
--- a/api/src/main/java/javax/faces/convert/IntegerConverter.java
+++ b/api/src/main/java/javax/faces/convert/IntegerConverter.java
@@ -27,75 +27,68 @@ import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFConvert
  * see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF
Specification</a>
  */
 @JSFConverter
-public class IntegerConverter
-        implements Converter
+public class IntegerConverter implements Converter
 {
-    // FIELDS
     public static final String CONVERTER_ID = "javax.faces.Integer";
     public static final String STRING_ID = "javax.faces.converter.STRING";
     public static final String INTEGER_ID = "javax.faces.converter.IntegerConverter.INTEGER";
 
-    // CONSTRUCTORS
     public IntegerConverter()
     {
     }
 
-    // METHODS
     @Override
     public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String
value)
     {
-        if (facesContext == null)
+        if (facesContext == null || uiComponent == null)
         {
-            throw new NullPointerException("facesContext");
+            throw new NullPointerException(); // should never happen
         }
-        if (uiComponent == null)
+
+        if (value == null)
+        {
+            return null;
+        }
+        
+        value = value.trim();
+        if (value.length() < 1)
         {
-            throw new NullPointerException("uiComponent");
+            return null;
         }
 
-        if (value != null)
+        try
         {
-            value = value.trim();
-            if (value.length() > 0)
-            {
-                try
-                {
-                    return Integer.valueOf(value);
-                }
-                catch (NumberFormatException e)
-                {
-                    throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
-                                   INTEGER_ID,
-                                   new Object[]{value,"21",_MessageUtils.getLabel(facesContext,
uiComponent)}), e);
-                }
-            }
+            return Integer.valueOf(value);
+        }
+        catch (NumberFormatException e)
+        {
+            throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
+                           INTEGER_ID,
+                           new Object[]{value,"21",_MessageUtils.getLabel(facesContext, uiComponent)}),
e);
         }
-        return null;
     }
 
     @Override
     public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object
value)
     {
-        if (facesContext == null)
-        {
-            throw new NullPointerException("facesContext");
-        }
-        if (uiComponent == null)
+        if (facesContext == null || uiComponent == null)
         {
-            throw new NullPointerException("uiComponent");
+            throw new NullPointerException(); // should never happen
         }
 
         if (value == null)
         {
             return "";
         }
+
         if (value instanceof String)
         {
-            return (String)value;
+            return (String) value;
         }
+
         try
         {
-            return Integer.toString(((Number)value).intValue());
+            return Integer.toString(((Number) value).intValue());
         }
         catch (Exception e)
         {
diff --git a/api/src/main/java/javax/faces/convert/LongConverter.java b/api/src/main/java/javax/faces/convert/LongConverter.java
index 02d9d56..019cc8f 100755
--- a/api/src/main/java/javax/faces/convert/LongConverter.java
+++ b/api/src/main/java/javax/faces/convert/LongConverter.java
@@ -27,75 +27,68 @@ import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFConvert
  * see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF
Specification</a>
  */
 @JSFConverter
-public class LongConverter
-        implements Converter
+public class LongConverter implements Converter
 {
-    // FIELDS
     public static final String CONVERTER_ID = "javax.faces.Long";
     public static final String STRING_ID = "javax.faces.converter.STRING";
     public static final String LONG_ID = "javax.faces.converter.LongConverter.LONG";
 
-    // CONSTRUCTORS
     public LongConverter()
     {
     }
 
-    // METHODS
     @Override
     public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String
value)
     {
-        if (facesContext == null)
+        if (facesContext == null || uiComponent == null)
         {
-            throw new NullPointerException("facesContext");
+            throw new NullPointerException(); // should never happen
         }
-        if (uiComponent == null)
+
+        if (value == null)
+        {
+            return null;
+        }
+        
+        value = value.trim();
+        if (value.length() < 1)
         {
-            throw new NullPointerException("uiComponent");
+            return null;
         }
 
-        if (value != null)
+        try
         {
-            value = value.trim();
-            if (value.length() > 0)
-            {
-                try
-                {
-                    return Long.valueOf(value);
-                }
-                catch (NumberFormatException e)
-                {
-                    throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
-                               LONG_ID,
-                               new Object[]{value,"9392218515",_MessageUtils.getLabel(facesContext,
uiComponent)}), e);
-                }
-            }
+            return Long.valueOf(value);
+        }
+        catch (NumberFormatException e)
+        {
+            throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
+                       LONG_ID,
+                       new Object[]{value,"9392218515",_MessageUtils.getLabel(facesContext,
uiComponent)}), e);
         }
-        return null;
     }
 
     @Override
     public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object
value)
     {
-        if (facesContext == null)
-        {
-            throw new NullPointerException("facesContext");
-        }
-        if (uiComponent == null)
+        if (facesContext == null || uiComponent == null)
         {
-            throw new NullPointerException("uiComponent");
+            throw new NullPointerException(); // should never happen
         }
 
         if (value == null)
         {
             return "";
         }
+
         if (value instanceof String)
         {
             return (String)value;
         }
+
         try
         {
-            return Long.toString(((Number)value).longValue());
+            return Long.toString(((Number) value).longValue());
         }
         catch (Exception e)
         {
diff --git a/api/src/main/java/javax/faces/convert/NumberConverter.java b/api/src/main/java/javax/faces/convert/NumberConverter.java
index 40a08fa..51efe3f 100755
--- a/api/src/main/java/javax/faces/convert/NumberConverter.java
+++ b/api/src/main/java/javax/faces/convert/NumberConverter.java
@@ -53,10 +53,8 @@ import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFPropert
     name="binding", 
     returnType = "javax.faces.convert.NumberConverter",
     longDesc = "A ValueExpression that evaluates to a NumberConverter.")
-public class NumberConverter
-        implements Converter, PartialStateHolder
+public class NumberConverter implements Converter, PartialStateHolder
 {
-    // API FIELDS
     public static final String CONVERTER_ID = "javax.faces.Number";
     public static final String STRING_ID = "javax.faces.converter.STRING";
     public static final String CURRENCY_ID = "javax.faces.converter.NumberConverter.CURRENCY";
@@ -82,113 +80,110 @@ public class NumberConverter
     private boolean _minFractionDigitsSet;
     private boolean _minIntegerDigitsSet;
 
-
-    // CONSTRUCTORS
     public NumberConverter()
     {
     }
 
-    // METHODS
     @Override
     public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String
value)
     {
-        if (facesContext == null)
+        if (facesContext == null || uiComponent == null)
+        {
+            throw new NullPointerException(); // should never happen
+        }
+
+        if (value == null)
         {
-            throw new NullPointerException("facesContext");
+            return null;
         }
-        if (uiComponent == null)
+        
+        value = value.trim();
+        if (value.length() < 1)
         {
-            throw new NullPointerException("uiComponent");
+            return null;
+        }
+        
+        NumberFormat format = getNumberFormat(facesContext);
+        format.setParseIntegerOnly(_integerOnly);
+
+        DecimalFormat df = (DecimalFormat)format;
+
+        // The best we can do in this case is check if there is a ValueExpression
+        // with a BigDecimal as returning type , and if that so enable BigDecimal parsing
+        // to prevent loss in precision, and do not break existing examples (since
+        // in those cases it is expected to return Double). See MYFACES-1890 and TRINIDAD-1124
+        // for details
+        ValueExpression valueExpression = uiComponent.getValueExpression("value");
+        Class<?> destType = null;
+        if (valueExpression != null)
+        {
+            destType = valueExpression.getType(facesContext.getELContext());
+            if (destType != null
+                && (BigDecimal.class.isAssignableFrom(destType) || BigInteger.class.isAssignableFrom(destType)))
+            {
+                df.setParseBigDecimal(true);
+            }
         }
 
-        if (value != null)
+        DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
+        boolean changed = false;
+        if(dfs.getGroupingSeparator() == '\u00a0')
         {
-            value = value.trim();
-            if (value.length() > 0)
+            dfs.setGroupingSeparator(' ');
+            df.setDecimalFormatSymbols(dfs);
+            value = value.replace('\u00a0', ' ');
+            changed = true;
+        }
+
+        formatCurrency(format);
+
+        try
+        {
+            return parse(value, format, destType);
+        }
+        catch (ParseException e)
+        {
+            if(changed)
+            {
+                dfs.setGroupingSeparator('\u00a0');
+                df.setDecimalFormatSymbols(dfs);
+            }
+            try
+            {
+                return parse(value, format, destType);
+            }
+            catch (ParseException pe)
             {
-                NumberFormat format = getNumberFormat(facesContext);
-                format.setParseIntegerOnly(_integerOnly);
-                
-                DecimalFormat df = (DecimalFormat)format;
-                
-                // The best we can do in this case is check if there is a ValueExpression
-                // with a BigDecimal as returning type , and if that so enable BigDecimal
parsing
-                // to prevent loss in precision, and do not break existing examples (since
-                // in those cases it is expected to return Double). See MYFACES-1890 and
TRINIDAD-1124
-                // for details
-                ValueExpression valueExpression = uiComponent.getValueExpression("value");
-                Class<?> destType = null;
-                if (valueExpression != null)
+                if(getPattern() != null)
                 {
-                    destType = valueExpression.getType(facesContext.getELContext());
-                    if (destType != null
-                        && (BigDecimal.class.isAssignableFrom(destType) || BigInteger.class.isAssignableFrom(destType)))
-                    {
-                        df.setParseBigDecimal(true);
-                    }
+                    throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
+                            PATTERN_ID,
+                            new Object[]{value, "$###,###", _MessageUtils.getLabel(facesContext,
uiComponent)}));
                 }
-                
-                DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
-                boolean changed = false;
-                if(dfs.getGroupingSeparator() == '\u00a0')
+                else if(getType().equals("number"))
                 {
-                  dfs.setGroupingSeparator(' ');
-                  df.setDecimalFormatSymbols(dfs);
-                  value = value.replace('\u00a0', ' ');
-                  changed = true;
+                    throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
+                            NUMBER_ID,
+                            new Object[]{value, format.format(21),
+                                         _MessageUtils.getLabel(facesContext, uiComponent)}));
                 }
-                
-                formatCurrency(format);
-                
-                try
+                else if(getType().equals("currency"))
                 {
-                    return parse(value, format, destType);
+                    throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
+                            CURRENCY_ID,
+                            new Object[]{value, format.format(42.25),
+                                         _MessageUtils.getLabel(facesContext, uiComponent)}));
                 }
-                catch (ParseException e)
+                else if(getType().equals("percent"))
                 {
-                  if(changed)
-                  {
-                    dfs.setGroupingSeparator('\u00a0');
-                    df.setDecimalFormatSymbols(dfs);
-                  }
-                  try
-                  {
-                      return parse(value, format, destType);
-                  }
-                  catch (ParseException pe)
-                  {
-
-                    if(getPattern() != null)
-                    {
-                        throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
-                                PATTERN_ID,
-                                new Object[]{value, "$###,###", _MessageUtils.getLabel(facesContext,
uiComponent)}));
-                    }
-                    else if(getType().equals("number"))
-                    {
-                        throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
-                                NUMBER_ID,
-                                new Object[]{value, format.format(21),
-                                             _MessageUtils.getLabel(facesContext, uiComponent)}));
-                    }
-                    else if(getType().equals("currency"))
-                    {
-                        throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
-                                CURRENCY_ID,
-                                new Object[]{value, format.format(42.25),
-                                             _MessageUtils.getLabel(facesContext, uiComponent)}));
-                    }
-                    else if(getType().equals("percent"))
-                    {
-                        throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
-                                PERCENT_ID,
-                                new Object[]{value, format.format(.90),
-                                             _MessageUtils.getLabel(facesContext, uiComponent)}));
-                    }
-                  }
+                    throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
+                            PERCENT_ID,
+                            new Object[]{value, format.format(.90),
+                                         _MessageUtils.getLabel(facesContext, uiComponent)}));
                 }
             }
         }
+        
         return null;
     }
 
@@ -208,22 +203,19 @@ public class NumberConverter
     @Override
     public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object
value)
     {
-        if (facesContext == null)
+        if (facesContext == null || uiComponent == null)
         {
-            throw new NullPointerException("facesContext");
-        }
-        if (uiComponent == null)
-        {
-            throw new NullPointerException("uiComponent");
+            throw new NullPointerException(); // should never happen
         }
 
         if (value == null)
         {
             return "";
         }
+
         if (value instanceof String)
         {
-            return (String)value;
+            return (String) value;
         }
 
         NumberFormat format = getNumberFormat(facesContext);
diff --git a/api/src/main/java/javax/faces/convert/ShortConverter.java b/api/src/main/java/javax/faces/convert/ShortConverter.java
index 1a99d46..b1ee397 100755
--- a/api/src/main/java/javax/faces/convert/ShortConverter.java
+++ b/api/src/main/java/javax/faces/convert/ShortConverter.java
@@ -27,75 +27,68 @@ import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFConvert
  * see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF
Specification</a>
  */
 @JSFConverter
-public class ShortConverter
-        implements Converter
+public class ShortConverter implements Converter
 {
-    // FIELDS
     public static final String CONVERTER_ID = "javax.faces.Short";
     public static final String STRING_ID = "javax.faces.converter.STRING";
     public static final String SHORT_ID = "javax.faces.converter.ShortConverter.SHORT";
 
-    // CONSTRUCTORS
     public ShortConverter()
     {
     }
 
-    // METHODS
     @Override
     public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String
value)
     {
-        if (facesContext == null)
+        if (facesContext == null || uiComponent == null)
         {
-            throw new NullPointerException("facesContext");
+            throw new NullPointerException(); // should never happen
         }
-        if (uiComponent == null)
+
+        if (value == null)
+        {
+            return null;
+        }
+        
+        value = value.trim();
+        if (value.length() < 1)
         {
-            throw new NullPointerException("uiComponent");
+            return null;
         }
 
-        if (value != null)
+        try
         {
-            value = value.trim();
-            if (value.length() > 0)
-            {
-                try
-                {
-                    return Short.valueOf(value);
-                }
-                catch (NumberFormatException e)
-                {
-                    throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
-                                   SHORT_ID,
-                                   new Object[]{value,"21",_MessageUtils.getLabel(facesContext,
uiComponent)}), e);
-                }
-            }
+            return Short.valueOf(value);
+        }
+        catch (NumberFormatException e)
+        {
+            throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
+                           SHORT_ID,
+                           new Object[]{value,"21",_MessageUtils.getLabel(facesContext, uiComponent)}),
e);
         }
-        return null;
     }
 
     @Override
     public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object
value)
     {
-        if (facesContext == null)
-        {
-            throw new NullPointerException("facesContext");
-        }
-        if (uiComponent == null)
+        if (facesContext == null || uiComponent == null)
         {
-            throw new NullPointerException("uiComponent");
+            throw new NullPointerException(); // should never happen
         }
 
         if (value == null)
         {
             return "";
         }
+
         if (value instanceof String)
         {
-            return (String)value;
+            return (String) value;
         }
+
         try
         {
-            return Short.toString(((Number)value).shortValue());
+            return Short.toString(((Number) value).shortValue());
         }
         catch (Exception e)
         {


Mime
View raw message