git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1888977 13f79535-47bb-0310-9956-ffa450edef68tags/REL_5_1_0
@@ -144,18 +144,21 @@ public class ExternalLinksTable extends POIXMLDocumentPart { | |||
protected class ExternalName implements Name { | |||
private CTExternalDefinedName name; | |||
private final CTExternalDefinedName name; | |||
protected ExternalName(CTExternalDefinedName name) { | |||
this.name = name; | |||
} | |||
@Override | |||
public String getNameName() { | |||
return name.getName(); | |||
} | |||
@Override | |||
public void setNameName(String name) { | |||
this.name.setName(name); | |||
} | |||
@Override | |||
public String getSheetName() { | |||
int sheetId = getSheetIndex(); | |||
if (sheetId >= 0) { | |||
@@ -164,29 +167,35 @@ public class ExternalLinksTable extends POIXMLDocumentPart { | |||
return null; | |||
} | |||
} | |||
@Override | |||
public int getSheetIndex() { | |||
if (name.isSetSheetId()) { | |||
return (int)name.getSheetId(); | |||
} | |||
return -1; | |||
} | |||
@Override | |||
public void setSheetIndex(int sheetId) { | |||
name.setSheetId(sheetId); | |||
} | |||
@Override | |||
public String getRefersToFormula() { | |||
// Return, without the leading = | |||
return name.getRefersTo().substring(1); | |||
} | |||
@Override | |||
public void setRefersToFormula(String formulaText) { | |||
// Save with leading = | |||
name.setRefersTo('=' + formulaText); | |||
} | |||
@Override | |||
public boolean isFunctionName() { | |||
return false; | |||
} | |||
@Override | |||
public boolean isDeleted() { | |||
return false; | |||
} | |||
@@ -196,12 +205,15 @@ public class ExternalLinksTable extends POIXMLDocumentPart { | |||
return false; | |||
} | |||
@Override | |||
public String getComment() { | |||
return null; | |||
} | |||
@Override | |||
public void setComment(String comment) { | |||
throw new IllegalStateException("Not Supported"); | |||
} | |||
@Override | |||
public void setFunction(boolean value) { | |||
throw new IllegalStateException("Not Supported"); | |||
} |
@@ -49,9 +49,9 @@ public final class SSTRecord extends ContinuableRecord { | |||
* according to docs ONLY SST | |||
*/ | |||
private int field_2_num_unique_strings; | |||
private IntMapper<UnicodeString> field_3_strings; | |||
private final IntMapper<UnicodeString> field_3_strings; | |||
private SSTDeserializer deserializer; | |||
private final SSTDeserializer deserializer; | |||
/** | |||
* Offsets from the beginning of the SST record (even across continuations) | |||
@@ -134,6 +134,7 @@ public final class SSTRecord extends ContinuableRecord { | |||
return field_3_strings.get( id ); | |||
} | |||
@Override | |||
public short getSid() { | |||
return sid; | |||
} | |||
@@ -143,8 +144,7 @@ public final class SSTRecord extends ContinuableRecord { | |||
* <P> | |||
* The data consists of sets of string data. This string data is | |||
* arranged as follows: | |||
* </P> | |||
* <pre> | |||
* <pre>{@code | |||
* short string_length; // length of string data | |||
* byte string_flag; // flag specifying special string | |||
* // handling | |||
@@ -157,12 +157,11 @@ public final class SSTRecord extends ContinuableRecord { | |||
* // array is run_count) | |||
* byte[] extension; // optional extension (length of array | |||
* // is extend_length) | |||
* </pre> | |||
* }</pre> | |||
* <P> | |||
* The string_flag is bit mapped as follows: | |||
* </P> | |||
* <P> | |||
* <TABLE summary="string_flag mapping"> | |||
* <TABLE> | |||
* <caption>string_flag mapping</caption> | |||
* <TR> | |||
* <TH>Bit number</TH> | |||
* <TH>Meaning if 0</TH> | |||
@@ -252,6 +251,7 @@ public final class SSTRecord extends ContinuableRecord { | |||
return field_3_strings.size(); | |||
} | |||
@Override | |||
protected void serialize(ContinuableRecordOutput out) { | |||
SSTSerializer serializer = new SSTSerializer(field_3_strings, getNumStrings(), getNumUniqueStrings() ); | |||
serializer.serialize(out); | |||
@@ -313,7 +313,7 @@ public final class SSTRecord extends ContinuableRecord { | |||
return GenericRecordUtil.getGenericProperties( | |||
"numStrings", this::getNumStrings, | |||
"numUniqueStrings", this::getNumUniqueStrings, | |||
"strings", () -> field_3_strings.getElements(), | |||
"strings", field_3_strings::getElements, | |||
"bucketAbsoluteOffsets", () -> bucketAbsoluteOffsets, | |||
"bucketRelativeOffsets", () -> bucketRelativeOffsets | |||
); |
@@ -67,7 +67,7 @@ public final class HSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E | |||
public void clearAllCachedResultValues() { | |||
// nothing to do | |||
} | |||
@Override | |||
public HSSFName createName() { | |||
return _uBook.createName(); | |||
@@ -82,7 +82,7 @@ public final class HSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E | |||
public int getExternalSheetIndex(String workbookName, String sheetName) { | |||
return _iBook.getExternalSheetIndex(workbookName, sheetName); | |||
} | |||
@Override | |||
public Ptg get3DReferencePtg(CellReference cr, SheetIdentifier sheet) { | |||
int extIx = getSheetExtIx(sheet); | |||
@@ -107,7 +107,7 @@ public final class HSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E | |||
* | |||
* @param name the name to search | |||
* @param sheetIndex the 0-based index of the sheet this formula belongs to. | |||
* The sheet index is required to resolve sheet-level names. <code>-1</code> means workbook-global names | |||
* The sheet index is required to resolve sheet-level names. {@code -1} means workbook-global names | |||
*/ | |||
@Override | |||
public EvaluationName getName(String name, int sheetIndex) { | |||
@@ -160,10 +160,10 @@ public final class HSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E | |||
// Not actually sheet based at all - is workbook scoped | |||
return null; | |||
} | |||
// Look up the local sheet | |||
String sheetName = getSheetName(localSheetIndex); | |||
// Is it a single local sheet, or a range? | |||
int lastLocalSheetIndex = _iBook.getLastSheetIndexFromExternSheetIndex(externSheetIndex); | |||
if (lastLocalSheetIndex == localSheetIndex) { | |||
@@ -177,7 +177,7 @@ public final class HSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E | |||
} | |||
/** | |||
* @throws IllegalStateException: XSSF-style external references are not supported for HSSF | |||
* @throws IllegalStateException XSSF-style external references are not supported for HSSF | |||
*/ | |||
@Override | |||
public ExternalSheet getExternalSheet(String firstSheetName, String lastSheetName, int externalWorkbookNumber) { | |||
@@ -190,7 +190,7 @@ public final class HSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E | |||
} | |||
/** | |||
* @throws IllegalStateException: XSSF-style external names are not supported for HSSF | |||
* @throws IllegalStateException XSSF-style external names are not supported for HSSF | |||
*/ | |||
@Override | |||
public ExternalName getExternalName(String nameName, String sheetName, int externalWorkbookNumber) { | |||
@@ -275,14 +275,14 @@ public final class HSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E | |||
if (sheetIden == null) { | |||
extIx = -1; | |||
} else { | |||
String workbookName = sheetIden.getBookName(); | |||
String workbookName = sheetIden.getBookName(); | |||
String firstSheetName = sheetIden.getSheetIdentifier().getName(); | |||
String lastSheetName = firstSheetName; | |||
if (sheetIden instanceof SheetRangeIdentifier) { | |||
lastSheetName = ((SheetRangeIdentifier)sheetIden).getLastSheetIdentifier().getName(); | |||
} | |||
if (workbookName == null) { | |||
int firstSheetIndex = _uBook.getSheetIndex(firstSheetName); | |||
int lastSheetIndex = _uBook.getSheetIndex(lastSheetName); | |||
@@ -300,7 +300,7 @@ public final class HSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E | |||
} | |||
/** | |||
* @throws IllegalStateException: data tables are not supported in Excel 97-2003 format | |||
* @throws IllegalStateException data tables are not supported in Excel 97-2003 format | |||
*/ | |||
@Override | |||
public Table getTable(String name) { |
@@ -32,12 +32,12 @@ import org.apache.poi.ss.util.CellReference; | |||
* 'named range' or name of a user defined function. | |||
*/ | |||
public final class HSSFName implements Name { | |||
private HSSFWorkbook _book; | |||
private NameRecord _definedNameRec; | |||
private NameCommentRecord _commentRec; | |||
/** | |||
private final HSSFWorkbook _book; | |||
private final NameRecord _definedNameRec; | |||
private final NameCommentRecord _commentRec; | |||
/** | |||
* Creates new HSSFName - called by HSSFWorkbook to create a name from | |||
* scratch. | |||
* | |||
@@ -48,7 +48,7 @@ public final class HSSFName implements Name { | |||
/* package */ HSSFName(HSSFWorkbook book, NameRecord name) { | |||
this(book, name, null); | |||
} | |||
/** | |||
/** | |||
* Creates new HSSFName - called by HSSFWorkbook to create a name from | |||
* scratch. | |||
* | |||
@@ -66,6 +66,7 @@ public final class HSSFName implements Name { | |||
/** Get the sheets name which this named range is referenced to | |||
* @return sheet name, which this named range referred to | |||
*/ | |||
@Override | |||
public String getSheetName() { | |||
int indexToExternSheet = _definedNameRec.getExternSheetNumber(); | |||
@@ -75,6 +76,7 @@ public final class HSSFName implements Name { | |||
/** | |||
* @return text name of this defined name | |||
*/ | |||
@Override | |||
public String getNameName(){ | |||
return _definedNameRec.getNameText(); | |||
} | |||
@@ -104,7 +106,7 @@ public final class HSSFName implements Name { | |||
* <p> | |||
* A name must always be unique within its scope. POI prevents you from defining a name that is not unique | |||
* within its scope. However you can use the same name in different scopes. Example: | |||
* <pre><blockquote> | |||
* <pre>{@code | |||
* //by default names are workbook-global | |||
* HSSFName name; | |||
* name = workbook.createName(); | |||
@@ -122,12 +124,12 @@ public final class HSSFName implements Name { | |||
* name.setSheetIndex(0); | |||
* name.setNameName("sales_08"); //will throw an exception: "The sheet already contains this name (case-insensitive)" | |||
* | |||
* </blockquote></pre> | |||
* </p> | |||
* }</pre> | |||
* | |||
* @param nameName named range name to set | |||
* @throws IllegalArgumentException if the name is invalid or the name already exists (case-insensitive) | |||
*/ | |||
@Override | |||
public void setNameName(String nameName){ | |||
validateName(nameName); | |||
@@ -149,7 +151,7 @@ public final class HSSFName implements Name { | |||
} | |||
} | |||
} | |||
// Update our comment, if there is one | |||
if(_commentRec != null) { | |||
_commentRec.setNameText(nameName); | |||
@@ -159,21 +161,21 @@ public final class HSSFName implements Name { | |||
/** | |||
* https://support.office.com/en-us/article/Define-and-use-names-in-formulas-4D0F13AC-53B7-422E-AFD2-ABD7FF379C64#bmsyntax_rules_for_names | |||
* | |||
* | |||
* Valid characters: | |||
* First character: { letter | underscore | backslash } | |||
* Remaining characters: { letter | number | period | underscore } | |||
* | |||
* | |||
* Cell shorthand: cannot be { "C" | "c" | "R" | "r" } | |||
* | |||
* | |||
* Cell references disallowed: cannot be a cell reference $A$1 or R1C1 | |||
* | |||
* | |||
* Spaces are not valid (follows from valid characters above) | |||
* | |||
* | |||
* Name length: (XSSF-specific?) 255 characters maximum | |||
* | |||
* | |||
* Case sensitivity: all names are case-insensitive | |||
* | |||
* | |||
* Uniqueness: must be unique (for names with the same scope) | |||
*/ | |||
private static void validateName(String name) { | |||
@@ -187,7 +189,7 @@ public final class HSSFName implements Name { | |||
if (name.equalsIgnoreCase("R") || name.equalsIgnoreCase("C")) { | |||
throw new IllegalArgumentException("Invalid name: '"+name+"': cannot be special shorthand R or C"); | |||
} | |||
// is first character valid? | |||
char c = name.charAt(0); | |||
String allowedSymbols = "_\\"; | |||
@@ -195,7 +197,7 @@ public final class HSSFName implements Name { | |||
if (!characterIsValid) { | |||
throw new IllegalArgumentException("Invalid name: '"+name+"': first character must be underscore or a letter"); | |||
} | |||
// are all other characters valid? | |||
allowedSymbols = "_.\\"; //backslashes needed for unicode escape | |||
for (final char ch : name.toCharArray()) { | |||
@@ -204,7 +206,7 @@ public final class HSSFName implements Name { | |||
throw new IllegalArgumentException("Invalid name: '"+name+"': name must be letter, digit, period, or underscore"); | |||
} | |||
} | |||
// Is the name a valid $A$1 cell reference | |||
// Because $, :, and ! are disallowed characters, A1-style references become just a letter-number combination | |||
if (name.matches("[A-Za-z]+\\d+")) { | |||
@@ -214,18 +216,20 @@ public final class HSSFName implements Name { | |||
throw new IllegalArgumentException("Invalid name: '"+name+"': cannot be $A$1-style cell reference"); | |||
} | |||
} | |||
// Is the name a valid R1C1 cell reference? | |||
if (name.matches("[Rr]\\d+[Cc]\\d+")) { | |||
throw new IllegalArgumentException("Invalid name: '"+name+"': cannot be R1C1-style cell reference"); | |||
} | |||
} | |||
@Override | |||
public void setRefersToFormula(String formulaText) { | |||
Ptg[] ptgs = HSSFFormulaParser.parse(formulaText, _book, FormulaType.NAMEDRANGE, getSheetIndex()); | |||
_definedNameRec.setNameDefinition(ptgs); | |||
} | |||
@Override | |||
public String getRefersToFormula() { | |||
if (_definedNameRec.isFunctionName()) { | |||
throw new IllegalStateException("Only applicable to named ranges"); | |||
@@ -240,9 +244,9 @@ public final class HSSFName implements Name { | |||
/** | |||
* Sets the NameParsedFormula structure that specifies the formula for the | |||
* Sets the NameParsedFormula structure that specifies the formula for the | |||
* defined name. | |||
* | |||
* | |||
* @param ptgs the sequence of {@link Ptg}s for the formula. | |||
*/ | |||
void setNameDefinition(Ptg[] ptgs) { | |||
@@ -250,6 +254,7 @@ public final class HSSFName implements Name { | |||
} | |||
@Override | |||
public boolean isDeleted(){ | |||
Ptg[] ptgs = _definedNameRec.getNameDefinition(); | |||
return Ptg.doesFormulaReferToDeletedCell(ptgs); | |||
@@ -260,6 +265,7 @@ public final class HSSFName implements Name { | |||
* | |||
* @return true if this name is a function name | |||
*/ | |||
@Override | |||
public boolean isFunctionName() { | |||
return _definedNameRec.isFunctionName(); | |||
} | |||
@@ -270,6 +276,7 @@ public final class HSSFName implements Name { | |||
* | |||
* @return true if this name is a hidden one | |||
*/ | |||
@Override | |||
public boolean isHidden() { | |||
return _definedNameRec.isHiddenName(); | |||
} | |||
@@ -287,6 +294,7 @@ public final class HSSFName implements Name { | |||
* to the collection of sheets as they appear in the workbook. | |||
* @throws IllegalArgumentException if the sheet index is invalid. | |||
*/ | |||
@Override | |||
public void setSheetIndex(int index){ | |||
int lastSheetIx = _book.getNumberOfSheets() - 1; | |||
if (index < -1 || index > lastSheetIx) { | |||
@@ -302,6 +310,7 @@ public final class HSSFName implements Name { | |||
* | |||
* @return the sheet index this name applies to, -1 if this name applies to the entire workbook | |||
*/ | |||
@Override | |||
public int getSheetIndex(){ | |||
return _definedNameRec.getSheetNumber() - 1; | |||
} | |||
@@ -311,6 +320,7 @@ public final class HSSFName implements Name { | |||
* | |||
* @return the user comment for this named range | |||
*/ | |||
@Override | |||
public String getComment() { | |||
if(_commentRec != null) { | |||
// Prefer the comment record if it has text in it | |||
@@ -327,6 +337,7 @@ public final class HSSFName implements Name { | |||
* | |||
* @param comment the user comment for this named range | |||
*/ | |||
@Override | |||
public void setComment(String comment){ | |||
// Update the main record | |||
_definedNameRec.setDescriptionText(comment); | |||
@@ -340,8 +351,9 @@ public final class HSSFName implements Name { | |||
* Indicates that the defined name refers to a user-defined function. | |||
* This attribute is used when there is an add-in or other code project associated with the file. | |||
* | |||
* @param value <code>true</code> indicates the name refers to a function. | |||
* @param value {@code true} indicates the name refers to a function. | |||
*/ | |||
@Override | |||
public void setFunction(boolean value) { | |||
_definedNameRec.setFunction(value); | |||
} |
@@ -370,7 +370,7 @@ public final class CryptoFunctions { | |||
* | |||
* @see <a href="http://msdn.microsoft.com/en-us/library/dd926947.aspx">2.3.7.1 Binary Document Password Verifier Derivation Method 1</a> | |||
* @see <a href="http://msdn.microsoft.com/en-us/library/dd905229.aspx">2.3.7.4 Binary Document Password Verifier Derivation Method 2</a> | |||
* @see <a href="http://www.ecma-international.org/news/TC45_current_work/Office Open XML Part 4 - Markup Language Reference.pdf">Part 4 - Markup Language Reference - Ecma International - 3.2.12 fileSharing</a> | |||
* @see <a href="https://www.ecma-international.org/publications-and-standards/standards/ecma-376/">Part 4 - Markup Language Reference - Ecma International - 3.2.12 fileSharing</a> | |||
* | |||
* @param password the password | |||
* @return the verifier (actually a short value) |
@@ -49,7 +49,7 @@ public enum SpreadsheetVersion { | |||
* (actually limited by available memory in Excel)</li> | |||
* <li>Number of cell styles is 64000</li> | |||
* <li>Length of text cell contents is 32767</li> | |||
* <ul> | |||
* </ul> | |||
*/ | |||
EXCEL2007(0x100000, 0x4000, 255, Integer.MAX_VALUE, 64000, 32767); | |||
@@ -60,7 +60,7 @@ public enum SpreadsheetVersion { | |||
private final int _maxCellStyles; | |||
private final int _maxTextLength; | |||
private SpreadsheetVersion(int maxRows, int maxColumns, int maxFunctionArgs, int maxCondFormats, int maxCellStyles, int maxText) { | |||
SpreadsheetVersion(int maxRows, int maxColumns, int maxFunctionArgs, int maxCondFormats, int maxCellStyles, int maxText) { | |||
_maxRows = maxRows; | |||
_maxColumns = maxColumns; | |||
_maxFunctionArgs = maxFunctionArgs; | |||
@@ -77,7 +77,7 @@ public enum SpreadsheetVersion { | |||
} | |||
/** | |||
* @return the last (maximum) valid row index, equals to <code> getMaxRows() - 1 </code> | |||
* @return the last (maximum) valid row index, equals to {@code getMaxRows() - 1 } | |||
*/ | |||
public int getLastRowIndex() { | |||
return _maxRows - 1; | |||
@@ -91,7 +91,7 @@ public enum SpreadsheetVersion { | |||
} | |||
/** | |||
* @return the last (maximum) valid column index, equals to <code> getMaxColumns() - 1 </code> | |||
* @return the last (maximum) valid column index, equals to {@code getMaxColumns() - 1 } | |||
*/ | |||
public int getLastColumnIndex() { | |||
return _maxColumns - 1; | |||
@@ -121,7 +121,7 @@ public enum SpreadsheetVersion { | |||
/** | |||
* | |||
* @return the last valid column index in a ALPHA-26 representation | |||
* (<code>IV</code> or <code>XFD</code>). | |||
* ({@code IV} or {@code XFD}). | |||
*/ | |||
public String getLastColumnName() { | |||
return CellReference.convertNumToColString(getLastColumnIndex()); |
@@ -17,7 +17,6 @@ | |||
package org.apache.poi.ss.format; | |||
import java.util.Locale; | |||
import java.util.logging.Logger; | |||
import org.apache.poi.util.LocaleUtil; | |||
@@ -25,9 +24,6 @@ import org.apache.poi.util.LocaleUtil; | |||
* This is the abstract supertype for the various cell formatters. | |||
*/ | |||
public abstract class CellFormatter { | |||
/** The logger to use in the formatting code. */ | |||
private static final Logger LOG = Logger.getLogger(CellFormatter.class.getName()); | |||
/** The original specified format. */ | |||
protected final String format; | |||
protected final Locale locale; | |||
@@ -54,7 +50,7 @@ public abstract class CellFormatter { | |||
/** | |||
* Format a value according the format string. | |||
* <p/> | |||
* <p> | |||
* NOTE: this method must be thread safe! In particular, if it uses a | |||
* Format instance that is not thread safe, i.e. DateFormat, this method | |||
* must be synchronized, either on the method, if the format is a final | |||
@@ -67,7 +63,7 @@ public abstract class CellFormatter { | |||
/** | |||
* Format a value according to the type, in the most basic way. | |||
* <p/> | |||
* <p> | |||
* NOTE: this method must be thread safe! In particular, if it uses a | |||
* Format instance that is not thread safe, i.e. DateFormat, this method | |||
* must be synchronized, either on the method, if the format is a final |
@@ -41,6 +41,7 @@ public class CellGeneralFormatter extends CellFormatter { | |||
* @param toAppendTo The buffer to append to. | |||
* @param value The value to format. | |||
*/ | |||
@Override | |||
public void formatValue(StringBuffer toAppendTo, Object value) { | |||
if (value instanceof Number) { | |||
double val = ((Number) value).doubleValue(); | |||
@@ -86,6 +87,7 @@ public class CellGeneralFormatter extends CellFormatter { | |||
} | |||
/** Equivalent to {@link #formatValue(StringBuffer,Object)}. {@inheritDoc}. */ | |||
@Override | |||
public void simpleValue(StringBuffer toAppendTo, Object value) { | |||
formatValue(toAppendTo, value); | |||
} |
@@ -50,7 +50,7 @@ public class CellTextFormatter extends CellFormatter { | |||
} | |||
} | |||
/** {@inheritDoc} */ | |||
@Override | |||
public void formatValue(StringBuffer toAppendTo, Object obj) { | |||
int start = toAppendTo.length(); | |||
String text = obj.toString(); | |||
@@ -69,6 +69,7 @@ public class CellTextFormatter extends CellFormatter { | |||
* <p> | |||
* For text, this is just printing the text. | |||
*/ | |||
@Override | |||
public void simpleValue(StringBuffer toAppendTo, Object value) { | |||
SIMPLE_TEXT.formatValue(toAppendTo, value); | |||
} |
@@ -81,7 +81,7 @@ public interface EvaluationWorkbook { | |||
* | |||
* @since POI 3.15 beta 3 | |||
*/ | |||
public void clearAllCachedResultValues(); | |||
void clearAllCachedResultValues(); | |||
class ExternalSheet { | |||
private final String _workbookName; |
@@ -28,7 +28,7 @@ import org.apache.poi.util.Internal; | |||
@Internal | |||
public interface FormulaRenderingWorkbook { | |||
/** | |||
* @return <code>null</code> if externSheetIndex refers to a sheet inside the current workbook | |||
* @return {@code null} if externSheetIndex refers to a sheet inside the current workbook | |||
*/ | |||
ExternalSheet getExternalSheet(int externSheetIndex); | |||
@@ -20,8 +20,6 @@ package org.apache.poi.ss.formula.eval; | |||
import org.apache.poi.ss.formula.functions.ArrayFunction; | |||
import org.apache.poi.ss.formula.functions.Fixed2ArgFunction; | |||
import org.apache.poi.ss.formula.functions.Function; | |||
import org.apache.poi.ss.formula.functions.MatrixFunction.MutableValueCollector; | |||
import org.apache.poi.ss.formula.functions.MatrixFunction.TwoArrayArg; | |||
public abstract class TwoOperandNumericOperation extends Fixed2ArgFunction implements ArrayFunction { | |||
@@ -30,7 +28,8 @@ public abstract class TwoOperandNumericOperation extends Fixed2ArgFunction imple | |||
return OperandResolver.coerceValueToDouble(ve); | |||
} | |||
public ValueEval evaluateArray(ValueEval[] args, int srcRowIndex, int srcColumnIndex) { | |||
@Override | |||
public ValueEval evaluateArray(ValueEval[] args, int srcRowIndex, int srcColumnIndex) { | |||
if (args.length != 2) { | |||
return ErrorEval.VALUE_INVALID; | |||
} | |||
@@ -50,6 +49,7 @@ public abstract class TwoOperandNumericOperation extends Fixed2ArgFunction imple | |||
} | |||
@Override | |||
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1) { | |||
double result; | |||
try { | |||
@@ -73,35 +73,14 @@ public abstract class TwoOperandNumericOperation extends Fixed2ArgFunction imple | |||
protected abstract double evaluate(double d0, double d1) throws EvaluationException; | |||
private final class ArrayEval extends TwoArrayArg { | |||
private final MutableValueCollector instance = new MutableValueCollector(true, true); | |||
protected double[] collectValues(ValueEval arg) throws EvaluationException { | |||
return instance.collectValues(arg); | |||
} | |||
protected double[][] evaluate(double[][] d1, double[][] d2) throws IllegalArgumentException, EvaluationException { | |||
int width = (d1[0].length < d2[0].length) ? d1[0].length : d2[0].length; | |||
int height = (d1.length < d2.length) ? d1.length : d2.length; | |||
double[][] result = new double[height][width]; | |||
for (int j = 0; j < height; j++) { | |||
for (int i = 0; i < width; i++) { | |||
result[j][i] = TwoOperandNumericOperation.this.evaluate(d1[j][i], d2[j][i]); | |||
} | |||
} | |||
return result; | |||
} | |||
} | |||
public static final Function AddEval = new TwoOperandNumericOperation() { | |||
@Override | |||
protected double evaluate(double d0, double d1) { | |||
return d0+d1; | |||
} | |||
}; | |||
public static final Function DivideEval = new TwoOperandNumericOperation() { | |||
@Override | |||
protected double evaluate(double d0, double d1) throws EvaluationException { | |||
if (d1 == 0.0) { | |||
throw new EvaluationException(ErrorEval.DIV_ZERO); | |||
@@ -110,11 +89,13 @@ public abstract class TwoOperandNumericOperation extends Fixed2ArgFunction imple | |||
} | |||
}; | |||
public static final Function MultiplyEval = new TwoOperandNumericOperation() { | |||
@Override | |||
protected double evaluate(double d0, double d1) { | |||
return d0*d1; | |||
} | |||
}; | |||
public static final Function PowerEval = new TwoOperandNumericOperation() { | |||
@Override | |||
protected double evaluate(double d0, double d1) { | |||
if(d0 < 0 && Math.abs(d1) > 0.0 && Math.abs(d1) < 1.0) { | |||
return -1 * Math.pow(d0 * -1, d1); | |||
@@ -126,6 +107,7 @@ public abstract class TwoOperandNumericOperation extends Fixed2ArgFunction imple | |||
public SubtractEvalClass() { | |||
// | |||
} | |||
@Override | |||
protected double evaluate(double d0, double d1) { | |||
return d0-d1; | |||
} |
@@ -36,7 +36,7 @@ import org.apache.poi.util.Internal; | |||
* Represents a workbook being used for forked evaluation. Most operations are delegated to the | |||
* shared master workbook, except those that potentially involve cell values that may have been | |||
* updated after a call to {@link #getOrCreateUpdatableCell(String, int, int)}.<br> | |||
* | |||
* | |||
* For POI internal use only | |||
*/ | |||
@Internal | |||
@@ -117,7 +117,7 @@ final class ForkedEvaluationWorkbook implements EvaluationWorkbook { | |||
public EvaluationSheet getSheet(int sheetIndex) { | |||
return getSharedSheet(getSheetName(sheetIndex)); | |||
} | |||
@Override | |||
public ExternalName getExternalName(int externSheetIndex, int externNameIndex) { | |||
return _masterBook.getExternalName(externSheetIndex, externNameIndex); | |||
@@ -155,15 +155,16 @@ final class ForkedEvaluationWorkbook implements EvaluationWorkbook { | |||
public UDFFinder getUDFFinder() { | |||
return _masterBook.getUDFFinder(); | |||
} | |||
@Override | |||
public SpreadsheetVersion getSpreadsheetVersion() { | |||
return _masterBook.getSpreadsheetVersion(); | |||
} | |||
/* (non-Javadoc) | |||
* leave the map alone, if it needs resetting, reusing this class is probably a bad idea. | |||
* @see org.apache.poi.ss.formula.EvaluationSheet#clearAllCachedResultValues() | |||
* | |||
* | |||
* @since POI 3.15 beta 3 | |||
*/ | |||
@Override |
@@ -48,7 +48,7 @@ public interface ArrayFunction { | |||
* @param arg0 the first function argument. Empty values are represented with | |||
* {@link BlankEval} or {@link MissingArgEval}, never {@code null} | |||
* @param arg1 the first function argument. Empty values are represented with | |||
* @link BlankEval} or {@link MissingArgEval}, never {@code null} | |||
* {@link BlankEval} or {@link MissingArgEval}, never {@code null} | |||
* | |||
* @param srcRowIndex row index of the cell containing the formula under evaluation | |||
* @param srcColumnIndex column index of the cell containing the formula under evaluation |
@@ -29,7 +29,6 @@ import org.apache.poi.ss.formula.functions.CountUtils.I_MatchPredicate; | |||
* <caption>Parameter descriptions</caption> | |||
* <tr><th>range </th><td>is the range of cells to count blanks</td></tr> | |||
* </table> | |||
* </p> | |||
*/ | |||
public final class Countblank extends Fixed1ArgFunction { | |||
@@ -197,7 +197,7 @@ public abstract class TextFunction implements Function { | |||
* MID returns a specific number of | |||
* characters from a text string, starting at the specified position.<p> | |||
* | |||
* <b>Syntax<b>:<br> <b>MID</b>(<b>text</b>, <b>start_num</b>, | |||
* <b>Syntax</b>:<br> <b>MID</b>(<b>text</b>, <b>start_num</b>, | |||
* <b>num_chars</b>)<br> | |||
* | |||
* Author: Manda Wilson < wilson at c bio dot msk cc dot org > | |||
@@ -335,7 +335,7 @@ public abstract class TextFunction implements Function { | |||
* {@link DataFormatter} to be done, as this works much the same as the | |||
* display focused work that that does. | |||
* | |||
* <b>Syntax<b>:<br> <b>TEXT</b>(<b>value</b>, <b>format_text</b>)<br> | |||
* <b>Syntax</b>:<br> <b>TEXT</b>(<b>value</b>, <b>format_text</b>)<br> | |||
*/ | |||
public static final Function TEXT = new Fixed2ArgFunction() { | |||
@@ -62,7 +62,6 @@ public enum HorizontalAlignment { | |||
* left/right edge, don't append the additional occurrence of the value.</li> | |||
* <li>The display value of the cell is filled, not the underlying raw number.</li> | |||
* </ol> | |||
* </p> | |||
*/ | |||
FILL, | |||
@@ -92,7 +91,7 @@ public enum HorizontalAlignment { | |||
* <p> Two lines inside a cell are separated by a carriage return. </p> | |||
*/ | |||
DISTRIBUTED; | |||
public short getCode() { | |||
return (short) ordinal(); | |||
} |
@@ -90,7 +90,7 @@ public interface Name { | |||
* <p> | |||
* A name must always be unique within its scope. POI prevents you from defining a name that is not unique | |||
* within its scope. However you can use the same name in different scopes. Example: | |||
* <pre><blockquote> | |||
* <pre>{@code | |||
* //by default names are workbook-global | |||
* Name name; | |||
* name = workbook.createName(); | |||
@@ -108,8 +108,8 @@ public interface Name { | |||
* name.setSheetIndex(0); | |||
* name.setNameName("sales_08"); //will throw an exception: "The sheet already contains this name (case-insensitive)" | |||
* | |||
* </blockquote></pre> | |||
* </p> | |||
* }</pre> | |||
* | |||
* @param name named range name to set | |||
* @throws IllegalArgumentException if the name is invalid or the already exists within its scope (case-insensitive) | |||
*/ | |||
@@ -118,7 +118,7 @@ public interface Name { | |||
/** | |||
* Returns the formula that the name is defined to refer to. | |||
* | |||
* @return the reference for this name, <code>null</code> if it has not been set yet. Never empty string | |||
* @return the reference for this name, {@code null} if it has not been set yet. Never empty string | |||
* @see #setRefersToFormula(String) | |||
*/ | |||
String getRefersToFormula(); | |||
@@ -127,11 +127,11 @@ public interface Name { | |||
* Sets the formula that the name is defined to refer to. The following are representative examples: | |||
* | |||
* <ul> | |||
* <li><code>'My Sheet'!$A$3</code></li> | |||
* <li><code>8.3</code></li> | |||
* <li><code>HR!$A$1:$Z$345</code></li> | |||
* <li><code>SUM(Sheet1!A1,Sheet2!B2)</li> | |||
* <li><code>-PMT(Interest_Rate/12,Number_of_Payments,Loan_Amount)</li> | |||
* <li>{@code 'My Sheet'!$A$3}</li> | |||
* <li>{@code 8.3}</li> | |||
* <li>{@code HR!$A$1:$Z$345}</li> | |||
* <li>{@code SUM(Sheet1!A1,Sheet2!B2)}</li> | |||
* <li>{@code -PMT(Interest_Rate/12,Number_of_Payments,Loan_Amount)}</li> | |||
* </ul> | |||
* | |||
* Note: Using relative values like 'A1:B1' can lead to unexpected moving of | |||
@@ -154,7 +154,7 @@ public interface Name { | |||
/** | |||
* Checks if this name points to a cell that no longer exists | |||
* | |||
* @return <code>true</code> if the name refers to a deleted cell, <code>false</code> otherwise | |||
* @return {@code true} if the name refers to a deleted cell, {@code false} otherwise | |||
*/ | |||
boolean isDeleted(); | |||
@@ -162,7 +162,7 @@ public interface Name { | |||
* Checks if this name is hidden, eg one of the built-in Excel | |||
* internal names | |||
* | |||
* @return <code>true</code> if the name is a hidden name, <code>false</code> otherwise | |||
* @return {@code true} if the name is a hidden name, {@code false} otherwise | |||
*/ | |||
boolean isHidden(); | |||
@@ -172,34 +172,34 @@ public interface Name { | |||
* @param sheetId the sheet index this name applies to, -1 unsets this property making the name workbook-global | |||
* @throws IllegalArgumentException if the sheet index is invalid. | |||
*/ | |||
public void setSheetIndex(int sheetId); | |||
void setSheetIndex(int sheetId); | |||
/** | |||
* Returns the sheet index this name applies to. | |||
* | |||
* @return the sheet index this name applies to, -1 if this name applies to the entire workbook | |||
*/ | |||
public int getSheetIndex(); | |||
int getSheetIndex(); | |||
/** | |||
* Returns the comment the user provided when the name was created. | |||
* | |||
* @return the user comment for this named range | |||
*/ | |||
public String getComment(); | |||
String getComment(); | |||
/** | |||
* Sets the comment the user provided when the name was created. | |||
* | |||
* @param comment the user comment for this named range | |||
*/ | |||
public void setComment(String comment); | |||
void setComment(String comment); | |||
/** | |||
* Indicates that the defined name refers to a user-defined function. | |||
* This attribute is used when there is an add-in or other code project associated with the file. | |||
* | |||
* @param value <code>true</code> indicates the name refers to a function. | |||
* @param value {@code true} indicates the name refers to a function. | |||
*/ | |||
void setFunction(boolean value); | |||
} |
@@ -385,7 +385,7 @@ public class AreaReference { | |||
* Example return values: | |||
* <table> | |||
* <caption>Example return values</caption> | |||
* <tr><th align='left'>Result</th><th align='left'>Comment</th></tr> | |||
* <tr><th>Result</th><th>Comment</th></tr> | |||
* <tr><td>A1:A1</td><td>Single cell area reference without sheet</td></tr> | |||
* <tr><td>A1:$C$1</td><td>Multi-cell area reference without sheet</td></tr> | |||
* <tr><td>Sheet1!A$1:B4</td><td>Standard sheet name</td></tr> |
@@ -300,8 +300,8 @@ public class CellReference implements GenericRecord { | |||
* | |||
* POI currently targets BIFF8 (Excel 97-2003), so the following behaviour can be observed for | |||
* this method: | |||
* <blockquote><table border="0" cellpadding="1" cellspacing="0" | |||
* summary="Notable cases."> | |||
* <table> | |||
* <caption>Notable cases</caption> | |||
* <tr><th>Input </th> | |||
* <th>Result </th></tr> | |||
* <tr><td>"A", "1"</td><td>true</td></tr> | |||
@@ -313,7 +313,7 @@ public class CellReference implements GenericRecord { | |||
* <tr><td>"AAA", "1"</td><td>false</td></tr> | |||
* <tr><td>"a", "111"</td><td>true</td></tr> | |||
* <tr><td>"Sheet", "1"</td><td>false</td></tr> | |||
* </table></blockquote> | |||
* </table> | |||
* | |||
* @param colStr a string of only letter characters | |||
* @param rowStr a string of only digit characters | |||
@@ -485,7 +485,7 @@ public class CellReference implements GenericRecord { | |||
* Example return values: | |||
* <table> | |||
* <caption>Example return values</caption> | |||
* <tr><th align='left'>Result</th><th align='left'>Comment</th></tr> | |||
* <tr><th>Result</th><th>Comment</th></tr> | |||
* <tr><td>A1</td><td>Cell reference without sheet</td></tr> | |||
* <tr><td>Sheet1!A1</td><td>Standard sheet name</td></tr> | |||
* <tr><td>'O''Brien''s Sales'!A1' </td><td>Sheet name with special characters</td></tr> | |||
@@ -502,8 +502,9 @@ public class CellReference implements GenericRecord { | |||
* | |||
* <p> | |||
* Example return values: | |||
* <table border="0" cellpadding="1" cellspacing="0" summary="Example return values"> | |||
* <tr><th align='left'>Result</th><th align='left'>Comment</th></tr> | |||
* <table> | |||
* <caption>Example return values</caption> | |||
* <tr><th>Result</th><th>Comment</th></tr> | |||
* <tr><td>A1</td><td>Cell reference without sheet</td></tr> | |||
* <tr><td>Sheet1!A1</td><td>Standard sheet name</td></tr> | |||
* <tr><td>'O''Brien''s Sales'!A1' </td><td>Sheet name with special characters</td></tr> | |||
@@ -583,9 +584,7 @@ public class CellReference implements GenericRecord { | |||
&& _colIndex == cr._colIndex | |||
&& _isRowAbs == cr._isRowAbs | |||
&& _isColAbs == cr._isColAbs | |||
&& ((_sheetName == null) | |||
? (cr._sheetName == null) | |||
: _sheetName.equals(cr._sheetName)); | |||
&& Objects.equals(_sheetName, cr._sheetName); | |||
} | |||
@Override |