From 0de74b143e9795011a153d6a99dc4fbcf0a6b16c Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Sun, 17 Jul 2016 07:14:49 +0000 Subject: [PATCH] add @Override annotations to CreationHelper classes git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1753017 13f79535-47bb-0310-9956-ffa450edef68 --- .../hssf/usermodel/HSSFCreationHelper.java | 23 +++++++++++++------ .../poi/ss/usermodel/CreationHelper.java | 6 +++++ .../xssf/streaming/SXSSFCreationHelper.java | 19 ++++++++++++--- .../xssf/usermodel/XSSFCreationHelper.java | 13 ++++++++++- 4 files changed, 50 insertions(+), 11 deletions(-) diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFCreationHelper.java b/src/java/org/apache/poi/hssf/usermodel/HSSFCreationHelper.java index 89f496fcf4..337255fd3b 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFCreationHelper.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFCreationHelper.java @@ -19,30 +19,37 @@ package org.apache.poi.hssf.usermodel; import org.apache.poi.hssf.record.common.ExtendedColor; import org.apache.poi.ss.usermodel.CreationHelper; +import org.apache.poi.util.Internal; public class HSSFCreationHelper implements CreationHelper { - private HSSFWorkbook workbook; - private HSSFDataFormat dataFormat; + private final HSSFWorkbook workbook; - HSSFCreationHelper(HSSFWorkbook wb) { + /** + * Should only be called by {@link HSSFWorkbook#getCreationHelper()} + * + * @param wb the workbook to create objects for + */ + @Internal(since="3.15 beta 3") + /*package*/ HSSFCreationHelper(HSSFWorkbook wb) { workbook = wb; - - // Create the things we only ever need one of - dataFormat = new HSSFDataFormat(workbook.getWorkbook()); } + @Override public HSSFRichTextString createRichTextString(String text) { return new HSSFRichTextString(text); } + @Override public HSSFDataFormat createDataFormat() { - return dataFormat; + return workbook.createDataFormat(); } + @Override public HSSFHyperlink createHyperlink(int type) { return new HSSFHyperlink(type); } + @Override public HSSFExtendedColor createExtendedColor() { return new HSSFExtendedColor(new ExtendedColor()); } @@ -52,6 +59,7 @@ public class HSSFCreationHelper implements CreationHelper { * * @return a HSSFFormulaEvaluator instance */ + @Override public HSSFFormulaEvaluator createFormulaEvaluator(){ return new HSSFFormulaEvaluator(workbook); } @@ -62,6 +70,7 @@ public class HSSFCreationHelper implements CreationHelper { * @return a HSSFClientAnchor instance * @see org.apache.poi.ss.usermodel.Drawing */ + @Override public HSSFClientAnchor createClientAnchor(){ return new HSSFClientAnchor(); } diff --git a/src/java/org/apache/poi/ss/usermodel/CreationHelper.java b/src/java/org/apache/poi/ss/usermodel/CreationHelper.java index 893ce41ec2..749cacf0b7 100644 --- a/src/java/org/apache/poi/ss/usermodel/CreationHelper.java +++ b/src/java/org/apache/poi/ss/usermodel/CreationHelper.java @@ -58,5 +58,11 @@ public interface CreationHelper { */ ExtendedColor createExtendedColor(); + /** + * Creates a ClientAnchor. Use this object to position drawing object in a sheet + * + * @return a ClientAnchor instance + * @see org.apache.poi.ss.usermodel.Drawing + */ ClientAnchor createClientAnchor(); } diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCreationHelper.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCreationHelper.java index 128803bfe0..24d6866657 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCreationHelper.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCreationHelper.java @@ -22,6 +22,7 @@ import org.apache.poi.ss.usermodel.CreationHelper; import org.apache.poi.ss.usermodel.DataFormat; import org.apache.poi.ss.usermodel.ExtendedColor; import org.apache.poi.ss.usermodel.Hyperlink; +import org.apache.poi.util.Internal; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; import org.apache.poi.xssf.usermodel.XSSFCreationHelper; @@ -33,35 +34,47 @@ import org.apache.poi.xssf.usermodel.XSSFRichTextString; * regular XSSF Workbook */ public class SXSSFCreationHelper implements CreationHelper { - private static POILogger logger = POILogFactory.getLogger(SXSSFCreationHelper.class); + private static final POILogger logger = POILogFactory.getLogger(SXSSFCreationHelper.class); - private SXSSFWorkbook wb; - private XSSFCreationHelper helper; + private final SXSSFWorkbook wb; + private final XSSFCreationHelper helper; + /** + * Should only be called by {@link SXSSFWorkbook#getCreationHelper()} + * + * @param workbook the workbook to create objects for + */ + @Internal public SXSSFCreationHelper(SXSSFWorkbook workbook) { this.helper = new XSSFCreationHelper(workbook.getXSSFWorkbook()); this.wb = workbook; } + @Override public XSSFRichTextString createRichTextString(String text) { logger.log(POILogger.INFO, "SXSSF doesn't support Rich Text Strings, any formatting information will be lost"); return new XSSFRichTextString(text); } + @Override public SXSSFFormulaEvaluator createFormulaEvaluator() { return new SXSSFFormulaEvaluator(wb); } // Pass-through methods + @Override public DataFormat createDataFormat() { return helper.createDataFormat(); } + @Override public Hyperlink createHyperlink(int type) { return helper.createHyperlink(type); } + @Override public ExtendedColor createExtendedColor() { return helper.createExtendedColor(); } + @Override public ClientAnchor createClientAnchor() { return helper.createClientAnchor(); } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCreationHelper.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCreationHelper.java index 2e5ca2d958..4ea560d33a 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCreationHelper.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCreationHelper.java @@ -21,8 +21,13 @@ import org.apache.poi.ss.usermodel.Hyperlink; import org.apache.poi.util.Internal; public class XSSFCreationHelper implements CreationHelper { - private XSSFWorkbook workbook; + private final XSSFWorkbook workbook; + /** + * Should only be called by {@link XSSFWorkbook#getCreationHelper()} + * + * @param wb the workbook to create objects for + */ @Internal public XSSFCreationHelper(XSSFWorkbook wb) { workbook = wb; @@ -31,16 +36,19 @@ public class XSSFCreationHelper implements CreationHelper { /** * Creates a new XSSFRichTextString for you. */ + @Override public XSSFRichTextString createRichTextString(String text) { XSSFRichTextString rt = new XSSFRichTextString(text); rt.setStylesTableReference(workbook.getStylesSource()); return rt; } + @Override public XSSFDataFormat createDataFormat() { return workbook.createDataFormat(); } + @Override public XSSFColor createExtendedColor() { return new XSSFColor(); } @@ -50,6 +58,7 @@ public class XSSFCreationHelper implements CreationHelper { * * @param type - the type of hyperlink to create, see {@link Hyperlink} */ + @Override public XSSFHyperlink createHyperlink(int type) { return new XSSFHyperlink(type); } @@ -59,6 +68,7 @@ public class XSSFCreationHelper implements CreationHelper { * * @return a XSSFFormulaEvaluator instance */ + @Override public XSSFFormulaEvaluator createFormulaEvaluator() { return new XSSFFormulaEvaluator(workbook); } @@ -70,6 +80,7 @@ public class XSSFCreationHelper implements CreationHelper { * @return a XSSFClientAnchor instance * @see org.apache.poi.ss.usermodel.Drawing */ + @Override public XSSFClientAnchor createClientAnchor() { return new XSSFClientAnchor(); }