diff options
author | Dominik Stadler <centic@apache.org> | 2016-06-02 20:14:28 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2016-06-02 20:14:28 +0000 |
commit | bb7c632559ec5b187402d17cc0d65e16572c5d15 (patch) | |
tree | dafcf2d8f4c9ae219dc9401c0e4e0ee93b3d91b2 /src/excelant | |
parent | 8811c99ac3a9d6b843c99fc6cee00533067f1402 (diff) | |
download | poi-bb7c632559ec5b187402d17cc0d65e16572c5d15.tar.gz poi-bb7c632559ec5b187402d17cc0d65e16572c5d15.zip |
Fix some Sonar issues and some IntelliJ warnings
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1746627 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/excelant')
8 files changed, 63 insertions, 79 deletions
diff --git a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntEvaluateCell.java b/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntEvaluateCell.java index d35cc6a7d8..55e51975fe 100644 --- a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntEvaluateCell.java +++ b/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntEvaluateCell.java @@ -125,13 +125,13 @@ public class ExcelAntEvaluateCell extends Task { } result = wbUtil.evaluateCell(cell, expectedValue, precisionToUse ) ; - StringBuffer sb = new StringBuffer() ; + StringBuilder sb = new StringBuilder() ; sb.append( "evaluation of cell " ) ; sb.append( cell ) ; sb.append( " resulted in " ) ; sb.append( result.getReturnValue() ) ; - if( showDelta == true ) { - sb.append( " with a delta of " + result.getDelta() ) ; + if(showDelta) { + sb.append(" with a delta of ").append(result.getDelta()); } log( sb.toString(), Project.MSG_DEBUG) ; @@ -141,6 +141,4 @@ public class ExcelAntEvaluateCell extends Task { public ExcelAntEvaluationResult getResult() { return result ; } - - } diff --git a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntSetDoubleCell.java b/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntSetDoubleCell.java index a1113509a2..3e6c4cd607 100644 --- a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntSetDoubleCell.java +++ b/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntSetDoubleCell.java @@ -29,15 +29,13 @@ import org.apache.tools.ant.Project; * */ public class ExcelAntSetDoubleCell extends ExcelAntSet { - - - private double cellValue ; + private double cellValue; public ExcelAntSetDoubleCell() {} /** * Set the value of the specified cell as the double passed in. - * @param value + * @param value The double-value that should be set when this task is executed. */ public void setValue( double value ) { cellValue = value ; @@ -45,14 +43,14 @@ public class ExcelAntSetDoubleCell extends ExcelAntSet { /** * Return the cell value as a double. - * @return + * @return The double-value of the cell as populated via setValue(), null + * if the value was not set yet. */ public double getCellValue() { return cellValue; } public void execute() throws BuildException { - wbUtil.setDoubleValue(cellStr, cellValue ) ; log( "set cell " + cellStr + " to value " + cellValue + " as double.", Project.MSG_DEBUG ) ; diff --git a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntSetStringCell.java b/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntSetStringCell.java index 12221ee170..047e544ea5 100644 --- a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntSetStringCell.java +++ b/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntSetStringCell.java @@ -29,17 +29,13 @@ import org.apache.tools.ant.Project; * */ public class ExcelAntSetStringCell extends ExcelAntSet { - - private String stringValue ; - - + public ExcelAntSetStringCell() {} - /** * Set the value of the cell to the String passed in. - * @param value + * @param value The string-value that should be set when this task is executed. */ public void setValue(String value ) { stringValue = value ; @@ -47,14 +43,14 @@ public class ExcelAntSetStringCell extends ExcelAntSet { /** * Return the value that will be set into the cell. - * @return + * @return The string-value of the cell as populated via setValue(), null + * if the value was not set yet. */ public String getCellValue() { return stringValue; } public void execute() throws BuildException { - wbUtil.setStringValue(cellStr, stringValue ) ; log( "set cell " + cellStr + " to value " + stringValue + " as String.", Project.MSG_DEBUG ) ; diff --git a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntTask.java b/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntTask.java index ad0cf6b845..13271611b1 100644 --- a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntTask.java +++ b/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntTask.java @@ -17,14 +17,6 @@ package org.apache.poi.ss.excelant; -import java.io.File; -import java.io.FileInputStream; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Locale; - import org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtil; import org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtilFactory; import org.apache.poi.ss.usermodel.Workbook; @@ -33,6 +25,13 @@ import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; +import java.io.File; +import java.io.FileInputStream; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.LinkedList; +import java.util.Locale; + /** * Ant task class for testing Excel workbook cells. * @@ -85,7 +84,7 @@ public class ExcelAntTask extends Task { int totalCount = 0 ; int successCount = 0 ; - StringBuffer versionBffr = new StringBuffer() ; + StringBuilder versionBffr = new StringBuilder() ; versionBffr.append( "ExcelAnt version " ) ; versionBffr.append( VERSION ) ; versionBffr.append( " Copyright 2011" ) ; @@ -107,43 +106,38 @@ public class ExcelAntTask extends Task { return ; } if( tests.size() > 0 ) { - - Iterator<ExcelAntTest> testsIt = tests.iterator() ; - while( testsIt.hasNext() ) { - ExcelAntTest test = testsIt.next(); - - log( "executing test: " + test.getName(), Project.MSG_DEBUG ) ; - - workbookUtil = ExcelAntWorkbookUtilFactory.getInstance( excelFileName ) ; - - Iterator<ExcelAntUserDefinedFunction> functionsIt = functions.iterator() ; - while( functionsIt.hasNext() ) { - ExcelAntUserDefinedFunction eaUdf = functionsIt.next() ; + + for (ExcelAntTest test : tests) { + log("executing test: " + test.getName(), Project.MSG_DEBUG); + + workbookUtil = ExcelAntWorkbookUtilFactory.getInstance(excelFileName); + + for (ExcelAntUserDefinedFunction eaUdf : functions) { try { - workbookUtil.addFunction(eaUdf.getFunctionAlias(), eaUdf.getClassName() ) ; - } catch ( Exception e) { - throw new BuildException( e.getMessage(), e ); + workbookUtil.addFunction(eaUdf.getFunctionAlias(), eaUdf.getClassName()); + } catch (Exception e) { + throw new BuildException(e.getMessage(), e); } } - test.setWorkbookUtil( workbookUtil ) ; - - if( precision != null && precision.getValue() > 0 ) { - log( "setting precision for the test " + test.getName(), Project.MSG_VERBOSE ) ; - test.setPrecision( precision.getValue() ) ; + test.setWorkbookUtil(workbookUtil); + + if (precision != null && precision.getValue() > 0) { + log("setting precision for the test " + test.getName(), Project.MSG_VERBOSE); + test.setPrecision(precision.getValue()); } - - test.execute() ; - - if( test.didTestPass() ) { - successCount++ ; + + test.execute(); + + if (test.didTestPass()) { + successCount++; } else { - if( failOnError == true ) { - throw new BuildException( "Test " + test.getName() + " failed." ) ; + if (failOnError) { + throw new BuildException("Test " + test.getName() + " failed."); } } - totalCount++ ; - - workbookUtil = null ; + totalCount++; + + workbookUtil = null; } log( successCount + "/" + totalCount + " tests passed.", Project.MSG_INFO ) ; workbookUtil = null ; diff --git a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntTest.java b/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntTest.java index 719b05699c..36b9b6d9e0 100644 --- a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntTest.java +++ b/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntTest.java @@ -162,9 +162,9 @@ public class ExcelAntTest extends Task{ try { eval.execute(); ExcelAntEvaluationResult result = eval.getResult(); - if( result.didTestPass() && - result.evaluationCompleteWithError() == false ) { - if( showSuccessDetails == true ) { + if( result.didTestPass() && + !result.evaluationCompleteWithError()) { + if(showSuccessDetails) { log("Succeeded when evaluating " + result.getCellName() + ". It evaluated to " + result.getReturnValue() + " when the value of " + @@ -172,7 +172,7 @@ public class ExcelAntTest extends Task{ eval.getPrecision(), Project.MSG_INFO ); } } else { - if( showFailureDetail == true ) { + if(showFailureDetail) { failureMessages.add( "\tFailed to evaluate cell " + result.getCellName() + ". It evaluated to " + result.getReturnValue() + " when the value of " + @@ -183,7 +183,7 @@ public class ExcelAntTest extends Task{ passed = false; failureCount++; - if( eval.requiredToPass() == true ) { + if(eval.requiredToPass()) { throw new BuildException( "\tFailed to evaluate cell " + result.getCellName() + ". It evaluated to " + result.getReturnValue() + " when the value of " + @@ -200,15 +200,14 @@ public class ExcelAntTest extends Task{ } } - if( passed == false ) { + if(!passed) { log( "Test named " + name + " failed because " + failureCount + " of " + testCount + " evaluations failed to " + "evaluate correctly.", Project.MSG_ERR ); - if( showFailureDetail == true && failureMessages.size() > 0 ) { - Iterator<String> failures = failureMessages.iterator(); - while( failures.hasNext() ) { - log( failures.next(), Project.MSG_ERR ); + if(showFailureDetail && failureMessages.size() > 0 ) { + for (String failureMessage : failureMessages) { + log(failureMessage, Project.MSG_ERR); } } } diff --git a/src/excelant/java/org/apache/poi/ss/excelant/IExcelAntWorkbookHandler.java b/src/excelant/java/org/apache/poi/ss/excelant/IExcelAntWorkbookHandler.java index 3cd477abc8..139e34c0d7 100644 --- a/src/excelant/java/org/apache/poi/ss/excelant/IExcelAntWorkbookHandler.java +++ b/src/excelant/java/org/apache/poi/ss/excelant/IExcelAntWorkbookHandler.java @@ -36,11 +36,7 @@ import org.apache.poi.ss.usermodel.Workbook; *
*/
public interface IExcelAntWorkbookHandler {
-
-
public void setWorkbook( Workbook workbook ) ;
public void execute() ;
-
-
}
diff --git a/src/excelant/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtil.java b/src/excelant/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtil.java index 7d2fbe4fc3..627493b291 100644 --- a/src/excelant/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtil.java +++ b/src/excelant/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtil.java @@ -67,7 +67,8 @@ public class ExcelAntWorkbookUtil extends Typedef { * path of the Excel file. This constructor initializes a Workbook instance * based on that file name. * - * @param fName + * @param fName The fully qualified path of the Excel file. + * @throws BuildException If the workbook cannot be loaded. */ protected ExcelAntWorkbookUtil(String fName) { excelFileName = fName; @@ -78,7 +79,7 @@ public class ExcelAntWorkbookUtil extends Typedef { /** * Constructs an instance based on a Workbook instance. * - * @param wb + * @param wb The Workbook to use for this instance. */ protected ExcelAntWorkbookUtil(Workbook wb) { workbook = wb; @@ -86,7 +87,8 @@ public class ExcelAntWorkbookUtil extends Typedef { /** * Loads the member variable workbook based on the fileName variable. - * @return + * @return The opened Workbook-instance + * @throws BuildException If the workbook cannot be loaded. */ private Workbook loadWorkbook() { diff --git a/src/excelant/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtilFactory.java b/src/excelant/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtilFactory.java index e9d385146a..08e7fb3d98 100644 --- a/src/excelant/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtilFactory.java +++ b/src/excelant/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtilFactory.java @@ -40,15 +40,16 @@ public final class ExcelAntWorkbookUtilFactory { * Using the fileName, check the internal map to see if an instance
* of the WorkbookUtil exists. If not, then add an instance to the map.
*
- * @param fileName
- * @return
+ * @param fileName The filename to use as key to look for the ExcelAntWorkbookUtil.
+ * @return An instance of ExcelAntWorkbookUtil associated with the filename or
+ * a freshly instantiated one if none did exist before.
*/
public static ExcelAntWorkbookUtil getInstance(String fileName) {
if(workbookUtilMap == null) {
workbookUtilMap = new HashMap<String, ExcelAntWorkbookUtil>();
}
- if(workbookUtilMap != null &&
- workbookUtilMap.containsKey(fileName)) {
+
+ if(workbookUtilMap.containsKey(fileName)) {
return workbookUtilMap.get(fileName);
}
|