From: Sergey Vladimirov Date: Fri, 8 Jul 2011 14:31:25 +0000 (+0000) Subject: sort CHPX on load (sometimes out of order) X-Git-Tag: REL_3_8_BETA4~256 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ad91a5f33ba57fd15b242e852e271f597ec5dd5e;p=poi.git sort CHPX on load (sometimes out of order) git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1144333 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java index 72f37b4182..4a10944664 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java @@ -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 + { + 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 _textRuns = new ArrayList(); /** 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) {