poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1694335 - in /poi: site/src/documentation/content/xdocs/ trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/ trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/
Date Wed, 05 Aug 2015 21:44:01 GMT
Author: kiwiwings
Date: Wed Aug  5 21:44:01 2015
New Revision: 1694335

URL: http://svn.apache.org/r1694335
Log:
#58204 - STYLE: ShapeContainer interface makes internal getShapesList() redundant

Modified:
    poi/site/src/documentation/content/xdocs/status.xml
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFGroupShape.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java

Modified: poi/site/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/status.xml?rev=1694335&r1=1694334&r2=1694335&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/status.xml (original)
+++ poi/site/src/documentation/content/xdocs/status.xml Wed Aug  5 21:44:01 2015
@@ -39,6 +39,7 @@
     </devs>
 
     <release version="3.13-beta2" date="2015-10-??">
+        <action dev="PD" type="fix" fixes-bug="58204">STYLE: ShapeContainer interface
makes internal getShapesList() redundant</action>
         <action dev="PD" type="add" fixes-bug="58190">The current picture handling
uses raw integers for types and index, replace with enum and reference</action>
         <action dev="PD" type="fix" fixes-bug="58203">Apparently Maven uses plurals
for all artifacts except javadocs, so tweak our naming to make it happy</action>
         <action dev="PD" type="add" fixes-bug="58193">Use input stream rather than
byte array for checksum etc.</action>

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java?rev=1694335&r1=1694334&r2=1694335&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java Wed Aug  5
21:44:01 2015
@@ -144,8 +144,7 @@ public class XSLFGroupShape extends XSLF
     }
 
     /**
-     *
-     * @return child shapes contained witin this group
+     * @return child shapes contained within this group
      */
     @Override
     public List<XSLFShape> getShapes(){

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java?rev=1694335&r1=1694334&r2=1694335&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java Wed Aug  5 21:44:01
2015
@@ -25,7 +25,6 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-
 import javax.xml.namespace.QName;
 
 import org.apache.poi.POIXMLDocumentPart;
@@ -126,57 +125,70 @@ public abstract class XSLFSheet extends
     }
 
     private XSLFDrawing getDrawing(){
-        if(_drawing == null) {
-            _drawing = new XSLFDrawing(this, getSpTree());
-        }
+        initDrawingAndShapes();
         return _drawing;
     }
 
-    private List<XSLFShape> getShapeList(){
-        if(_shapes == null){
-            _shapes = buildShapes(getSpTree());
-        }
+    /**
+     * Returns an array containing all of the shapes in this sheet
+     *
+     * @return an array of all shapes in this sheet
+     */
+    @Override
+    public List<XSLFShape> getShapes(){
+        initDrawingAndShapes();
         return _shapes;
     }
+    
+    /**
+     * Helper method for initializing drawing and shapes in one go.
+     * If they are initialized separately, there's a risk that shapes
+     * get added twice, e.g. a shape is added to the drawing, then
+     * buildShapes is called and at last the shape is added to shape list
+     */
+    private void initDrawingAndShapes() {
+        CTGroupShape cgs = getSpTree();
+        if(_drawing == null) {
+            _drawing = new XSLFDrawing(this, cgs);
+        }
+        if (_shapes == null) {
+            _shapes = buildShapes(cgs);
+        }
+    }
 
     // shape factory methods
 
     public XSLFAutoShape createAutoShape(){
-        List<XSLFShape> shapes = getShapeList();
         XSLFAutoShape sh = getDrawing().createAutoShape();
-        shapes.add(sh);
+        getShapes().add(sh);
         sh.setParent(this);
         return sh;
     }
 
     public XSLFFreeformShape createFreeform(){
-        List<XSLFShape> shapes = getShapeList();
         XSLFFreeformShape sh = getDrawing().createFreeform();
-        shapes.add(sh);
+        getShapes().add(sh);
         sh.setParent(this);
         return sh;
     }
 
     public XSLFTextBox createTextBox(){
-        List<XSLFShape> shapes = getShapeList();
         XSLFTextBox sh = getDrawing().createTextBox();
-        shapes.add(sh);
+        getShapes().add(sh);
         sh.setParent(this);
         return sh;
     }
 
     public XSLFConnectorShape createConnector(){
-        List<XSLFShape> shapes = getShapeList();
         XSLFConnectorShape sh = getDrawing().createConnector();
-        shapes.add(sh);
+        getShapes().add(sh);
         sh.setParent(this);
         return sh;
     }
 
     public XSLFGroupShape createGroup(){
-        List<XSLFShape> shapes = getShapeList();
         XSLFGroupShape sh = getDrawing().createGroup();
-        shapes.add(sh);
+        getShapes().add(sh);
         sh.setParent(this);
         return sh;
     }
@@ -190,36 +202,25 @@ public abstract class XSLFSheet extends
 
         XSLFPictureShape sh = getDrawing().createPicture(rel.getId());
         sh.resize();
-
-        getShapeList().add(sh);
+        getShapes().add(sh);
         sh.setParent(this);
         return sh;
     }
 
     public XSLFTable createTable(){
-        List<XSLFShape> shapes = getShapeList();
         XSLFTable sh = getDrawing().createTable();
-        shapes.add(sh);
+        getShapes().add(sh);
         sh.setParent(this);
         return sh;
     }
 
     /**
-     * Returns an array containing all of the shapes in this sheet
-     *
-     * @return an array of all shapes in this sheet
-     */
-    public List<XSLFShape> getShapes(){
-        return getShapeList();
-    }
-
-    /**
      * Returns an iterator over the shapes in this sheet
      *
      * @return an iterator over the shapes in this sheet
      */
     public Iterator<XSLFShape> iterator(){
-        return getShapeList().iterator();
+        return getShapes().iterator();
     }
 
     public void addShape(XSLFShape shape) {
@@ -250,7 +251,7 @@ public abstract class XSLFSheet extends
         } else {
             throw new IllegalArgumentException("Unsupported shape: " + xShape);
         }
