Skip to content

Commit 8a7cd63

Browse files
committed
bug 58775: add Override annotations, Javadocs, and comments
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1721880 13f79535-47bb-0310-9956-ffa450edef68
1 parent a94df00 commit 8a7cd63

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ public String getNumberFormatAt(int idx) {
210210
return numberFormats.get(idx);
211211
}
212212

213+
/**
214+
* Puts <code>fmt</code> in the numberFormats map if the format is not
215+
* already in the the number format style table.
216+
* Does nothing if <code>fmt</code> is already in number format style table.
217+
*
218+
* @param fmt the number format to add to number format style table
219+
* @return the index of <code>fmt</code> in the number format style table
220+
*/
213221
public int putNumberFormat(String fmt) {
214222
if (numberFormats.containsValue(fmt)) {
215223
// Find the key, and return that

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataFormat.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,16 @@ Licensed to the Apache Software Foundation (ASF) under one or more
2323
/**
2424
* Handles data formats for XSSF.
2525
*
26+
* Per Microsoft Excel 2007+ format limitations:
27+
* Workbooks support between 200 and 250 "number formats"
28+
* (POI calls them "data formats") So short or even byte
29+
* would be acceptable data types to use for referring to
30+
* data format indices.
31+
* https://support.office.com/en-us/article/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3
32+
*
2633
*/
2734
public class XSSFDataFormat implements DataFormat {
28-
private StylesTable stylesSource;
35+
private final StylesTable stylesSource;
2936

3037
protected XSSFDataFormat(StylesTable stylesSource) {
3138
this.stylesSource = stylesSource;
@@ -36,9 +43,10 @@ protected XSSFDataFormat(StylesTable stylesSource) {
3643
* string, creating a new format entry if required.
3744
* Aliases text to the proper format as required.
3845
*
39-
* @param format string matching a built in format
46+
* @param format string matching a built-in format
4047
* @return index of format.
4148
*/
49+
@Override
4250
public short getFormat(String format) {
4351
int idx = BuiltinFormats.getBuiltinFormat(format);
4452
if(idx == -1) idx = stylesSource.putNumberFormat(format);
@@ -48,17 +56,24 @@ public short getFormat(String format) {
4856
/**
4957
* get the format string that matches the given format index
5058
* @param index of a format
51-
* @return string represented at index of format or null if there is not a format at that index
59+
* @return string represented at index of format or <code>null</code> if there is not a format at that index
5260
*/
61+
@Override
5362
public String getFormat(short index) {
5463
return getFormat(index&0xffff);
5564
}
5665
/**
5766
* get the format string that matches the given format index
5867
* @param index of a format
59-
* @return string represented at index of format or null if there is not a format at that index
68+
* @return string represented at index of format or <code>null</code> if there is not a format at that index
6069
*/
6170
public String getFormat(int index) {
71+
// Indices used for built-in formats may be overridden with
72+
// custom formats, such as locale-specific currency.
73+
// See org.apache.poi.xssf.usermodel.TestXSSFDataFormat#test49928()
74+
// or bug 49928 for an example.
75+
// This is why we need to check stylesSource first and only fall back to
76+
// BuiltinFormats if the format hasn't been overridden.
6277
String fmt = stylesSource.getNumberFormatAt(index);
6378
if(fmt == null) fmt = BuiltinFormats.getBuiltinFormat(index);
6479
return fmt;

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ public XSSFCellStyle createCellStyle() {
660660
}
661661

662662
/**
663-
* Returns the instance of XSSFDataFormat for this workbook.
663+
* Returns the workbook's data format table (a factory for creating data format strings).
664664
*
665665
* @return the XSSFDataFormat object
666666
* @see org.apache.poi.ss.usermodel.DataFormat

0 commit comments

Comments
 (0)