Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 7076 invoked from network); 27 Apr 2006 07:10:24 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 27 Apr 2006 07:10:22 -0000 Received: (qmail 53365 invoked by uid 500); 27 Apr 2006 07:09:41 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 53217 invoked by uid 500); 27 Apr 2006 07:09:40 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 53033 invoked by uid 500); 27 Apr 2006 07:09:40 -0000 Received: (qmail 52957 invoked by uid 99); 27 Apr 2006 07:09:39 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 27 Apr 2006 00:09:39 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 27 Apr 2006 00:09:38 -0700 Received: (qmail 6440 invoked by uid 65534); 27 Apr 2006 07:09:18 -0000 Message-ID: <20060427070918.6439.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r397454 - /jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/Coercion.java Date: Thu, 27 Apr 2006 07:09:17 -0000 To: commons-cvs@jakarta.apache.org From: rahul@apache.org X-Mailer: svnmailer-1.0.8 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: rahul Date: Thu Apr 27 00:09:13 2006 New Revision: 397454 URL: http://svn.apache.org/viewcvs?rev=397454&view=rev Log: Conform to checkstyle, add missing Javadocs. No functional change. Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/Coercion.java Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/Coercion.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/Coercion.java?rev=397454&r1=397453&r2=397454&view=diff ============================================================================== --- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/Coercion.java (original) +++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/Coercion.java Thu Apr 27 00:09:13 2006 @@ -21,97 +21,94 @@ * @since 1.0 * @author Geir Magnusson Jr. */ -public class Coercion -{ +public class Coercion { + /** + * Coerce to a Boolean. + * + * @param val Object to be coerced. + * @return The Boolean coerced value, or null if none possible. + */ public static Boolean coerceBoolean(Object val) { - if (val == null) - { + if (val == null) { return Boolean.FALSE; - } - else if (val instanceof Boolean) - { + } else if (val instanceof Boolean) { return (Boolean) val; - } - else if (val instanceof String) - { + } else if (val instanceof String) { return Boolean.valueOf((String) val); } - return null; } + /** + * Coerce to a Integer. + * + * @param val Object to be coerced. + * @return The Integer coerced value. + * @throws Exception If Integer coercion fails. + */ public static Integer coerceInteger(Object val) - throws Exception - { - if (val == null) - { + throws Exception { + if (val == null) { return new Integer(0); - } - else if (val instanceof String) - { - if("".equals(val)) + } else if (val instanceof String) { + if ("".equals(val)) { return new Integer(0); - - return Integer.valueOf((String)val); - } - else if(val instanceof Character) - { - return new Integer(((Character)val).charValue()); - } - else if(val instanceof Boolean) - { + } + return Integer.valueOf((String) val); + } else if (val instanceof Character) { + return new Integer(((Character) val).charValue()); + } else if (val instanceof Boolean) { throw new Exception("Boolean->Integer coercion exception"); - } - else if(val instanceof Number) - { - return new Integer(((Number)val).intValue()); + } else if (val instanceof Number) { + return new Integer(((Number) val).intValue()); } throw new Exception("Integer coercion exception"); } + /** + * Coerce to a Long. + * + * @param val Object to be coerced. + * @return The Long coerced value. + * @throws Exception If Long coercion fails. + */ public static Long coerceLong(Object val) - throws Exception - { - if (val == null) - { + throws Exception { + if (val == null) { return new Long(0); - } - else if (val instanceof String) - { - if("".equals(val)) + } else if (val instanceof String) { + if ("".equals(val)) { return new Long(0); - - return Long.valueOf((String)val); - } - else if(val instanceof Character) - { - return new Long(((Character)val).charValue()); - } - else if(val instanceof Boolean) - { + } + return Long.valueOf((String) val); + } else if (val instanceof Character) { + return new Long(((Character) val).charValue()); + } else if (val instanceof Boolean) { throw new Exception("Boolean->Integer coercion exception"); - } - else if(val instanceof Number) - { - return new Long(((Number)val).longValue()); + } else if (val instanceof Number) { + return new Long(((Number) val).longValue()); } throw new Exception("Long coercion exception"); } + /** + * Coerce to a Double. + * + * @param val Object to be coerced. + * @return The Double coerced value. + * @throws Exception If Double coercion fails. + */ public static Double coerceDouble(Object val) - throws Exception - { - if (val == null) - { + throws Exception { + if (val == null) { return new Double(0); - } - else if (val instanceof String) - { - if("".equals(val)) + } else if (val instanceof String) { + if ("".equals(val)) { return new Double(0); + } /* * the spec seems to be iffy about this. Going to give it a wack @@ -119,23 +116,15 @@ */ return new Double((String) val); - } - else if(val instanceof Character) - { - int i = ((Character)val).charValue(); + } else if (val instanceof Character) { + int i = ((Character) val).charValue(); return new Double(Double.parseDouble(String.valueOf(i))); - } - else if(val instanceof Boolean) - { + } else if (val instanceof Boolean) { throw new Exception("Boolean->Integer coercion exception"); - } - else if(val instanceof Double) - { + } else if (val instanceof Double) { return (Double) val; - } - else if (val instanceof Number) - { + } else if (val instanceof Number) { //The below construct is used rather than ((Number)val).doubleValue() to ensure //equality between comparint new Double( 6.4 / 3 ) and the jexl expression of 6.4 / 3 return new Double(Double.parseDouble(String.valueOf(val))); @@ -144,13 +133,23 @@ throw new Exception("Double coercion exception"); } - public static boolean isFloatingPoint( final Object o ) - { + /** + * Is Object a floating point number. + * + * @param o Object to be analyzed. + * @return true if it is a Float or a Double. + */ + public static boolean isFloatingPoint(final Object o) { return o instanceof Float || o instanceof Double; } - public static boolean isNumberable( final Object o ) - { + /** + * Is Object a whole number. + * + * @param o Object to be analyzed. + * @return true if Integer, Long, Byte, Short or Character. + */ + public static boolean isNumberable(final Object o) { return o instanceof Integer || o instanceof Long || o instanceof Byte --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org