-        return getShapeList().remove(xShape);
+        return getShapes().remove(xShape);
     }
 
     /**
@@ -319,8 +320,8 @@ public abstract class XSLFSheet extends
         getSpTree().set(src.getSpTree());
 
         // recursively update each shape
-        List<XSLFShape> tgtShapes = getShapeList();
-        List<XSLFShape> srcShapes = src.getShapeList();
+        List<XSLFShape> tgtShapes = getShapes();
+        List<XSLFShape> srcShapes = src.getShapes();
         for(int i = 0; i < tgtShapes.size(); i++){
             XSLFShape s1 = srcShapes.get(i);
             XSLFShape s2 = tgtShapes.get(i);
@@ -338,7 +339,7 @@ public abstract class XSLFSheet extends
      */
     public XSLFSheet appendContent(XSLFSheet src){
         CTGroupShape spTree = getSpTree();
-        int numShapes = getShapeList().size();
+        int numShapes = getShapes().size();
 
         CTGroupShape srcTree = src.getSpTree();
         for(XmlObject ch : srcTree.selectPath("*")){
@@ -362,8 +363,8 @@ public abstract class XSLFSheet extends
         _placeholders = null;
 
         // recursively update each shape
-        List<XSLFShape> tgtShapes = getShapeList();
-        List<XSLFShape> srcShapes = src.getShapeList();
+        List<XSLFShape> tgtShapes = getShapes();
+        List<XSLFShape> srcShapes = src.getShapes();
         for(int i = 0; i < srcShapes.size(); i++){
             XSLFShape s1 = srcShapes.get(i);
             XSLFShape s2 = tgtShapes.get(numShapes + i);

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFGroupShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFGroupShape.java?rev=1694335&r1=1694334&r2=1694335&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFGroupShape.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFGroupShape.java Wed Aug
 5 21:44:01 2015
@@ -52,11 +52,6 @@ public class HSLFGroupShape extends HSLF
         super(escherRecord, parent);
     }
 
-    @Override
-    public List<HSLFShape> getShapes() {
-        return getShapeList();
-    }
-
     /**
      * Sets the anchor (the bounding box rectangle) of this shape.
      * All coordinates should be expressed in Master units (576 dpi).
@@ -238,7 +233,7 @@ public class HSLFGroupShape extends HSLF
     }
 
     public Iterator<HSLFShape> iterator() {
-        return getShapeList().iterator();
+        return getShapes().iterator();
     }
 
     public boolean removeShape(HSLFShape shape) {
@@ -249,7 +244,8 @@ public class HSLFGroupShape extends HSLF
     /**
      * @return the shapes contained in this group container
      */
-    protected List<HSLFShape> getShapeList() {
+    @Override
+    public List<HSLFShape> getShapes() {
         // Out escher container record should contain several
         //  SpContainers, the first of which is the group shape itself
         Iterator<EscherRecord> iter = _escherContainer.getChildIterator();

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java?rev=1694335&r1=1694334&r2=1694335&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java Wed Aug  5 21:44:01
2015
@@ -162,7 +162,7 @@ public final class HSLFTable extends HSL
     }
 
     protected void initTable(){
-        List<HSLFShape> shapeList = getShapeList();
+        List<HSLFShape> shapeList = getShapes();
 
         Iterator<HSLFShape> shapeIter = shapeList.iterator();
         while (shapeIter.hasNext()) {



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


Mime
View raw message