diff --git a/src/examples/src/org/apache/poi/ss/examples/formula/SettingExternalFunction.java b/src/examples/src/org/apache/poi/ss/examples/formula/SettingExternalFunction.java index df79f5a35..ae7079436 100644 --- a/src/examples/src/org/apache/poi/ss/examples/formula/SettingExternalFunction.java +++ b/src/examples/src/org/apache/poi/ss/examples/formula/SettingExternalFunction.java @@ -48,7 +48,7 @@ public class SettingExternalFunction { /** * wrap external functions in a plugin */ - public static class BloombergAddIn extends UDFFinder { + public static class BloombergAddIn implements UDFFinder { private final Map _functionsByName; public BloombergAddIn() { @@ -89,7 +89,6 @@ public class SettingExternalFunction { wb.write(out); out.close(); - wb.close(); } } diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java index 744e8d5a8..cfae1e92c 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java @@ -31,6 +31,7 @@ import java.io.PrintWriter; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; @@ -38,7 +39,6 @@ import java.util.List; import java.util.Map; import java.util.NoSuchElementException; import java.util.regex.Pattern; -import java.util.Collections; import org.apache.commons.codec.digest.DigestUtils; import org.apache.poi.EncryptedDocumentException; @@ -181,7 +181,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss * The locator of user-defined functions. * By default includes functions from the Excel Analysis Toolpack */ - private UDFFinder _udfFinder = new IndexedUDFFinder(UDFFinder.getDefault()); + private UDFFinder _udfFinder = new IndexedUDFFinder(AggregatingUDFFinder.DEFAULT); public static HSSFWorkbook create(InternalWorkbook book) { return new HSSFWorkbook(book); diff --git a/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java b/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java index 106709cea..a0da336d7 100644 --- a/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java +++ b/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java @@ -44,7 +44,7 @@ import org.apache.poi.ss.formula.udf.UDFFinder; /** * Analysis Toolpack Function Definitions */ -public final class AnalysisToolPak extends UDFFinder { +public final class AnalysisToolPak implements UDFFinder { public static final UDFFinder instance = new AnalysisToolPak(); diff --git a/src/java/org/apache/poi/ss/formula/udf/AggregatingUDFFinder.java b/src/java/org/apache/poi/ss/formula/udf/AggregatingUDFFinder.java index 7d19de33c..ece80345c 100644 --- a/src/java/org/apache/poi/ss/formula/udf/AggregatingUDFFinder.java +++ b/src/java/org/apache/poi/ss/formula/udf/AggregatingUDFFinder.java @@ -17,6 +17,7 @@ package org.apache.poi.ss.formula.udf; +import org.apache.poi.ss.formula.atp.AnalysisToolPak; import org.apache.poi.ss.formula.functions.FreeRefFunction; import java.util.ArrayList; @@ -25,8 +26,15 @@ import java.util.Collection; /** * Collects add-in libraries and VB macro functions together into one UDF finder + * + * @author PUdalau */ -public class AggregatingUDFFinder extends UDFFinder { +public class AggregatingUDFFinder implements UDFFinder { + + /** + * Default UDFFinder implementation + */ + public static final UDFFinder DEFAULT = new AggregatingUDFFinder(AnalysisToolPak.instance); private final Collection _usedToolPacks; diff --git a/src/java/org/apache/poi/ss/formula/udf/DefaultUDFFinder.java b/src/java/org/apache/poi/ss/formula/udf/DefaultUDFFinder.java index 71e709b84..382820b1e 100644 --- a/src/java/org/apache/poi/ss/formula/udf/DefaultUDFFinder.java +++ b/src/java/org/apache/poi/ss/formula/udf/DefaultUDFFinder.java @@ -25,8 +25,10 @@ import org.apache.poi.ss.formula.functions.FreeRefFunction; /** * Default UDF finder - for adding your own user defined functions. + * + * @author PUdalau */ -public final class DefaultUDFFinder extends UDFFinder { +public final class DefaultUDFFinder implements UDFFinder { private final Map _functionsByName; public DefaultUDFFinder(String[] functionNames, FreeRefFunction[] functionImpls) { diff --git a/src/java/org/apache/poi/ss/formula/udf/UDFFinder.java b/src/java/org/apache/poi/ss/formula/udf/UDFFinder.java index 4086f7334..a434756e9 100644 --- a/src/java/org/apache/poi/ss/formula/udf/UDFFinder.java +++ b/src/java/org/apache/poi/ss/formula/udf/UDFFinder.java @@ -21,12 +21,18 @@ import org.apache.poi.ss.formula.atp.AnalysisToolPak; import org.apache.poi.ss.formula.functions.FreeRefFunction; /** - * Common abstract class for "Add-in" libraries and user defined function libraries. + * Common interface for "Add-in" libraries and user defined function libraries. */ -public abstract class UDFFinder { - public static UDFFinder getDefault() { - return new AggregatingUDFFinder(AnalysisToolPak.instance); - } +public interface UDFFinder { + // FIXME: Findbugs error: IC_SUPERCLASS_USES_SUBCLASS_DURING_INITIALIZATION + /** + * Default UDFFinder implementation + * + * @deprecated use AggregatingUDFFinder.DEFAULT instead, deprecated in POI 3.15, + * scheduled for removable in POI 3.17 + */ + @Deprecated + public static final UDFFinder DEFAULT = new AggregatingUDFFinder(AnalysisToolPak.instance); /** * Returns executor by specified name. Returns null if the function name is unknown. @@ -34,5 +40,5 @@ public abstract class UDFFinder { * @param name Name of function. * @return Function executor. */ - public abstract FreeRefFunction findFunction(String name); + FreeRefFunction findFunction(String name); } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java index 74a861b41..e278c16b0 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java @@ -33,7 +33,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.NoSuchElementException; import java.util.regex.Pattern; @@ -57,6 +56,7 @@ import org.apache.poi.openxml4j.opc.TargetMode; import org.apache.poi.poifs.crypt.HashAlgorithm; import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.formula.SheetNameFormatter; +import org.apache.poi.ss.formula.udf.AggregatingUDFFinder; import org.apache.poi.ss.formula.udf.IndexedUDFFinder; import org.apache.poi.ss.formula.udf.UDFFinder; import org.apache.poi.ss.usermodel.Row; @@ -160,7 +160,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook { * The locator of user-defined functions. * By default includes functions from the Excel Analysis Toolpack */ - private IndexedUDFFinder _udfFinder = new IndexedUDFFinder(UDFFinder.getDefault()); + private IndexedUDFFinder _udfFinder = new IndexedUDFFinder(AggregatingUDFFinder.DEFAULT); /** * TODO diff --git a/src/testcases/org/apache/poi/hssf/model/TestWorkbook.java b/src/testcases/org/apache/poi/hssf/model/TestWorkbook.java index 726c4e86f..0d88e2111 100644 --- a/src/testcases/org/apache/poi/hssf/model/TestWorkbook.java +++ b/src/testcases/org/apache/poi/hssf/model/TestWorkbook.java @@ -106,7 +106,7 @@ public final class TestWorkbook { public void testAddNameX() throws IOException { HSSFWorkbook hwb = new HSSFWorkbook(); InternalWorkbook wb = TestHSSFWorkbook.getInternalWorkbook(hwb); - assertNotNull(wb.getNameXPtg("ISODD", UDFFinder.getDefault())); + assertNotNull(wb.getNameXPtg("ISODD", AggregatingUDFFinder.DEFAULT)); FreeRefFunction NotImplemented = new FreeRefFunction() { public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {