diff options
author | Dominik Stadler <centic@apache.org> | 2016-12-30 22:11:48 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2016-12-30 22:11:48 +0000 |
commit | 9dfbbdb480997156f1b30353c9a2f34537924269 (patch) | |
tree | 1e81432e570809663b114160004f8f15065ae44a /src | |
parent | bce3c31ea2770a54d4cd2933f47fcc02109e9f5e (diff) | |
download | poi-9dfbbdb480997156f1b30353c9a2f34537924269.tar.gz poi-9dfbbdb480997156f1b30353c9a2f34537924269.zip |
Fix some compilation warnings
Update Javadoc
Reformat code somewhat
Supress IntelliJ warnings in findbugs-filters.xml
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1776645 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
5 files changed, 92 insertions, 83 deletions
diff --git a/src/java/org/apache/poi/hssf/record/FormulaRecord.java b/src/java/org/apache/poi/hssf/record/FormulaRecord.java index 4eae6ce5c2..0ef07d470f 100644 --- a/src/java/org/apache/poi/hssf/record/FormulaRecord.java +++ b/src/java/org/apache/poi/hssf/record/FormulaRecord.java @@ -21,11 +21,7 @@ import org.apache.poi.ss.formula.Formula; import org.apache.poi.ss.formula.eval.ErrorEval; import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.ss.usermodel.CellType; -import org.apache.poi.util.BitField; -import org.apache.poi.util.BitFieldFactory; -import org.apache.poi.util.HexDump; -import org.apache.poi.util.LittleEndianInput; -import org.apache.poi.util.LittleEndianOutput; +import org.apache.poi.util.*; /** * Formula Record (0x0006). @@ -65,6 +61,7 @@ public final class FormulaRecord extends CellRecord implements Cloneable { private SpecialCachedValue(byte[] data) { _variableData = data; } + public int getTypeCode() { return _variableData[0]; } @@ -91,42 +88,55 @@ public final class FormulaRecord extends CellRecord implements Cloneable { case EMPTY: break; default: - throw new RecordFormatException("Bad special value code (" + result[0] + ")"); + throw new org.apache.poi.util.RecordFormatException("Bad special value code (" + result[0] + ")"); } return new SpecialCachedValue(result); } + public void serialize(LittleEndianOutput out) { out.write(_variableData); out.writeShort(0xFFFF); } + public String formatDebugString() { return formatValue() + ' ' + HexDump.toHex(_variableData); } + private String formatValue() { int typeCode = getTypeCode(); switch (typeCode) { - case STRING: return "<string>"; - case BOOLEAN: return getDataValue() == 0 ? "FALSE" : "TRUE"; - case ERROR_CODE: return ErrorEval.getText(getDataValue()); - case EMPTY: return "<empty>"; + case STRING: + return "<string>"; + case BOOLEAN: + return getDataValue() == 0 ? "FALSE" : "TRUE"; + case ERROR_CODE: + return ErrorEval.getText(getDataValue()); + case EMPTY: + return "<empty>"; } return "#error(type=" + typeCode + ")#"; } + private int getDataValue() { return _variableData[DATA_INDEX]; } + public static SpecialCachedValue createCachedEmptyValue() { return create(EMPTY, 0); } + public static SpecialCachedValue createForString() { return create(STRING, 0); } + public static SpecialCachedValue createCachedBoolean(boolean b) { return create(BOOLEAN, b ? 1 : 0); } + public static SpecialCachedValue createCachedErrorCode(int errorCode) { return create(ERROR_CODE, errorCode); } + private static SpecialCachedValue create(int code, int data) { byte[] vd = { (byte) code, @@ -138,13 +148,12 @@ public final class FormulaRecord extends CellRecord implements Cloneable { }; return new SpecialCachedValue(vd); } + @Override public String toString() { - StringBuffer sb = new StringBuffer(64); - sb.append(getClass().getName()); - sb.append('[').append(formatValue()).append(']'); - return sb.toString(); + return getClass().getName() + '[' + formatValue() + ']'; } + public int getValueType() { int typeCode = getTypeCode(); switch (typeCode) { @@ -155,12 +164,14 @@ public final class FormulaRecord extends CellRecord implements Cloneable { } throw new IllegalStateException("Unexpected type id (" + typeCode + ")"); } + public boolean getBooleanValue() { if (getTypeCode() != BOOLEAN) { throw new IllegalStateException("Not a boolean cached value - " + formatValue()); } return getDataValue() != 0; } + public int getErrorValue() { if (getTypeCode() != ERROR_CODE) { throw new IllegalStateException("Not an error cached value - " + formatValue()); @@ -192,19 +203,18 @@ public final class FormulaRecord extends CellRecord implements Cloneable { public FormulaRecord(RecordInputStream ris) { super(ris); - LittleEndianInput in = ris; - long valueLongBits = in.readLong(); - field_5_options = in.readShort(); + long valueLongBits = ris.readLong(); + field_5_options = ris.readShort(); specialCachedValue = SpecialCachedValue.create(valueLongBits); if (specialCachedValue == null) { field_4_value = Double.longBitsToDouble(valueLongBits); } - field_6_zero = in.readInt(); + field_6_zero = ris.readInt(); - int field_7_expression_len = in.readShort(); // this length does not include any extra array data - int nBytesAvailable = in.available(); - field_8_parsed_expr = Formula.read(field_7_expression_len, in, nBytesAvailable); + int field_7_expression_len = ris.readShort(); // this length does not include any extra array data + int nBytesAvailable = ris.available(); + field_8_parsed_expr = Formula.read(field_7_expression_len, ris, nBytesAvailable); } /** @@ -235,10 +245,8 @@ public final class FormulaRecord extends CellRecord implements Cloneable { * evaluation. */ public boolean hasCachedResultString() { - if (specialCachedValue == null) { - return false; - } - return specialCachedValue.getTypeCode() == SpecialCachedValue.STRING; + return specialCachedValue != null && + specialCachedValue.getTypeCode() == SpecialCachedValue.STRING; } public int getCachedResultType() { diff --git a/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java b/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java index 65c22d7817..b1fbd9b067 100644 --- a/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java +++ b/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java @@ -62,7 +62,7 @@ public class DrawTextParagraph implements Drawable { protected List<DrawTextFragment> lines = new ArrayList<DrawTextFragment>();
protected String rawText;
protected DrawTextFragment bullet;
- protected int autoNbrIdx = 0;
+ protected int autoNbrIdx;
/**
* the highest line in this paragraph. Used for line spacing.
@@ -226,7 +226,7 @@ public class DrawTextParagraph implements Drawable { /**
* break text into lines, each representing a line of text that fits in the wrapping width
*
- * @param graphics
+ * @param graphics The drawing context for computing text-lengths.
*/
protected void breakText(Graphics2D graphics){
lines.clear();
@@ -479,7 +479,7 @@ public class DrawTextParagraph implements Drawable { */
@SuppressWarnings("rawtypes")
private PlaceableShape<?,?> getParagraphShape() {
- PlaceableShape<?,?> ps = new PlaceableShape(){
+ return new PlaceableShape(){
public ShapeContainer<?,?> getParent() { return null; }
public Rectangle2D getAnchor() { return paragraph.getParentShape().getAnchor(); }
public void setAnchor(Rectangle2D anchor) {}
@@ -491,7 +491,6 @@ public class DrawTextParagraph implements Drawable { public boolean getFlipVertical() { return false; }
public Sheet<?,?> getSheet() { return paragraph.getParentShape().getSheet(); }
};
- return ps;
}
protected AttributedString getAttributedString(Graphics2D graphics, StringBuilder text){
@@ -633,7 +632,7 @@ public class DrawTextParagraph implements Drawable { return string;
}
-
+
protected boolean isHSLF() {
return paragraph.getClass().getName().contains("HSLF");
}
diff --git a/src/ooxml/java/org/apache/poi/util/DocumentHelper.java b/src/ooxml/java/org/apache/poi/util/DocumentHelper.java index 1ec47953ab..f86e60fd90 100644 --- a/src/ooxml/java/org/apache/poi/util/DocumentHelper.java +++ b/src/ooxml/java/org/apache/poi/util/DocumentHelper.java @@ -78,6 +78,9 @@ public final class DocumentHelper { /** * Creates a new document builder, with sensible defaults + * + * @throws IllegalStateException If creating the DocumentBuilder fails, e.g. + * due to {@link ParserConfigurationException}. */ public static synchronized DocumentBuilder newDocumentBuilder() { try { diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java index 5bc1ece94e..e3f51e774d 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java @@ -31,21 +31,19 @@ import org.apache.poi.util.IOUtils; /** * Raw picture data, normally attached to a WordprocessingML Drawing. * As a rule, pictures are stored in the /word/media/ part of a WordprocessingML package. - */ - -/** + * * @author Philipp Epp */ public class XWPFPictureData extends POIXMLDocumentPart { /** - * Relationships for each known picture type
- */
- protected static final POIXMLRelation[] RELATIONS;
-
- static {
- RELATIONS = new POIXMLRelation[13];
- RELATIONS[Document.PICTURE_TYPE_EMF] = XWPFRelation.IMAGE_EMF;
+ * Relationships for each known picture type + */ + protected static final POIXMLRelation[] RELATIONS; + + static { + RELATIONS = new POIXMLRelation[13]; + RELATIONS[Document.PICTURE_TYPE_EMF] = XWPFRelation.IMAGE_EMF; RELATIONS[Document.PICTURE_TYPE_WMF] = XWPFRelation.IMAGE_WMF; RELATIONS[Document.PICTURE_TYPE_PICT] = XWPFRelation.IMAGE_PICT; RELATIONS[Document.PICTURE_TYPE_JPEG] = XWPFRelation.IMAGE_JPEG; @@ -58,13 +56,13 @@ public class XWPFPictureData extends POIXMLDocumentPart { RELATIONS[Document.PICTURE_TYPE_WPG] = XWPFRelation.IMAGE_WPG; } - private Long checksum = null; -
- /**
- * Create a new XWPFGraphicData node
- */
- protected XWPFPictureData() {
- super();
+ private Long checksum; + + /** + * Create a new XWPFGraphicData node + */ + protected XWPFPictureData() { + super(); } /** @@ -90,13 +88,13 @@ public class XWPFPictureData extends POIXMLDocumentPart { * You can grab the picture data directly from the underlying package part as follows: * <br/> * <code> - * InputStream is = getPackagePart().getInputStream();
- * </code>
- * </p>
- *
- * @return the Picture data.
- */
- public byte[] getData() {
+ * InputStream is = getPackagePart().getInputStream(); + * </code> + * </p> + * + * @return the Picture data. + */ + public byte[] getData() { try { return IOUtils.toByteArray(getPackagePart().getInputStream()); } catch (IOException e) { @@ -113,22 +111,22 @@ public class XWPFPictureData extends POIXMLDocumentPart { String name = getPackagePart().getPartName().getName(); return name.substring(name.lastIndexOf('/') + 1); } -
- /**
- * Suggests a file extension for this image.
- *
- * @return the file extension.
- */
- public String suggestFileExtension() {
+ + /** + * Suggests a file extension for this image. + * + * @return the file extension. + */ + public String suggestFileExtension() { return getPackagePart().getPartName().getExtension(); } -
- /**
- * Return an integer constant that specifies type of this picture
- *
- * @return an integer constant that specifies type of this picture
- * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_EMF
- * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_WMF
+ + /** + * Return an integer constant that specifies type of this picture + * + * @return an integer constant that specifies type of this picture + * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_EMF + * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_WMF * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_PICT * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_JPEG * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_PNG @@ -171,7 +169,7 @@ public class XWPFPictureData extends POIXMLDocumentPart { @Override public boolean equals(Object obj) { - /** + /* * In case two objects ARE equal, but its not the same instance, this * implementation will always run through the whole * byte-array-comparison before returning true. If this will turn into a @@ -216,13 +214,13 @@ public class XWPFPictureData extends POIXMLDocumentPart { if (!ownPackage.equals(foreignPackage)) { return false; - }
- }
- }
-
- Long foreignChecksum = picData.getChecksum();
- Long localChecksum = getChecksum();
-
+ } + } + } + + Long foreignChecksum = picData.getChecksum(); + Long localChecksum = getChecksum(); + if (!(localChecksum.equals(foreignChecksum))) { return false; } @@ -232,13 +230,13 @@ public class XWPFPictureData extends POIXMLDocumentPart { @Override public int hashCode() { return getChecksum().hashCode(); - }
-
- /**
- * *PictureData objects store the actual content in the part directly without keeping a
- * copy like all others therefore we need to handle them differently.
- */
- @Override
+ } + + /** + * *PictureData objects store the actual content in the part directly without keeping a + * copy like all others therefore we need to handle them differently. + */ + @Override protected void prepareForCommit() { // do not clear the part here } diff --git a/src/resources/devtools/findbugs-filters.xml b/src/resources/devtools/findbugs-filters.xml index 98c2ffb1cd..0355a441a1 100644 --- a/src/resources/devtools/findbugs-filters.xml +++ b/src/resources/devtools/findbugs-filters.xml @@ -17,6 +17,7 @@ limitations under the License. ==================================================================== --> +<!--suppress DeprecatedClassUsageInspection --> <FindBugsFilter> <Match> <Bug code="EI,EI2" pattern="CN_IMPLEMENTS_CLONE_BUT_NOT_CLONEABLE,MS_PKGPROTECT,MS_MUTABLE_ARRAY"/> |