You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2016/12/30 22:11:48 UTC

svn commit: r1776645 - in /poi/trunk/src: java/org/apache/poi/hssf/record/ java/org/apache/poi/sl/draw/ ooxml/java/org/apache/poi/util/ ooxml/java/org/apache/poi/xwpf/usermodel/ resources/devtools/

Author: centic
Date: Fri Dec 30 22:11:48 2016
New Revision: 1776645

URL: http://svn.apache.org/viewvc?rev=1776645&view=rev
Log:
Fix some compilation warnings
Update Javadoc
Reformat code somewhat
Supress IntelliJ warnings in findbugs-filters.xml

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/record/FormulaRecord.java
    poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java
    poi/trunk/src/ooxml/java/org/apache/poi/util/DocumentHelper.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java
    poi/trunk/src/resources/devtools/findbugs-filters.xml

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/FormulaRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/FormulaRecord.java?rev=1776645&r1=1776644&r2=1776645&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/FormulaRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/FormulaRecord.java Fri Dec 30 22:11:48 2016
@@ -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
 		private SpecialCachedValue(byte[] data) {
 			_variableData = data;
 		}
+
 		public int getTypeCode() {
 			return _variableData[0];
 		}
@@ -91,42 +88,55 @@ public final class FormulaRecord extends
 				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
 			};
 			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
 			}
 			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
 
 	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
 	 *  evaluation.
 	 */
 	public boolean hasCachedResultString() {
-		if (specialCachedValue == null) {
-			return false;
-		}
-		return specialCachedValue.getTypeCode() == SpecialCachedValue.STRING;
+		return specialCachedValue != null &&
+				specialCachedValue.getTypeCode() == SpecialCachedValue.STRING;
 	}
 
 	public int getCachedResultType() {

Modified: poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java?rev=1776645&r1=1776644&r2=1776645&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java Fri Dec 30 22:11:48 2016
@@ -62,7 +62,7 @@ public class DrawTextParagraph implement
     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 implement
     /**
      * 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 implement
      */
     @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 implement
             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 implement
 
         return string;
     }
-    
+
     protected boolean isHSLF() {
         return paragraph.getClass().getName().contains("HSLF");
     }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/util/DocumentHelper.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/util/DocumentHelper.java?rev=1776645&r1=1776644&r2=1776645&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/util/DocumentHelper.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/util/DocumentHelper.java Fri Dec 30 22:11:48 2016
@@ -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 {

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java?rev=1776645&r1=1776644&r2=1776645&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java Fri Dec 30 22:11:48 2016
@@ -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 POI
         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 POI
      * 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 POI
         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 POI
 
     @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 POI
 
                 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 POI
     @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
     }

Modified: poi/trunk/src/resources/devtools/findbugs-filters.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/resources/devtools/findbugs-filters.xml?rev=1776645&r1=1776644&r2=1776645&view=diff
==============================================================================
--- poi/trunk/src/resources/devtools/findbugs-filters.xml (original)
+++ poi/trunk/src/resources/devtools/findbugs-filters.xml Fri Dec 30 22:11:48 2016
@@ -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"/>



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org