aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/poi
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2020-03-29 14:39:11 +0000
committerAndreas Beeker <kiwiwings@apache.org>2020-03-29 14:39:11 +0000
commitc01273ad02478412e8b92db797830f2a9f70f05b (patch)
treecaf9261b54f4858af5ca7086c5f68a71bd08e105 /src/java/org/apache/poi
parenta68b67a70bcb57131add0e602e9521b2112c1ed4 (diff)
downloadpoi-c01273ad02478412e8b92db797830f2a9f70f05b.tar.gz
poi-c01273ad02478412e8b92db797830f2a9f70f05b.zip
Sonar Fixes
- use String.replace instead of String.replaceAll for literal values - use constants from base class - deprecated various references to constants of org.apache.poi.ss.usermodel.FontFormatting - to be replaced by o.a.p.s.u.Font in POI 5.0.0 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1875859 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi')
-rw-r--r--src/java/org/apache/poi/ddf/EscherProperties.java2
-rw-r--r--src/java/org/apache/poi/ddf/EscherPropertyTypes.java1
-rw-r--r--src/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java48
-rw-r--r--src/java/org/apache/poi/hssf/record/cf/FontFormatting.java109
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java58
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFFontFormatting.java149
-rw-r--r--src/java/org/apache/poi/ss/formula/functions/Roman.java115
-rw-r--r--src/java/org/apache/poi/ss/usermodel/DataFormatter.java99
-rw-r--r--src/java/org/apache/poi/ss/usermodel/ExcelStyleDateFormatter.java14
-rw-r--r--src/java/org/apache/poi/ss/usermodel/Font.java12
-rw-r--r--src/java/org/apache/poi/ss/usermodel/FontFormatting.java122
-rw-r--r--src/java/org/apache/poi/ss/util/DateFormatConverter.java2
12 files changed, 426 insertions, 305 deletions
diff --git a/src/java/org/apache/poi/ddf/EscherProperties.java b/src/java/org/apache/poi/ddf/EscherProperties.java
index 415519b453..7cebea603b 100644
--- a/src/java/org/apache/poi/ddf/EscherProperties.java
+++ b/src/java/org/apache/poi/ddf/EscherProperties.java
@@ -24,7 +24,7 @@ import org.apache.poi.util.Removal;
*
* @deprecated use {@link EscherPropertyTypes} enum instead
*/
-@SuppressWarnings({"unused"})
+@SuppressWarnings({"unused","java:S115"})
@Deprecated
@Removal(version = "5.0.0")
public interface EscherProperties {
diff --git a/src/java/org/apache/poi/ddf/EscherPropertyTypes.java b/src/java/org/apache/poi/ddf/EscherPropertyTypes.java
index cd5b25a7d4..a48972faf3 100644
--- a/src/java/org/apache/poi/ddf/EscherPropertyTypes.java
+++ b/src/java/org/apache/poi/ddf/EscherPropertyTypes.java
@@ -25,6 +25,7 @@ import java.util.stream.Stream;
/**
* Provides a list of all known escher properties including the description and type.
*/
+@SuppressWarnings({"java:S115"})
public enum EscherPropertyTypes {
TRANSFORM__ROTATION(0x0004, "transform.rotation"),
PROTECTION__LOCKROTATION(0x0077, "protection.lockrotation"),
diff --git a/src/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java b/src/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java
index 8c2226becc..4843b1c116 100644
--- a/src/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java
+++ b/src/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java
@@ -26,7 +26,7 @@ import org.apache.poi.ss.formula.ptg.Ref3DPtg;
import org.apache.poi.ss.formula.ptg.RefPtg;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.IOUtils;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianInputStream;
import org.apache.poi.util.LittleEndianOutput;
@@ -94,13 +94,13 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord {
// 1223 void XclImpOleObj::ReadPictFmla( XclImpStream& rStrm, sal_uInt16 nRecSize )
int streamIdOffset = in.readShort(); // OOO calls this 'nFmlaLen'
- int remaining = size - LittleEndian.SHORT_SIZE;
+ int remaining = size - LittleEndianConsts.SHORT_SIZE;
int dataLenAfterFormula = remaining - streamIdOffset;
int formulaSize = in.readUShort();
- remaining -= LittleEndian.SHORT_SIZE;
+ remaining -= LittleEndianConsts.SHORT_SIZE;
field_1_unknown_int = in.readInt();
- remaining -= LittleEndian.INT_SIZE;
+ remaining -= LittleEndianConsts.INT_SIZE;
byte[] formulaRawBytes = readRawData(in, formulaSize);
remaining -= formulaSize;
field_2_refPtg = readRefPtg(formulaRawBytes);
@@ -116,16 +116,16 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord {
int stringByteCount;
if (remaining >= dataLenAfterFormula + 3) {
int tag = in.readByte();
- stringByteCount = LittleEndian.BYTE_SIZE;
+ stringByteCount = LittleEndianConsts.BYTE_SIZE;
if (tag != 0x03) {
throw new RecordFormatException("Expected byte 0x03 here");
}
int nChars = in.readUShort();
- stringByteCount += LittleEndian.SHORT_SIZE;
+ stringByteCount += LittleEndianConsts.SHORT_SIZE;
if (nChars > 0) {
// OOO: the 4th way Xcl stores a unicode string: not even a Grbit byte present if length 0
field_3_unicode_flag = ( in.readByte() & 0x01 ) != 0;
- stringByteCount += LittleEndian.BYTE_SIZE;
+ stringByteCount += LittleEndianConsts.BYTE_SIZE;
if (field_3_unicode_flag) {
field_4_ole_classname = StringUtil.readUnicodeLE(in, nChars);
stringByteCount += nChars * 2;
@@ -144,9 +144,9 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord {
// Pad to next 2-byte boundary
if (((stringByteCount + formulaSize) % 2) != 0) {
int b = in.readByte();
- remaining -= LittleEndian.BYTE_SIZE;
+ remaining -= LittleEndianConsts.BYTE_SIZE;
if (field_2_refPtg != null && field_4_ole_classname == null) {
- field_4_unknownByte = Byte.valueOf((byte)b);
+ field_4_unknownByte = (byte)b;
}
}
int nUnexpectedPadding = remaining - dataLenAfterFormula;
@@ -159,8 +159,8 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord {
// Fetch the stream ID
if (dataLenAfterFormula >= 4) {
- field_5_stream_id = Integer.valueOf(in.readInt());
- remaining -= LittleEndian.INT_SIZE;
+ field_5_stream_id = in.readInt();
+ remaining -= LittleEndianConsts.INT_SIZE;
} else {
field_5_stream_id = null;
}
@@ -199,13 +199,10 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord {
int result = 2 + 4; // formulaSize + f2unknown_int
result += formulaSize;
- int stringLen;
- if (field_4_ole_classname == null) {
- // don't write 0x03, stringLen, flag, text
- stringLen = 0;
- } else {
+ // don't write 0x03, stringLen, flag, text
+ if (field_4_ole_classname != null) {
result += 1 + 2; // 0x03, stringLen
- stringLen = field_4_ole_classname.length();
+ int stringLen = field_4_ole_classname.length();
if (stringLen > 0) {
result += 1; // flag
if (field_3_unicode_flag) {
@@ -259,14 +256,11 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord {
}
pos += formulaSize;
- int stringLen;
- if (field_4_ole_classname == null) {
- // don't write 0x03, stringLen, flag, text
- stringLen = 0;
- } else {
+ // don't write 0x03, stringLen, flag, text
+ if (field_4_ole_classname != null) {
out.writeByte(0x03);
pos+=1;
- stringLen = field_4_ole_classname.length();
+ int stringLen = field_4_ole_classname.length();
out.writeShort(stringLen);
pos+=2;
if (stringLen > 0) {
@@ -287,7 +281,6 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord {
switch(idOffset - (pos - 6)) { // 6 for 3 shorts: sid, dataSize, idOffset
case 1:
out.writeByte(field_4_unknownByte == null ? 0x00 : field_4_unknownByte.intValue());
- pos++;
break;
case 0:
break;
@@ -296,8 +289,7 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord {
}
if (field_5_stream_id != null) {
- out.writeInt(field_5_stream_id.intValue());
- pos += 4;
+ out.writeInt(field_5_stream_id);
}
out.write(field_6_unknown);
}
@@ -349,10 +341,10 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord {
sb.append(" .oleClassname = ").append(field_4_ole_classname).append("\n");
}
if (field_4_unknownByte != null) {
- sb.append(" .f4unknown = ").append(HexDump.byteToHex(field_4_unknownByte.intValue())).append("\n");
+ sb.append(" .f4unknown = ").append(HexDump.byteToHex(field_4_unknownByte)).append("\n");
}
if (field_5_stream_id != null) {
- sb.append(" .streamId = ").append(HexDump.intToHex(field_5_stream_id.intValue())).append("\n");
+ sb.append(" .streamId = ").append(HexDump.intToHex(field_5_stream_id)).append("\n");
}
if (field_6_unknown.length > 0) {
sb.append(" .f7unknown = ").append(HexDump.toHex(field_6_unknown)).append("\n");
diff --git a/src/java/org/apache/poi/hssf/record/cf/FontFormatting.java b/src/java/org/apache/poi/hssf/record/cf/FontFormatting.java
index 22a4aed29e..d8b2d11275 100644
--- a/src/java/org/apache/poi/hssf/record/cf/FontFormatting.java
+++ b/src/java/org/apache/poi/hssf/record/cf/FontFormatting.java
@@ -64,22 +64,71 @@ public final class FontFormatting implements Duplicatable {
private static final BitField shadowModified = BitFieldFactory.getInstance(0x00000010);
private static final BitField cancellationModified = BitFieldFactory.getInstance(0x00000080);
- /** Escapement type - None */
+ /**
+ * Escapement type - None
+ *
+ * @deprecated use {@link org.apache.poi.ss.usermodel.Font#SS_NONE}
+ */
+ @Deprecated
+ @Removal(version = "5.0.0")
public static final short SS_NONE = 0;
- /** Escapement type - Superscript */
+ /**
+ * Escapement type - Superscript
+ *
+ * @deprecated use {@link org.apache.poi.ss.usermodel.Font#SS_SUPER}
+ */
+ @Deprecated
+ @Removal(version = "5.0.0")
public static final short SS_SUPER = 1;
- /** Escapement type - Subscript */
+ /**
+ * Escapement type - Subscript
+ *
+ * @deprecated use {@link org.apache.poi.ss.usermodel.Font#SS_SUB}
+ */
+ @Deprecated
+ @Removal(version = "5.0.0")
public static final short SS_SUB = 2;
- /** Underline type - None */
+ /**
+ * Underline type - None
+ *
+ * @deprecated use {@link org.apache.poi.ss.usermodel.Font#U_NONE}
+ */
+ @Deprecated
+ @Removal(version = "5.0.0")
public static final byte U_NONE = 0;
- /** Underline type - Single */
+ /**
+ * Underline type - Single
+ *
+ * @deprecated use {@link org.apache.poi.ss.usermodel.Font#U_SINGLE}
+ */
+ @Deprecated
+ @Removal(version = "5.0.0")
public static final byte U_SINGLE = 1;
- /** Underline type - Double */
+ /**
+ * Underline type - Double
+ *
+ * @deprecated use {@link org.apache.poi.ss.usermodel.Font#U_DOUBLE}
+ */
+ @Deprecated
+ @Removal(version = "5.0.0")
public static final byte U_DOUBLE = 2;
- /** Underline type - Single Accounting */
+ /**
+ * Underline type - Single Accounting
+ *
+ * @deprecated use {@link org.apache.poi.ss.usermodel.Font#U_SINGLE_ACCOUNTING}
+ */
+ @Deprecated
+ @Removal(version = "5.0.0")
public static final byte U_SINGLE_ACCOUNTING = 0x21;
- /** Underline type - Double Accounting */
+ /**
+ * Underline type - Double Accounting
+ *
+ * @deprecated use {@link org.apache.poi.ss.usermodel.Font#U_DOUBLE_ACCOUNTING}
+ */
+ @Deprecated
+ @Removal(version = "5.0.0")
public static final byte U_DOUBLE_ACCOUNTING = 0x22;
+
/** Normal boldness (not bold) */
private static final short FONT_WEIGHT_NORMAL = 0x190;
@@ -253,12 +302,8 @@ public final class FontFormatting implements Duplicatable {
* @param bw - a number between 100-1000 for the fonts "boldness"
*/
- private void setFontWeight(short pbw)
- {
- short bw = pbw;
- if( bw<100) { bw=100; }
- if( bw>1000){ bw=1000; }
- setShort(OFFSET_FONT_WEIGHT, bw);
+ private void setFontWeight(short bw) {
+ setShort(OFFSET_FONT_WEIGHT, Math.max(100, Math.min(1000, bw)));
}
/**
@@ -298,9 +343,9 @@ public final class FontFormatting implements Duplicatable {
* get the type of super or subscript for the font
*
* @return super or subscript option
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#SS_NONE
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#SS_SUPER
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#SS_SUB
+ * @see org.apache.poi.ss.usermodel.Font#SS_NONE
+ * @see org.apache.poi.ss.usermodel.Font#SS_SUPER
+ * @see org.apache.poi.ss.usermodel.Font#SS_SUB
*/
public short getEscapementType()
{
@@ -311,9 +356,9 @@ public final class FontFormatting implements Duplicatable {
* set the escapement type for the font
*
* @param escapementType super or subscript option
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#SS_NONE
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#SS_SUPER
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#SS_SUB
+ * @see org.apache.poi.ss.usermodel.Font#SS_NONE
+ * @see org.apache.poi.ss.usermodel.Font#SS_SUPER
+ * @see org.apache.poi.ss.usermodel.Font#SS_SUB
*/
public void setEscapementType( short escapementType)
{
@@ -325,11 +370,11 @@ public final class FontFormatting implements Duplicatable {
*
* @return font underlining type
*
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_NONE
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_SINGLE
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_DOUBLE
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_SINGLE_ACCOUNTING
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_DOUBLE_ACCOUNTING
+ * @see org.apache.poi.ss.usermodel.Font#U_NONE
+ * @see org.apache.poi.ss.usermodel.Font#U_SINGLE
+ * @see org.apache.poi.ss.usermodel.Font#U_DOUBLE
+ * @see org.apache.poi.ss.usermodel.Font#U_SINGLE_ACCOUNTING
+ * @see org.apache.poi.ss.usermodel.Font#U_DOUBLE_ACCOUNTING
*/
public short getUnderlineType()
{
@@ -341,11 +386,11 @@ public final class FontFormatting implements Duplicatable {
*
* @param underlineType underline option
*
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_NONE
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_SINGLE
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_DOUBLE
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_SINGLE_ACCOUNTING
- * @see org.apache.poi.hssf.usermodel.HSSFFontFormatting#U_DOUBLE_ACCOUNTING
+ * @see org.apache.poi.ss.usermodel.Font#U_NONE
+ * @see org.apache.poi.ss.usermodel.Font#U_SINGLE
+ * @see org.apache.poi.ss.usermodel.Font#U_DOUBLE
+ * @see org.apache.poi.ss.usermodel.Font#U_SINGLE_ACCOUNTING
+ * @see org.apache.poi.ss.usermodel.Font#U_DOUBLE_ACCOUNTING
*/
public void setUnderlineType( short underlineType)
{
@@ -366,7 +411,7 @@ public final class FontFormatting implements Duplicatable {
private boolean getOptionFlag(BitField field) {
int optionFlags = getInt(OFFSET_OPTION_FLAGS);
int value = field.getValue(optionFlags);
- return value==0? true : false ;
+ return value == 0;
}
private void setOptionFlag(boolean modified, BitField field)
@@ -536,7 +581,7 @@ public final class FontFormatting implements Duplicatable {
}
@Override
- @SuppressWarnings("squid:S2975")
+ @SuppressWarnings({"squid:S2975", "MethodDoesntCallSuperMethod"})
@Deprecated
@Removal(version = "5.0.0")
public FontFormatting clone() {
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java b/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java
index 27e152b3af..29506743f6 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java
@@ -21,7 +21,6 @@ import org.apache.poi.hssf.model.HSSFFormulaParser;
import org.apache.poi.hssf.record.CFRule12Record;
import org.apache.poi.hssf.record.CFRuleBase;
import org.apache.poi.hssf.record.CFRuleBase.ComparisonOperator;
-import org.apache.poi.hssf.record.CFRuleRecord;
import org.apache.poi.hssf.record.cf.BorderFormatting;
import org.apache.poi.hssf.record.cf.ColorGradientFormatting;
import org.apache.poi.hssf.record.cf.DataBarFormatting;
@@ -41,8 +40,9 @@ import org.apache.poi.ss.usermodel.ExcelNumberFormat;
* It allows to specify formula based conditions for the Conditional Formatting
* and the formatting settings such as font, border and pattern.
*/
+@SuppressWarnings("unused")
public final class HSSFConditionalFormattingRule implements ConditionalFormattingRule {
- private static final byte CELL_COMPARISON = CFRuleRecord.CONDITION_TYPE_CELL_VALUE_IS;
+ private static final byte CELL_COMPARISON = CFRuleBase.CONDITION_TYPE_CELL_VALUE_IS;
private final CFRuleBase cfRuleRecord;
private final HSSFWorkbook workbook;
@@ -62,7 +62,7 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin
/**
* Only newer style formatting rules have priorities. For older ones,
- * we don't know priority for these, other than definition/model order,
+ * we don't know priority for these, other than definition/model order,
* which appears to be what Excel uses.
* @see org.apache.poi.ss.usermodel.ConditionalFormattingRule#getPriority()
*/
@@ -71,7 +71,7 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin
if (rule12 == null) return 0;
return rule12.getPriority();
}
-
+
/**
* Always true for HSSF files, per Microsoft Excel documentation
* @see org.apache.poi.ss.usermodel.ConditionalFormattingRule#getStopIfTrue()
@@ -79,20 +79,20 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin
public boolean getStopIfTrue() {
return true;
}
-
+
CFRuleBase getCfRuleRecord() {
return cfRuleRecord;
}
private CFRule12Record getCFRule12Record(boolean create) {
if (cfRuleRecord instanceof CFRule12Record) {
- // Good
- } else {
- if (create) throw new IllegalArgumentException("Can't convert a CF into a CF12 record");
- return null;
+ return (CFRule12Record) cfRuleRecord;
}
- return (CFRule12Record)cfRuleRecord;
+ if (create) {
+ throw new IllegalArgumentException("Can't convert a CF into a CF12 record");
+ }
+ return null;
}
-
+
/**
* Always null for HSSF records, until someone figures out where to find it
* @see org.apache.poi.ss.usermodel.ConditionalFormattingRule#getNumberFormat()
@@ -177,20 +177,20 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin
{
return getPatternFormatting(true);
}
-
+
private HSSFDataBarFormatting getDataBarFormatting(boolean create) {
CFRule12Record cfRule12Record = getCFRule12Record(create);
if (cfRule12Record == null) return null;
-
+
DataBarFormatting databarFormatting = cfRule12Record.getDataBarFormatting();
if (databarFormatting == null) {
if (!create) return null;
cfRule12Record.createDataBarFormatting();
}
-
+
return new HSSFDataBarFormatting(cfRule12Record, sheet);
}
-
+
/**
* @return databar / data-bar formatting object if defined, <code>null</code> otherwise
*/
@@ -204,11 +204,11 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin
public HSSFDataBarFormatting createDataBarFormatting() {
return getDataBarFormatting(true);
}
-
+
private HSSFIconMultiStateFormatting getMultiStateFormatting(boolean create) {
CFRule12Record cfRule12Record = getCFRule12Record(create);
if (cfRule12Record == null) return null;
-
+
IconMultiStateFormatting iconFormatting = cfRule12Record.getMultiStateFormatting();
if (iconFormatting == null) {
if (!create) return null;
@@ -216,7 +216,7 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin
}
return new HSSFIconMultiStateFormatting(cfRule12Record, sheet);
}
-
+
/**
* @return icon / multi-state formatting object if defined, <code>null</code> otherwise
*/
@@ -230,11 +230,11 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin
public HSSFIconMultiStateFormatting createMultiStateFormatting() {
return getMultiStateFormatting(true);
}
-
+
private HSSFColorScaleFormatting getColorScaleFormatting(boolean create) {
CFRule12Record cfRule12Record = getCFRule12Record(create);
if (cfRule12Record == null) return null;
-
+
ColorGradientFormatting colorFormatting = cfRule12Record.getColorGradientFormatting();
if (colorFormatting == null) {
if (!create) return null;
@@ -243,13 +243,14 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin
return new HSSFColorScaleFormatting(cfRule12Record, sheet);
}
-
+
/**
* @return color scale / gradient formatting object if defined, <code>null</code> otherwise
*/
public HSSFColorScaleFormatting getColorScaleFormatting() {
return getColorScaleFormatting(false);
}
+
/**
* create a new color scale / gradient formatting object if it does not exist,
* otherwise just return the existing object.
@@ -257,7 +258,7 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin
public HSSFColorScaleFormatting createColorScaleFormatting() {
return getColorScaleFormatting(true);
}
-
+
/**
* @return - the conditiontype for the cfrule
*/
@@ -274,11 +275,11 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin
public ConditionFilterType getConditionFilterType() {
return getConditionType() == ConditionType.FILTER ? ConditionFilterType.FILTER : null;
}
-
+
public ConditionFilterData getFilterConfiguration() {
return null;
}
-
+
/**
* @return - the comparisionoperatation for the cfrule
*/
@@ -308,17 +309,18 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin
public String getText() {
return null; // not available here, unless it exists and is unimplemented in cfRuleRecord
}
-
- protected String toFormulaString(Ptg[] parsedExpression) {
+
+ String toFormulaString(Ptg[] parsedExpression) {
return toFormulaString(parsedExpression, workbook);
}
- protected static String toFormulaString(Ptg[] parsedExpression, HSSFWorkbook workbook) {
+
+ static String toFormulaString(Ptg[] parsedExpression, HSSFWorkbook workbook) {
if(parsedExpression == null || parsedExpression.length == 0) {
return null;
}
return HSSFFormulaParser.toFormulaString(workbook, parsedExpression);
}
-
+
/**
* Conditional format rules don't define stripes, so always 0
* @see org.apache.poi.ss.usermodel.DifferentialStyleProvider#getStripeSize()
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFFontFormatting.java b/src/java/org/apache/poi/hssf/usermodel/HSSFFontFormatting.java
index 07f5fd4727..40cf873306 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFFontFormatting.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFFontFormatting.java
@@ -21,31 +21,59 @@ import org.apache.poi.hssf.record.CFRuleBase;
import org.apache.poi.hssf.record.cf.FontFormatting;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.Color;
+import org.apache.poi.util.Removal;
+
/**
* High level representation for Font Formatting component
* of Conditional Formatting settings
*/
+@SuppressWarnings("unused")
public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.FontFormatting {
- /** Underline type - None */
- public final static byte U_NONE = FontFormatting.U_NONE;
- /** Underline type - Single */
- public final static byte U_SINGLE = FontFormatting.U_SINGLE;
- /** Underline type - Double */
- public final static byte U_DOUBLE = FontFormatting.U_DOUBLE;
- /** Underline type - Single Accounting */
- public final static byte U_SINGLE_ACCOUNTING = FontFormatting.U_SINGLE_ACCOUNTING;
- /** Underline type - Double Accounting */
- public final static byte U_DOUBLE_ACCOUNTING = FontFormatting.U_DOUBLE_ACCOUNTING;
+ /**
+ * Underline type - None
+ * @deprecated use {@link org.apache.poi.ss.usermodel.Font#U_NONE}
+ */
+ @Deprecated
+ @Removal(version = "5.0.0")
+ public final static byte U_NONE = org.apache.poi.ss.usermodel.Font.U_NONE;
+ /**
+ * Underline type - Single
+ * @deprecated use {@link org.apache.poi.ss.usermodel.Font#U_SINGLE}
+ */
+ @Deprecated
+ @Removal(version = "5.0.0")
+ public final static byte U_SINGLE = org.apache.poi.ss.usermodel.Font.U_SINGLE;
+ /**
+ * Underline type - Double
+ * @deprecated use {@link org.apache.poi.ss.usermodel.Font#U_DOUBLE}
+ */
+ @Deprecated
+ @Removal(version = "5.0.0")
+ public final static byte U_DOUBLE = org.apache.poi.ss.usermodel.Font.U_DOUBLE;
+ /**
+ * Underline type - Single Accounting
+ * @deprecated use {@link org.apache.poi.ss.usermodel.Font#U_SINGLE_ACCOUNTING}
+ */
+ @Deprecated
+ @Removal(version = "5.0.0")
+ public final static byte U_SINGLE_ACCOUNTING = org.apache.poi.ss.usermodel.Font.U_SINGLE_ACCOUNTING;
+ /**
+ * Underline type - Double Accounting
+ * @deprecated use {@link org.apache.poi.ss.usermodel.Font#U_DOUBLE_ACCOUNTING}
+ */
+ @Deprecated
+ @Removal(version = "5.0.0")
+ public final static byte U_DOUBLE_ACCOUNTING = org.apache.poi.ss.usermodel.Font.U_DOUBLE_ACCOUNTING;
private final FontFormatting fontFormatting;
private final HSSFWorkbook workbook;
- protected HSSFFontFormatting(CFRuleBase cfRuleRecord, HSSFWorkbook workbook) {
+ HSSFFontFormatting(CFRuleBase cfRuleRecord, HSSFWorkbook workbook) {
this.fontFormatting = cfRuleRecord.getFontFormatting();
this.workbook = workbook;
}
- protected FontFormatting getFontFormattingBlock() {
+ FontFormatting getFontFormattingBlock() {
return fontFormatting;
}
@@ -53,9 +81,9 @@ public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.Fon
* get the type of super or subscript for the font
*
* @return super or subscript option
- * @see #SS_NONE
- * @see #SS_SUPER
- * @see #SS_SUB
+ * @see org.apache.poi.ss.usermodel.Font#SS_NONE
+ * @see org.apache.poi.ss.usermodel.Font#SS_SUPER
+ * @see org.apache.poi.ss.usermodel.Font#SS_SUB
*/
public short getEscapementType()
{
@@ -107,7 +135,7 @@ public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.Fon
/**
* @see org.apache.poi.hssf.record.cf.FontFormatting#getRawRecord()
*/
- protected byte[] getRawRecord() {
+ byte[] getRawRecord() {
return fontFormatting.getRawRecord();
}
@@ -116,11 +144,11 @@ public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.Fon
*
* @return font underlining type
*
- * @see #U_NONE
- * @see #U_SINGLE
- * @see #U_DOUBLE
- * @see #U_SINGLE_ACCOUNTING
- * @see #U_DOUBLE_ACCOUNTING
+ * @see org.apache.poi.ss.usermodel.Font#U_NONE
+ * @see org.apache.poi.ss.usermodel.Font#U_SINGLE
+ * @see org.apache.poi.ss.usermodel.Font#U_DOUBLE
+ * @see org.apache.poi.ss.usermodel.Font#U_SINGLE_ACCOUNTING
+ * @see org.apache.poi.ss.usermodel.Font#U_DOUBLE_ACCOUNTING
*/
public short getUnderlineType()
{
@@ -138,7 +166,7 @@ public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.Fon
}
/**
- * @return true if escapement type was modified from default
+ * @return true if escapement type was modified from default
*/
public boolean isEscapementTypeModified()
{
@@ -146,7 +174,7 @@ public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.Fon
}
/**
- * @return true if font cancellation was modified from default
+ * @return true if font cancellation was modified from default
*/
public boolean isFontCancellationModified()
{
@@ -154,7 +182,7 @@ public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.Fon
}
/**
- * @return true if font outline type was modified from default
+ * @return true if font outline type was modified from default
*/
public boolean isFontOutlineModified()
{
@@ -162,7 +190,7 @@ public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.Fon
}
/**
- * @return true if font shadow type was modified from default
+ * @return true if font shadow type was modified from default
*/
public boolean isFontShadowModified()
{
@@ -170,7 +198,7 @@ public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.Fon
}
/**
- * @return true if font style was modified from default
+ * @return true if font style was modified from default
*/
public boolean isFontStyleModified()
{
@@ -178,7 +206,7 @@ public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.Fon
}
/**
- * @return true if font style was set to <i>italic</i>
+ * @return true if font style was set to <i>italic</i>
*/
public boolean isItalic()
{
@@ -210,7 +238,7 @@ public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.Fon
}
/**
- * @return true if font underline type was modified from default
+ * @return true if font underline type was modified from default
*/
public boolean isUnderlineTypeModified()
{
@@ -218,7 +246,7 @@ public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.Fon
}
/**
- * @return true if font weight was modified from default
+ * @return true if font weight was modified from default
*/
public boolean isFontWeightModified()
{
@@ -227,8 +255,8 @@ public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.Fon
/**
* set font style options.
- *
- * @param italic - if true, set posture style to italic, otherwise to normal
+ *
+ * @param italic - if true, set posture style to italic, otherwise to normal
* @param bold if true, set font weight to bold, otherwise to normal
*/
@@ -253,18 +281,18 @@ public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.Fon
* set the escapement type for the font
*
* @param escapementType super or subscript option
- * @see #SS_NONE
- * @see #SS_SUPER
- * @see #SS_SUB
+ * @see org.apache.poi.ss.usermodel.Font#SS_NONE
+ * @see org.apache.poi.ss.usermodel.Font#SS_SUPER
+ * @see org.apache.poi.ss.usermodel.Font#SS_SUB
*/
public void setEscapementType(short escapementType) {
switch(escapementType) {
- case HSSFFontFormatting.SS_SUB:
- case HSSFFontFormatting.SS_SUPER:
+ case org.apache.poi.ss.usermodel.Font.SS_SUB:
+ case org.apache.poi.ss.usermodel.Font.SS_SUPER:
fontFormatting.setEscapementType(escapementType);
fontFormatting.setEscapementTypeModified(true);
break;
- case HSSFFontFormatting.SS_NONE:
+ case org.apache.poi.ss.usermodel.Font.SS_NONE:
fontFormatting.setEscapementType(escapementType);
fontFormatting.setEscapementTypeModified(false);
break;
@@ -273,7 +301,7 @@ public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.Fon
}
/**
- * @param modified
+ * @param modified flag, if escapement type is modified
* @see org.apache.poi.hssf.record.cf.FontFormatting#setEscapementTypeModified(boolean)
*/
public void setEscapementTypeModified(boolean modified) {
@@ -281,7 +309,7 @@ public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.Fon
}
/**
- * @param modified
+ * @param modified flag, if font cancellation is modified
* @see org.apache.poi.hssf.record.cf.FontFormatting#setFontCancellationModified(boolean)
*/
public void setFontCancellationModified(boolean modified)
@@ -290,7 +318,7 @@ public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.Fon
}
/**
- * @param fci
+ * @param fci the font color index
* @see org.apache.poi.hssf.record.cf.FontFormatting#setFontColorIndex(short)
*/
public void setFontColorIndex(short fci)
@@ -299,7 +327,7 @@ public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.Fon
}
/**
- * @param height
+ * @param height the font height
* @see org.apache.poi.hssf.record.cf.FontFormatting#setFontHeight(int)
*/
public void setFontHeight(int height)
@@ -308,7 +336,7 @@ public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.Fon
}
/**
- * @param modified
+ * @param modified flag, if font outline is modified
* @see org.apache.poi.hssf.record.cf.FontFormatting#setFontOutlineModified(boolean)
*/
public void setFontOutlineModified(boolean modified)
@@ -317,7 +345,7 @@ public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.Fon
}
/**
- * @param modified
+ * @param modified flag, if font shadow is modified
* @see org.apache.poi.hssf.record.cf.FontFormatting#setFontShadowModified(boolean)
*/
public void setFontShadowModified(boolean modified)
@@ -326,7 +354,7 @@ public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.Fon
}
/**
- * @param modified
+ * @param modified flag, if font style is modified
* @see org.apache.poi.hssf.record.cf.FontFormatting#setFontStyleModified(boolean)
*/
public void setFontStyleModified(boolean modified)
@@ -335,7 +363,7 @@ public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.Fon
}
/**
- * @param on
+ * @param on flag, if outline is set
* @see org.apache.poi.hssf.record.cf.FontFormatting#setOutline(boolean)
*/
public void setOutline(boolean on)
@@ -345,7 +373,7 @@ public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.Fon
}
/**
- * @param on
+ * @param on flag, if shadow is set
* @see org.apache.poi.hssf.record.cf.FontFormatting#setShadow(boolean)
*/
public void setShadow(boolean on)
@@ -355,7 +383,7 @@ public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.Fon
}
/**
- * @param strike
+ * @param strike flag, if strikeout is set
* @see org.apache.poi.hssf.record.cf.FontFormatting#setStrikeout(boolean)
*/
public void setStrikeout(boolean strike)
@@ -369,23 +397,23 @@ public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.Fon
*
* @param underlineType super or subscript option
*
- * @see #U_NONE
- * @see #U_SINGLE
- * @see #U_DOUBLE
- * @see #U_SINGLE_ACCOUNTING
- * @see #U_DOUBLE_ACCOUNTING
+ * @see org.apache.poi.ss.usermodel.Font#U_NONE
+ * @see org.apache.poi.ss.usermodel.Font#U_SINGLE
+ * @see org.apache.poi.ss.usermodel.Font#U_DOUBLE
+ * @see org.apache.poi.ss.usermodel.Font#U_SINGLE_ACCOUNTING
+ * @see org.apache.poi.ss.usermodel.Font#U_DOUBLE_ACCOUNTING
*/
public void setUnderlineType(short underlineType) {
switch(underlineType) {
- case HSSFFontFormatting.U_SINGLE:
- case HSSFFontFormatting.U_DOUBLE:
- case HSSFFontFormatting.U_SINGLE_ACCOUNTING:
- case HSSFFontFormatting.U_DOUBLE_ACCOUNTING:
+ case org.apache.poi.ss.usermodel.Font.U_SINGLE:
+ case org.apache.poi.ss.usermodel.Font.U_DOUBLE:
+ case org.apache.poi.ss.usermodel.Font.U_SINGLE_ACCOUNTING:
+ case org.apache.poi.ss.usermodel.Font.U_DOUBLE_ACCOUNTING:
fontFormatting.setUnderlineType(underlineType);
setUnderlineTypeModified(true);
break;
-
- case HSSFFontFormatting.U_NONE:
+
+ case org.apache.poi.ss.usermodel.Font.U_NONE:
fontFormatting.setUnderlineType(underlineType);
setUnderlineTypeModified(false);
break;
@@ -394,11 +422,10 @@ public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.Fon
}
/**
- * @param modified
+ * @param modified flag, if underline type is modified
* @see org.apache.poi.hssf.record.cf.FontFormatting#setUnderlineTypeModified(boolean)
*/
- public void setUnderlineTypeModified(boolean modified)
- {
+ public void setUnderlineTypeModified(boolean modified) {
fontFormatting.setUnderlineTypeModified(modified);
}
}
diff --git a/src/java/org/apache/poi/ss/formula/functions/Roman.java b/src/java/org/apache/poi/ss/formula/functions/Roman.java
index d73e322574..f822990dc3 100644
--- a/src/java/org/apache/poi/ss/formula/functions/Roman.java
+++ b/src/java/org/apache/poi/ss/formula/functions/Roman.java
@@ -24,32 +24,63 @@ import org.apache.poi.ss.formula.eval.StringEval;
import org.apache.poi.ss.formula.eval.ValueEval;
/**
- * Implementation for Excel WeekNum() function.<p>
+ * Implementation for Excel Roman() function.<p>
* <p>
- * <b>Syntax</b>:<br> <b>WeekNum </b>(<b>Serial_num</b>,<b>Return_type</b>)<br>
+ * <b>Syntax</b>:<br> <b>Roman </b>(<b>number</b>,<b>form</b>)<br>
* <p>
- * Returns a number that indicates where the week falls numerically within a year.
+ * Converts an arabic numeral to roman, as text.
* <p>
* <p>
- * Serial_num is a date within the week. Dates should be entered by using the DATE function,
- * or as results of other formulas or functions. For example, use DATE(2008,5,23)
- * for the 23rd day of May, 2008. Problems can occur if dates are entered as text.
- * Return_type is a number that determines on which day the week begins. The default is 1.
- * 1 Week begins on Sunday. Weekdays are numbered 1 through 7.
- * 2 Week begins on Monday. Weekdays are numbered 1 through 7.
- *
- * @author cedric dot walter @ gmail dot com
+ * Number Required. The Arabic numeral you want converted.<p>
+ * Form Optional. A number specifying the type of roman numeral you want.
+ * The roman numeral style ranges from Classic to Simplified, becoming more concise as the value of form increases.
+ * <p>
+ * Return_type a roman numeral, as text
*/
public class Roman extends Fixed2ArgFunction {
//M (1000), CM (900), D (500), CD (400), C (100), XC (90), L (50), XL (40), X (10), IX (9), V (5), IV (4) and I (1).
- public static final int[] VALUES = new int[]{1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
- public static final String[] ROMAN = new String[]
- {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
+ private static final int[] VALUES = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
+
+ private static final String[] ROMAN = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
+
+ private static final String[][] REPLACEMENTS = {
+ { // form > 0
+ "XLV", "VL", // 45
+ "XCV", "VC", // 95
+ "CDL", "LD", // 450
+ "CML", "LM", // 950
+ "CMVC", "LMVL" // 995
+ },{ // Form == 1 only
+ "CDXC", "LDXL", // 490
+ "CDVC", "LDVL", // 495
+ "CMXC", "LMXL", // 990
+ "XCIX", "VCIV", // 99
+ "XLIX", "VLIV" // 49
+ },{ // form > 1
+ "XLIX", "IL", // 49
+ "XCIX", "IC", // 99
+ "CDXC", "XD", // 490
+ "CDVC", "XDV", // 495
+ "CDIC", "XDIX", // 499
+ "LMVL", "XMV", // 995
+ "CMIC", "XMIX", // 999
+ "CMXC", "XM" // 990
+ },{ // form > 2
+ "XDV", "VD", // 495
+ "XDIX", "VDIV", // 499
+ "XMV", "VM", // 995
+ "XMIX", "VMIV" // 999
+ },{ // form == 4
+ "VDIV", "ID", // 499
+ "VMIV", "IM" // 999
+ }
+ };
+
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval numberVE, ValueEval formVE) {
- int number = 0;
+ final int number;
try {
ValueEval ve = OperandResolver.getSingleValue(numberVE, srcRowIndex, srcColumnIndex);
number = OperandResolver.coerceValueToInt(ve);
@@ -66,7 +97,7 @@ public class Roman extends Fixed2ArgFunction {
return new StringEval("");
}
- int form = 0;
+ final int form;
try {
ValueEval ve = OperandResolver.getSingleValue(formVE, srcRowIndex, srcColumnIndex);
form = OperandResolver.coerceValueToInt(ve);
@@ -90,7 +121,7 @@ public class Roman extends Fixed2ArgFunction {
/**
* Classic conversion.
*
- * @param number
+ * @param number the number
*/
private String integerToRoman(int number) {
StringBuilder result = new StringBuilder();
@@ -106,45 +137,21 @@ public class Roman extends Fixed2ArgFunction {
/**
* Use conversion rule to factor some parts and make them more concise
*
- * @param result
- * @param form
+ * @param input the input string
+ * @param form the level of conciseness [0..4] with 4 being most concise and simplified
*/
- public String makeConcise(String result, int form) {
- if (form > 0) {
- result = result.replaceAll("XLV", "VL"); //45
- result = result.replaceAll("XCV", "VC"); //95
- result = result.replaceAll("CDL", "LD"); //450
- result = result.replaceAll("CML", "LM"); //950
- result = result.replaceAll("CMVC", "LMVL"); //995
- }
- if (form == 1) {
- result = result.replaceAll("CDXC", "LDXL"); //490
- result = result.replaceAll("CDVC", "LDVL"); //495
- result = result.replaceAll("CMXC", "LMXL"); //990
- result = result.replaceAll("XCIX", "VCIV"); //99
- result = result.replaceAll("XLIX", "VLIV"); //49
- }
- if (form > 1) {
- result = result.replaceAll("XLIX", "IL"); //49
- result = result.replaceAll("XCIX", "IC"); //99
- result = result.replaceAll("CDXC", "XD"); //490
- result = result.replaceAll("CDVC", "XDV"); //495
- result = result.replaceAll("CDIC", "XDIX"); //499
- result = result.replaceAll("LMVL", "XMV"); //995
- result = result.replaceAll("CMIC", "XMIX"); //999
- result = result.replaceAll("CMXC", "XM"); // 990
- }
- if (form > 2) {
- result = result.replaceAll("XDV", "VD"); //495
- result = result.replaceAll("XDIX", "VDIV"); //499
- result = result.replaceAll("XMV", "VM"); // 995
- result = result.replaceAll("XMIX", "VMIV"); //999
- }
- if (form == 4) {
- result = result.replaceAll("VDIV", "ID"); //499
- result = result.replaceAll("VMIV", "IM"); //999
+ public String makeConcise(final String input, final int form) {
+ String result = input;
+ for (int i=0; i<=form && i<=4 && form > 0; i++) {
+ if (i==1 && form>1) {
+ // Replacement[1] is only meant for form == 1
+ continue;
+ }
+ String[] repl = REPLACEMENTS[i];
+ for (int j=0; j<repl.length; j+=2) {
+ result = result.replace(repl[j],repl[j+1]);
+ }
}
-
return result;
}
}
diff --git a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
index 19c0afaa7c..12b3412bdd 100644
--- a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
+++ b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
@@ -118,6 +118,7 @@ import org.apache.poi.util.POILogger;
* You can use {@link DateFormatConverter} to do some of this localisation if
* you need it.
*/
+@SuppressWarnings("unused")
public class DataFormatter implements Observer {
private static final String defaultFractionWholePartFormat = "#";
private static final String defaultFractionFractionPartFormat = "#/##";
@@ -342,13 +343,11 @@ public class DataFormatter implements Observer {
// Ask CellFormat to get a formatter for it
CellFormat cfmt = CellFormat.getInstance(locale, formatStr);
// CellFormat requires callers to identify date vs not, so do so
- Object cellValueO = Double.valueOf(cellValue);
- if (DateUtil.isADateFormat(formatIndex, formatStr) &&
- // don't try to handle Date value 0, let a 3 or 4-part format take care of it
- ((Double)cellValueO).doubleValue() != 0.0) {
- cellValueO = DateUtil.getJavaDate(cellValue, use1904Windowing);
- }
- // Wrap and return (non-cachable - CellFormat does that)
+ // don't try to handle Date value 0, let a 3 or 4-part format take care of it
+ Object cellValueO = (cellValue != 0.0 && DateUtil.isADateFormat(formatIndex, formatStr))
+ ? DateUtil.getJavaDate(cellValue, use1904Windowing)
+ : cellValue;
+ // Wrap and return (non-cacheable - CellFormat does that)
return new CellFormatResultWrapper( cfmt.apply(cellValueO) );
} catch (Exception e) {
logger.log(POILogger.WARN, "Formatting failed for format " + formatStr + ", falling back", e);
@@ -357,7 +356,7 @@ public class DataFormatter implements Observer {
// Excel's # with value 0 will output empty where Java will output 0. This hack removes the # from the format.
if (emulateCSV && cellValue == 0.0 && formatStr.contains("#") && !formatStr.contains("0")) {
- formatStr = formatStr.replaceAll("#", "");
+ formatStr = formatStr.replace("#", "");
}
// See if we already have it cached
@@ -397,38 +396,42 @@ public class DataFormatter implements Observer {
String formatStr = sFormat;
// Remove colour formatting if present
- Matcher colourM = colorPattern.matcher(formatStr);
- while(colourM.find()) {
- String colour = colourM.group();
-
- // Paranoid replacement...
- int at = formatStr.indexOf(colour);
- if(at == -1) break;
- String nFormatStr = formatStr.substring(0,at) +
- formatStr.substring(at+colour.length());
- if(nFormatStr.equals(formatStr)) break;
-
- // Try again in case there's multiple
- formatStr = nFormatStr;
- colourM = colorPattern.matcher(formatStr);
+ if (formatStr != null) {
+ Matcher colourM = colorPattern.matcher(formatStr);
+ while (colourM.find()) {
+ String colour = colourM.group();
+
+ // Paranoid replacement...
+ int at = formatStr.indexOf(colour);
+ if (at == -1) break;
+ String nFormatStr = formatStr.substring(0, at) +
+ formatStr.substring(at + colour.length());
+ if (nFormatStr.equals(formatStr)) break;
+
+ // Try again in case there's multiple
+ formatStr = nFormatStr;
+ colourM = colorPattern.matcher(formatStr);
+ }
}
// Strip off the locale information, we use an instance-wide locale for everything
- Matcher m = localePatternGroup.matcher(formatStr);
- while(m.find()) {
- String match = m.group();
- String symbol = match.substring(match.indexOf('$') + 1, match.indexOf('-'));
- if (symbol.indexOf('$') > -1) {
- symbol = symbol.substring(0, symbol.indexOf('$')) +
- '\\' +
- symbol.substring(symbol.indexOf('$'));
+ if (formatStr != null) {
+ Matcher m = localePatternGroup.matcher(formatStr);
+ while (m.find()) {
+ String match = m.group();
+ String symbol = match.substring(match.indexOf('$') + 1, match.indexOf('-'));
+ if (symbol.indexOf('$') > -1) {
+ symbol = symbol.substring(0, symbol.indexOf('$')) +
+ '\\' +
+ symbol.substring(symbol.indexOf('$'));
+ }
+ formatStr = m.replaceAll(symbol);
+ m = localePatternGroup.matcher(formatStr);
}
- formatStr = m.replaceAll(symbol);
- m = localePatternGroup.matcher(formatStr);
}
// Check for special cases
- if(formatStr == null || formatStr.trim().length() == 0) {
+ if(formatStr == null || formatStr.trim().isEmpty()) {
return getDefaultFormat(cellValue);
}
@@ -476,15 +479,15 @@ public class DataFormatter implements Observer {
private Format createDateFormat(String pFormatStr, double cellValue) {
String formatStr = pFormatStr;
- formatStr = formatStr.replaceAll("\\\\-","-");
- formatStr = formatStr.replaceAll("\\\\,",",");
- formatStr = formatStr.replaceAll("\\\\\\.","."); // . is a special regexp char
- formatStr = formatStr.replaceAll("\\\\ "," ");
- formatStr = formatStr.replaceAll("\\\\/","/"); // weird: m\\/d\\/yyyy
- formatStr = formatStr.replaceAll(";@", "");
- formatStr = formatStr.replaceAll("\"/\"", "/"); // "/" is escaped for no reason in: mm"/"dd"/"yyyy
+ formatStr = formatStr.replace("\\-","-");
+ formatStr = formatStr.replace("\\,",",");
+ formatStr = formatStr.replace("\\.","."); // . is a special regexp char
+ formatStr = formatStr.replace("\\ "," ");
+ formatStr = formatStr.replace("\\/","/"); // weird: m\\/d\\/yyyy
+ formatStr = formatStr.replace(";@", "");
+ formatStr = formatStr.replace("\"/\"", "/"); // "/" is escaped for no reason in: mm"/"dd"/"yyyy
formatStr = formatStr.replace("\"\"", "'"); // replace Excel quoting with Java style quoting
- formatStr = formatStr.replaceAll("\\\\T","'T'"); // Quote the T is iso8601 style dates
+ formatStr = formatStr.replace("\\T","'T'"); // Quote the T is iso8601 style dates
boolean hasAmPm = false;
@@ -494,12 +497,12 @@ public class DataFormatter implements Observer {
hasAmPm = true;
amPmMatcher = amPmPattern.matcher(formatStr);
}
- formatStr = formatStr.replaceAll("@", "a");
+ formatStr = formatStr.replace('@', 'a');
Matcher dateMatcher = daysAsText.matcher(formatStr);
if (dateMatcher.find()) {
- String match = dateMatcher.group(0).toUpperCase(Locale.ROOT).replaceAll("D", "E");
+ String match = dateMatcher.group(0).toUpperCase(Locale.ROOT).replace('D', 'E');
formatStr = dateMatcher.replaceAll(match);
}
@@ -567,9 +570,7 @@ public class DataFormatter implements Observer {
else if (c == 'm' || c == 'M') {
if(mIsMonth) {
sb.append('M');
- ms.add(
- Integer.valueOf(sb.length() -1)
- );
+ ms.add(sb.length() - 1);
} else {
sb.append('m');
}
@@ -801,6 +802,7 @@ public class DataFormatter implements Observer {
* Performs Excel-style date formatting, using the
* supplied Date and format
*/
+ @SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
private String performDateFormatting(Date d, Format dateFormat) {
Format df = dateFormat != null ? dateFormat : defaultDateformat;
synchronized (df) {
@@ -821,6 +823,7 @@ public class DataFormatter implements Observer {
* @param cfEvaluator ConditionalFormattingEvaluator (if available)
* @return Formatted value
*/
+ @SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
private String getFormattedDateString(Cell cell, ConditionalFormattingEvaluator cfEvaluator) {
if (cell == null) {
return null;
@@ -870,7 +873,7 @@ public class DataFormatter implements Observer {
if (numberFormat == null) {
return String.valueOf(d);
}
- String formatted = numberFormat.format(Double.valueOf(d));
+ String formatted = numberFormat.format(d);
return formatted.replaceFirst("E(\\d)", "E+$1"); // to match Excel's E-notation
}
@@ -921,7 +924,7 @@ public class DataFormatter implements Observer {
String result;
final String textValue = NumberToTextConverter.toText(value);
if (textValue.indexOf('E') > -1) {
- result = numberFormat.format(Double.valueOf(value));
+ result = numberFormat.format(value);
}
else {
result = numberFormat.format(new BigDecimal(textValue));
diff --git a/src/java/org/apache/poi/ss/usermodel/ExcelStyleDateFormatter.java b/src/java/org/apache/poi/ss/usermodel/ExcelStyleDateFormatter.java
index c5684b1c4d..fcaed994d5 100644
--- a/src/java/org/apache/poi/ss/usermodel/ExcelStyleDateFormatter.java
+++ b/src/java/org/apache/poi/ss/usermodel/ExcelStyleDateFormatter.java
@@ -91,13 +91,13 @@ public class ExcelStyleDateFormatter extends SimpleDateFormat {
* with our detection sequences
*/
private static String processFormatPattern(String f) {
- String t = f.replaceAll("MMMMM", MMMMM_START_SYMBOL + "MMM" + MMMMM_TRUNCATE_SYMBOL);
- t = t.replaceAll("\\[H]", String.valueOf(H_BRACKET_SYMBOL));
- t = t.replaceAll("\\[HH]", String.valueOf(HH_BRACKET_SYMBOL));
- t = t.replaceAll("\\[m]", String.valueOf(M_BRACKET_SYMBOL));
- t = t.replaceAll("\\[mm]", String.valueOf(MM_BRACKET_SYMBOL));
- t = t.replaceAll("\\[s]", String.valueOf(S_BRACKET_SYMBOL));
- t = t.replaceAll("\\[ss]", String.valueOf(SS_BRACKET_SYMBOL));
+ String t = f.replace("MMMMM", MMMMM_START_SYMBOL + "MMM" + MMMMM_TRUNCATE_SYMBOL);
+ t = t.replace("[H]", String.valueOf(H_BRACKET_SYMBOL));
+ t = t.replace("[HH]", String.valueOf(HH_BRACKET_SYMBOL));
+ t = t.replace("[m]", String.valueOf(M_BRACKET_SYMBOL));
+ t = t.replace("[mm]", String.valueOf(MM_BRACKET_SYMBOL));
+ t = t.replace("[s]", String.valueOf(S_BRACKET_SYMBOL));
+ t = t.replace("[ss]", String.valueOf(SS_BRACKET_SYMBOL));
t = t.replaceAll("s.000", "s.SSS");
t = t.replaceAll("s.00", "s." + LL_BRACKET_SYMBOL);
t = t.replaceAll("s.0", "s." + L_BRACKET_SYMBOL);
diff --git a/src/java/org/apache/poi/ss/usermodel/Font.java b/src/java/org/apache/poi/ss/usermodel/Font.java
index e7abe58288..4e95fb2751 100644
--- a/src/java/org/apache/poi/ss/usermodel/Font.java
+++ b/src/java/org/apache/poi/ss/usermodel/Font.java
@@ -21,65 +21,57 @@ package org.apache.poi.ss.usermodel;
import org.apache.poi.util.Removal;
public interface Font {
+ // TODO: refactor and unify Font & FontFormatting in POI 5.0.0
+ // TODO: refactor the constants to enums in POI 5.0.0
/**
* normal type of black color.
*/
-
short COLOR_NORMAL = 0x7fff;
/**
* Dark Red color
*/
-
short COLOR_RED = 0xa;
/**
* no type offsetting (not super or subscript)
*/
-
short SS_NONE = 0;
/**
* superscript
*/
-
short SS_SUPER = 1;
/**
* subscript
*/
-
short SS_SUB = 2;
/**
* not underlined
*/
-
byte U_NONE = 0;
/**
* single (normal) underline
*/
-
byte U_SINGLE = 1;
/**
* double underlined
*/
-
byte U_DOUBLE = 2;
/**
* accounting style single underline
*/
-
byte U_SINGLE_ACCOUNTING = 0x21;
/**
* accounting style double underline
*/
-
byte U_DOUBLE_ACCOUNTING = 0x22;
/**
diff --git a/src/java/org/apache/poi/ss/usermodel/FontFormatting.java b/src/java/org/apache/poi/ss/usermodel/FontFormatting.java
index 79c5e4f845..ca7335aac5 100644
--- a/src/java/org/apache/poi/ss/usermodel/FontFormatting.java
+++ b/src/java/org/apache/poi/ss/usermodel/FontFormatting.java
@@ -19,36 +19,88 @@
package org.apache.poi.ss.usermodel;
+import org.apache.poi.util.Removal;
+
/**
* High level representation for Font Formatting component
* of Conditional Formatting settings
*/
public interface FontFormatting {
- /** Escapement type - None */
- public final static short SS_NONE = 0;
- /** Escapement type - Superscript */
- public final static short SS_SUPER = 1;
- /** Escapement type - Subscript */
- public final static short SS_SUB = 2;
-
- /** Underline type - None */
- public final static byte U_NONE = 0;
- /** Underline type - Single */
- public final static byte U_SINGLE = 1;
- /** Underline type - Double */
- public final static byte U_DOUBLE = 2;
- /** Underline type - Single Accounting */
- public final static byte U_SINGLE_ACCOUNTING = 0x21;
- /** Underline type - Double Accounting */
- public final static byte U_DOUBLE_ACCOUNTING = 0x22;
+ // TODO: refactor and unify Font & FontFormatting in POI 5.0.0
+
+ /**
+ * Escapement type - None
+ *
+ * @deprecated use {@link Font#SS_NONE} instead
+ */
+ @Deprecated
+ @Removal(version = "5.0.0")
+ short SS_NONE = 0;
+ /**
+ * Escapement type - Superscript
+ *
+ * @deprecated use {@link Font#SS_SUPER} instead
+ */
+ @Deprecated
+ @Removal(version = "5.0.0")
+ short SS_SUPER = 1;
+ /**
+ * Escapement type - Subscript
+ *
+ * @deprecated use {@link Font#SS_SUB} instead
+ */
+ @Deprecated
+ @Removal(version = "5.0.0")
+ short SS_SUB = 2;
+
+ /**
+ * Underline type - None
+ *
+ * @deprecated use {@link Font#U_NONE} instead
+ */
+ @Deprecated
+ @Removal(version = "5.0.0")
+ byte U_NONE = 0;
+ /**
+ * Underline type - Single
+ *
+ * @deprecated use {@link Font#U_SINGLE} instead
+ */
+ @Deprecated
+ @Removal(version = "5.0.0")
+ byte U_SINGLE = 1;
+ /**
+ * Underline type - Double
+ *
+ * @deprecated use {@link Font#U_DOUBLE} instead
+ */
+ @Deprecated
+ @Removal(version = "5.0.0")
+ byte U_DOUBLE = 2;
+ /**
+ * Underline type - Single Accounting
+ *
+ * @deprecated use {@link Font#U_SINGLE_ACCOUNTING} instead
+ */
+ @Deprecated
+ @Removal(version = "5.0.0")
+ byte U_SINGLE_ACCOUNTING = 0x21;
+ /**
+ * Underline type - Double Accounting
+ *
+ * @deprecated use {@link Font#U_DOUBLE_ACCOUNTING} instead
+ */
+ @Deprecated
+ @Removal(version = "5.0.0")
+ byte U_DOUBLE_ACCOUNTING = 0x22;
/**
* get the type of super or subscript for the font
*
* @return super or subscript option
- * @see #SS_NONE
- * @see #SS_SUPER
- * @see #SS_SUB
+ * @see Font#SS_NONE
+ * @see Font#SS_SUPER
+ * @see Font#SS_SUB
*/
short getEscapementType();
@@ -56,9 +108,9 @@ public interface FontFormatting {
* set the escapement type for the font
*
* @param escapementType super or subscript option
- * @see #SS_NONE
- * @see #SS_SUPER
- * @see #SS_SUB
+ * @see Font#SS_NONE
+ * @see Font#SS_SUPER
+ * @see Font#SS_SUB
*/
void setEscapementType(short escapementType);
@@ -72,12 +124,12 @@ public interface FontFormatting {
* @param color font colour index
*/
void setFontColorIndex(short color);
-
+
/**
* @return The colour of the font, or null if no colour applied
*/
Color getFontColor();
-
+
/**
* Sets the colour to use
* @param color font colour to use
@@ -103,11 +155,11 @@ public interface FontFormatting {
*
* @return font underlining type
*
- * @see #U_NONE
- * @see #U_SINGLE
- * @see #U_DOUBLE
- * @see #U_SINGLE_ACCOUNTING
- * @see #U_DOUBLE_ACCOUNTING
+ * @see Font#U_NONE
+ * @see Font#U_SINGLE
+ * @see Font#U_DOUBLE
+ * @see Font#U_SINGLE_ACCOUNTING
+ * @see Font#U_DOUBLE_ACCOUNTING
*/
short getUnderlineType();
@@ -116,11 +168,11 @@ public interface FontFormatting {
*
* @param underlineType super or subscript option
*
- * @see #U_NONE
- * @see #U_SINGLE
- * @see #U_DOUBLE
- * @see #U_SINGLE_ACCOUNTING
- * @see #U_DOUBLE_ACCOUNTING
+ * @see Font#U_NONE
+ * @see Font#U_SINGLE
+ * @see Font#U_DOUBLE
+ * @see Font#U_SINGLE_ACCOUNTING
+ * @see Font#U_DOUBLE_ACCOUNTING
*/
void setUnderlineType(short underlineType);
diff --git a/src/java/org/apache/poi/ss/util/DateFormatConverter.java b/src/java/org/apache/poi/ss/util/DateFormatConverter.java
index 9a49da3b67..6c044de6c7 100644
--- a/src/java/org/apache/poi/ss/util/DateFormatConverter.java
+++ b/src/java/org/apache/poi/ss/util/DateFormatConverter.java
@@ -173,7 +173,7 @@ public final class DateFormatConverter {
String token;
while( ( token = tokenizer.getNextToken() ) != null ) {
if( token.startsWith("'") ) {
- result.append( token.replaceAll("'", "\"") );
+ result.append( token.replace('\'', '"') );
} else if( ! Character.isLetter( token.charAt( 0 ) ) ) {
result.append( token );
} else {