summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpshi2012-08-09 02:48:21 (EDT)
committer mwu2012-08-09 02:48:21 (EDT)
commit6dc0339fff8d63efdae67f8f19bbbdf46816d29f (patch)
treef4115701db1a67ae5451539b04cdb6c22b92f059
parent66f53876adc9fdebd7903beaf697711e08406dda (diff)
downloadorg.eclipse.birt-6dc0339fff8d63efdae67f8f19bbbdf46816d29f.zip
org.eclipse.birt-6dc0339fff8d63efdae67f8f19bbbdf46816d29f.tar.gz
org.eclipse.birt-6dc0339fff8d63efdae67f8f19bbbdf46816d29f.tar.bz2
Refactor the code by the findbugs tool
-rw-r--r--data/org.eclipse.birt.core.script.function/src/org/eclipse/birt/core/script/function/bre/BirtDateTime.java46
-rw-r--r--data/org.eclipse.birt.core.script.function/src/org/eclipse/birt/core/script/function/general/Finance.java2
-rw-r--r--data/org.eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/impl/Finance.java2
-rw-r--r--data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/ExcelFileReader.java4
4 files changed, 25 insertions, 29 deletions
diff --git a/data/org.eclipse.birt.core.script.function/src/org/eclipse/birt/core/script/function/bre/BirtDateTime.java b/data/org.eclipse.birt.core.script.function/src/org/eclipse/birt/core/script/function/bre/BirtDateTime.java
index 16a1478..c7e5fa9 100644
--- a/data/org.eclipse.birt.core.script.function/src/org/eclipse/birt/core/script/function/bre/BirtDateTime.java
+++ b/data/org.eclipse.birt.core.script.function/src/org/eclipse/birt/core/script/function/bre/BirtDateTime.java
@@ -12,7 +12,9 @@
package org.eclipse.birt.core.script.function.bre;
import java.sql.Timestamp;
+import java.util.ArrayList;
import java.util.Date;
+import java.util.List;
import org.eclipse.birt.core.data.DataTypeUtil;
import org.eclipse.birt.core.exception.BirtException;
@@ -36,26 +38,24 @@ public class BirtDateTime implements IScriptFunctionExecutor
*
*/
private static final long serialVersionUID = 1L;
- static private SimpleDateFormat abbrMonthFormat = null;
- static private SimpleDateFormat monthFormat = null;
- static private SimpleDateFormat abbrWeekFormat = null;
- static private SimpleDateFormat weekFormat = null;
+
+ static private ThreadLocal<List<SimpleDateFormat>> threadSDFArray = new ThreadLocal<List<SimpleDateFormat>>();
+ private static ThreadLocal<ULocale> threadLocale = new ThreadLocal<ULocale>();
private IScriptFunctionExecutor executor;
- private static IScriptFunctionContext scriptContext;
+ private IScriptFunctionContext scriptContext;
private static ULocale defaultLocale = null;
private static TimeZone timeZone = null;
+
/**
*
* @return
*/
private static SimpleDateFormat getAbbrMonthFormat( )
{
- if ( abbrMonthFormat == null )
- abbrMonthFormat = new SimpleDateFormat( "MMM", defaultLocale );
- return abbrMonthFormat;
+ return threadSDFArray.get( ).get( 0 );
}
/**
@@ -64,9 +64,7 @@ public class BirtDateTime implements IScriptFunctionExecutor
*/
private static SimpleDateFormat getMonthFormat( )
{
- if ( monthFormat == null )
- monthFormat = new SimpleDateFormat( "MMMM", defaultLocale );
- return monthFormat;
+ return threadSDFArray.get( ).get( 1 );
}
/**
@@ -75,9 +73,7 @@ public class BirtDateTime implements IScriptFunctionExecutor
*/
private static SimpleDateFormat getAbbrWeekFormat( )
{
- if ( abbrWeekFormat == null )
- abbrWeekFormat = new SimpleDateFormat( "EEE", defaultLocale );
- return abbrWeekFormat;
+ return threadSDFArray.get( ).get( 2 );
}
/**
@@ -86,9 +82,7 @@ public class BirtDateTime implements IScriptFunctionExecutor
*/
private static SimpleDateFormat getWeekFormat( )
{
- if ( weekFormat == null )
- weekFormat = new SimpleDateFormat( "EEEE", defaultLocale );
- return weekFormat;
+ return threadSDFArray.get( ).get( 3 );
}
/**
@@ -958,9 +952,9 @@ public class BirtDateTime implements IScriptFunctionExecutor
{
java.util.TimeZone jTimeZone = java.util.TimeZone.getTimeZone( timeZone.getID( ) );
jTimeZone.setRawOffset( timeZone.getRawOffset( ) );
- if( timeZone != null && jTimeZone.inDaylightTime( d1 ) )
+ if( jTimeZone.inDaylightTime( d1 ) )
diff -= jTimeZone.getDSTSavings( );
- if( timeZone != null && jTimeZone.inDaylightTime( d2 ) )
+ if( jTimeZone.inDaylightTime( d2 ) )
diff += jTimeZone.getDSTSavings( );
}
}
@@ -1517,13 +1511,15 @@ public class BirtDateTime implements IScriptFunctionExecutor
if ( scriptContext != null )
{
ULocale locale = (ULocale) scriptContext.findProperty( org.eclipse.birt.core.script.functionservice.IScriptFunctionContext.LOCALE );
- if ( defaultLocale != locale )
+ if ( threadLocale.get( ) != locale )
{
- abbrMonthFormat = null;
- monthFormat = null;
- abbrWeekFormat = null;
- weekFormat = null;
- defaultLocale = locale;
+ threadLocale.set( locale );
+ List<SimpleDateFormat> sdfList = new ArrayList<SimpleDateFormat>();
+ sdfList.add( new SimpleDateFormat( "MMM", threadLocale.get( ) ) );
+ sdfList.add( new SimpleDateFormat( "MMMM", threadLocale.get( ) ) );
+ sdfList.add( new SimpleDateFormat( "EEE", threadLocale.get( ) ) );
+ sdfList.add( new SimpleDateFormat( "EEEE", threadLocale.get( ) ) );
+ threadSDFArray.set( sdfList );
}
timeZone = (TimeZone) scriptContext.findProperty( org.eclipse.birt.core.script.functionservice.IScriptFunctionContext.TIMEZONE );
diff --git a/data/org.eclipse.birt.core.script.function/src/org/eclipse/birt/core/script/function/general/Finance.java b/data/org.eclipse.birt.core.script.function/src/org/eclipse/birt/core/script/function/general/Finance.java
index 8b2c36d..f05448e 100644
--- a/data/org.eclipse.birt.core.script.function/src/org/eclipse/birt/core/script/function/general/Finance.java
+++ b/data/org.eclipse.birt.core.script.function/src/org/eclipse/birt/core/script/function/general/Finance.java
@@ -97,7 +97,7 @@ public class Finance
double depr = 0; /* The depreciation we calculate for current cycle */
if ( life <= 0 || salvage < 0 || cost <= 0 || period <= 0
- || life == Double.NaN || salvage == Double.NaN
+ || Double.isNaN( life ) || Double.isNaN( salvage )
|| Double.isNaN( cost ) || Double.isNaN( period ) )
{
throw ( new IllegalArgumentException(
diff --git a/data/org.eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/impl/Finance.java b/data/org.eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/impl/Finance.java
index fd656cd..c590992 100644
--- a/data/org.eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/impl/Finance.java
+++ b/data/org.eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/impl/Finance.java
@@ -76,7 +76,7 @@ public class Finance
if ( life <= 0
|| salvage < 0 || cost <= 0 || period <= 0
- || life == Double.NaN || salvage == Double.NaN
+ || Double.isNaN( life ) || Double.isNaN( salvage )
|| Double.isNaN( cost ) || Double.isNaN( period ) )
{
throw DataException.wrap( new AggrException( ResourceConstants.ILLEGAL_PARAMETER_FUN,
diff --git a/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/ExcelFileReader.java b/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/ExcelFileReader.java
index fe731ea..cb1585e 100644
--- a/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/ExcelFileReader.java
+++ b/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/ExcelFileReader.java
@@ -87,7 +87,7 @@ public class ExcelFileReader {
for (short colIx = 0; colIx < maxColumnIndex; colIx++) {
Cell cell = row.getCell(colIx);
String cellVal = getCellValue(cell);
- if( cell != null && cellVal != null && cellVal != ExcelODAConstants.EMPTY_STRING){
+ if( cell != null && cellVal != null &&!ExcelODAConstants.EMPTY_STRING.equals( cellVal ) ){
return false;
}
}
@@ -115,7 +115,7 @@ public class ExcelFileReader {
for (short colIx = 0; colIx < maxColumnIndex; colIx++) {
Cell cell = row.getCell(colIx);
String cellVal = getCellValue(cell);
- if( cell != null && cellVal != null && cellVal != ExcelODAConstants.EMPTY_STRING){
+ if( cell != null && cellVal != null && !cellVal.equals( ExcelODAConstants.EMPTY_STRING ) ){
blankRow = false;
}
rowData.add(cellVal);