Author: doogie
Date: Wed Oct 17 10:45:11 2007 New Revision: 585597 URL: http://svn.apache.org/viewvc?rev=585597&view=rev Log: Use ?: trinary for looking up NumberFormats. Closes https://issues.apache.org/jira/browse/OFBIZ-1340 Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/ObjectType.java Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/ObjectType.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/ObjectType.java?rev=585597&r1=585596&r2=585597&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/ObjectType.java (original) +++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/ObjectType.java Wed Oct 17 10:45:11 2007 @@ -496,12 +496,7 @@ } else if ("BigDecimal".equals(type) || "java.math.BigDecimal".equals(type)) { str = StringUtil.removeSpaces(str); try { - NumberFormat nf = null; - if (locale == null) { - nf = NumberFormat.getNumberInstance(); - } else { - nf = NumberFormat.getNumberInstance(locale); - } + NumberFormat nf = locale == null ? NumberFormat.getNumberInstance() : NumberFormat.getNumberInstance(locale); Number tempNum = nf.parse(str); return new BigDecimal(tempNum.toString()); } catch (ParseException e) { @@ -510,12 +505,7 @@ } else if ("Double".equals(type) || "java.lang.Double".equals(type)) { str = StringUtil.removeSpaces(str); try { - NumberFormat nf = null; - if (locale == null) { - nf = NumberFormat.getNumberInstance(); - } else { - nf = NumberFormat.getNumberInstance(locale); - } + NumberFormat nf = locale == null ? NumberFormat.getNumberInstance() : NumberFormat.getNumberInstance(locale); Number tempNum = nf.parse(str); return Double.valueOf(tempNum.doubleValue()); @@ -525,12 +515,7 @@ } else if ("Float".equals(type) || "java.lang.Float".equals(type)) { str = StringUtil.removeSpaces(str); try { - NumberFormat nf = null; - if (locale == null) { - nf = NumberFormat.getNumberInstance(); - } else { - nf = NumberFormat.getNumberInstance(locale); - } + NumberFormat nf = locale == null ? NumberFormat.getNumberInstance() : NumberFormat.getNumberInstance(locale); Number tempNum = nf.parse(str); return Float.valueOf(tempNum.floatValue()); @@ -540,12 +525,7 @@ } else if ("Long".equals(type) || "java.lang.Long".equals(type)) { str = StringUtil.removeSpaces(str); try { - NumberFormat nf = null; - if (locale == null) { - nf = NumberFormat.getNumberInstance(); - } else { - nf = NumberFormat.getNumberInstance(locale); - } + NumberFormat nf = locale == null ? NumberFormat.getNumberInstance() : NumberFormat.getNumberInstance(locale); nf.setMaximumFractionDigits(0); Number tempNum = nf.parse(str); @@ -556,12 +536,7 @@ } else if ("Integer".equals(type) || "java.lang.Integer".equals(type)) { str = StringUtil.removeSpaces(str); try { - NumberFormat nf = null; - if (locale == null) { - nf = NumberFormat.getNumberInstance(); - } else { - nf = NumberFormat.getNumberInstance(locale); - } + NumberFormat nf = locale == null ? NumberFormat.getNumberInstance() : NumberFormat.getNumberInstance(locale); nf.setMaximumFractionDigits(0); Number tempNum = nf.parse(str); @@ -639,13 +614,7 @@ Double dbl = (Double) obj; if ("String".equals(type) || "java.lang.String".equals(type)) { - NumberFormat nf = null; - - if (locale == null) { - nf = NumberFormat.getNumberInstance(); - } else { - nf = NumberFormat.getNumberInstance(locale); - } + NumberFormat nf = locale == null ? NumberFormat.getNumberInstance() : NumberFormat.getNumberInstance(locale); return nf.format(dbl.doubleValue()); } else if ("BigDecimal".equals(type) || "java.math.BigDecimal".equals(type)) { return new BigDecimal(dbl.doubleValue()); @@ -673,12 +642,7 @@ Float flt = (Float) obj; if ("String".equals(type)) { - NumberFormat nf = null; - - if (locale == null) - nf = NumberFormat.getNumberInstance(); - else - nf = NumberFormat.getNumberInstance(locale); + NumberFormat nf = locale == null ? NumberFormat.getNumberInstance() : NumberFormat.getNumberInstance(locale); return nf.format(flt.doubleValue()); } else if ("BigDecimal".equals(type) || "java.math.BigDecimal".equals(type)) { return new BigDecimal(flt.doubleValue()); @@ -706,12 +670,7 @@ Long lng = (Long) obj; if ("String".equals(type) || "java.lang.String".equals(type)) { - NumberFormat nf = null; - if (locale == null) { - nf = NumberFormat.getNumberInstance(); - } else { - nf = NumberFormat.getNumberInstance(locale); - } + NumberFormat nf = locale == null ? NumberFormat.getNumberInstance() : NumberFormat.getNumberInstance(locale); return nf.format(lng.longValue()); } else if ("BigDecimal".equals(type) || "java.math.BigDecimal".equals(type)) { return BigDecimal.valueOf(lng.longValue()); @@ -738,12 +697,7 @@ fromType = "Integer"; Integer intgr = (Integer) obj; if ("String".equals(type) || "java.lang.String".equals(type)) { - NumberFormat nf = null; - if (locale == null) { - nf = NumberFormat.getNumberInstance(); - } else { - nf = NumberFormat.getNumberInstance(locale); - } + NumberFormat nf = locale == null ? NumberFormat.getNumberInstance() : NumberFormat.getNumberInstance(locale); return nf.format(intgr.longValue()); } else if ("BigDecimal".equals(type) || "java.math.BigDecimal".equals(type)) { return BigDecimal.valueOf(intgr.longValue()); @@ -770,12 +724,7 @@ fromType = "BigDecimal"; BigDecimal bigDec = (BigDecimal) obj; if ("String".equals(type) || "java.lang.String".equals(type)) { - NumberFormat nf = null; - if (locale == null) { - nf = NumberFormat.getNumberInstance(); - } else { - nf = NumberFormat.getNumberInstance(locale); - } + NumberFormat nf = locale == null ? NumberFormat.getNumberInstance() : NumberFormat.getNumberInstance(locale); return nf.format(bigDec.doubleValue()); } else if ("BigDecimal".equals(type) || "java.math.BigDecimal".equals(type)) { return obj; |
Free forum by Nabble | Edit this page |