]> source.dussan.org Git - poi.git/commitdiff
sort CHPX on load (sometimes out of order)
authorSergey Vladimirov <sergey@apache.org>
Fri, 8 Jul 2011 14:31:25 +0000 (14:31 +0000)
committerSergey Vladimirov <sergey@apache.org>
Fri, 8 Jul 2011 14:31:25 +0000 (14:31 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1144333 13f79535-47bb-0310-9956-ffa450edef68

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

index 72f37b4182f62b9b49589541b6973d9cd0496613..4a10944664bd10b4838dd441de446e1d0a56e44e 100644 (file)
@@ -17,6 +17,8 @@
 
 package org.apache.poi.hwpf.model;
 
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 import java.util.ArrayList;
 import java.io.OutputStream;
@@ -34,7 +36,21 @@ import org.apache.poi.hwpf.sprm.SprmBuffer;
  */
 public class CHPBinTable
 {
-  /** List of character properties.*/
+
+    private static final class CHPXStartComparator implements Comparator<CHPX>
+    {
+        static CHPXStartComparator instance = new CHPXStartComparator();
+
+        public int compare( CHPX o1, CHPX o2 )
+        {
+            int thisVal = o1.getStart();
+            int anotherVal = o2.getEnd();
+            return ( thisVal < anotherVal ? -1 : ( thisVal == anotherVal ? 0
+                    : 1 ) );
+        }
+    }
+
+/** List of character properties.*/
   protected ArrayList<CHPX> _textRuns = new ArrayList<CHPX>();
 
   /** So we can know if things are unicode or not */
@@ -74,10 +90,13 @@ public class CHPBinTable
 
       for (int y = 0; y < fkpSize; y++)
       {
-        _textRuns.add(cfkp.getCHPX(y));
+        final CHPX chpx = cfkp.getCHPX(y);
+        if (chpx != null)
+            _textRuns.add(chpx);
       }
     }
-  }
+        Collections.sort( _textRuns, CHPXStartComparator.instance );
+    }
 
   public void adjustForDelete(int listIndex, int offset, int length)
   {