]> source.dussan.org Git - poi.git/commitdiff
compact similar CHPX after restoring bin table
authorSergey Vladimirov <sergey@apache.org>
Mon, 25 Jul 2011 09:01:10 +0000 (09:01 +0000)
committerSergey Vladimirov <sergey@apache.org>
Mon, 25 Jul 2011 09:01:10 +0000 (09:01 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1150595 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java

index 3b2c7975ee7b4900a3af602ddb95446e4f15a28d..aed936329b915ce04ed69fef3832346b52627e85 100644 (file)
@@ -20,10 +20,12 @@ package org.apache.poi.hwpf.model;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashSet;
 import java.util.IdentityHashMap;
+import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
@@ -336,7 +338,35 @@ public class CHPBinTable
         logger.log( POILogger.DEBUG, "CHPX rebuilded in ",
                 Long.valueOf( System.currentTimeMillis() - start ), " ms (",
                 Integer.valueOf( _textRuns.size() ), " elements)" );
-    }
+        start = System.currentTimeMillis();
+
+        CHPX previous = null;
+        for ( Iterator<CHPX> iterator = _textRuns.iterator(); iterator
+                .hasNext(); )
+        {
+            CHPX current = iterator.next();
+            if ( previous == null )
+            {
+                previous = current;
+                continue;
+            }
+
+            if ( previous.getEnd() == current.getStart()
+                    && Arrays
+                            .equals( previous.getGrpprl(), current.getGrpprl() ) )
+            {
+                previous.setEnd( current.getEnd() );
+                iterator.remove();
+                continue;
+            }
+            
+            previous = current;
+        }
+
+        logger.log( POILogger.DEBUG, "CHPX compacted in ",
+                Long.valueOf( System.currentTimeMillis() - start ), " ms (",
+                Integer.valueOf( _textRuns.size() ), " elements)" );
+}
 
     private static int binarySearch( List<CHPX> chpxs, int startPosition )
     {