]> source.dussan.org Git - poi.git/commitdiff
TreeSet without JDK 6 method usages
authorAndreas Beeker <kiwiwings@apache.org>
Sun, 26 Jan 2014 16:26:59 +0000 (16:26 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Sun, 26 Jan 2014 16:26:59 +0000 (16:26 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1561511 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java

index e8751ef89689b64bb626025cf0b20cdc1d34a17f..4f64c7a4db8229d24236aa0ddc54b69ed885e654 100644 (file)
@@ -123,15 +123,31 @@ public class ColumnHelper {
             if (col.equals(overrideColumn)) haveOverrideColumn = overrideColumn;
             while (currentIndex <= nextIndex && !currentElements.isEmpty()) {
                 Set<CTCol> currentIndexElements = new HashSet<CTCol>();
-                CTCol currentElem = currentElements.first();
-                long currentElemIndex = currentElem.getMax();
-                currentIndexElements.add(currentElem);
-                while (currentElements.higher(currentElem) != null && currentElements.higher(currentElem).getMax() == currentElemIndex) {
-                    currentElem = currentElements.higher(currentElem);
+                long currentElemIndex;
+                
+                {
+                    // narrow scope of currentElem
+                    CTCol currentElem = currentElements.first();
+                    currentElemIndex = currentElem.getMax();
                     currentIndexElements.add(currentElem);
-                    if (col.getMax() > currentMax) currentMax = col.getMax();
-                    if (col.equals(overrideColumn)) haveOverrideColumn = overrideColumn;
+                    
+                    for (CTCol cc : currentElements.tailSet(currentElem)) {
+                        if (cc == null || cc.getMax() == currentElemIndex) break;
+                        currentIndexElements.add(cc);
+                        if (col.getMax() > currentMax) currentMax = col.getMax();
+                        if (col.equals(overrideColumn)) haveOverrideColumn = overrideColumn;
+                    }
+
+                    // JDK 6 code
+                    // while (currentElements.higher(currentElem) != null && currentElements.higher(currentElem).getMax() == currentElemIndex) {
+                    //     currentElem = currentElements.higher(currentElem);
+                    //     currentIndexElements.add(currentElem);
+                    //     if (col.getMax() > currentMax) currentMax = col.getMax();
+                    //     if (col.equals(overrideColumn)) haveOverrideColumn = overrideColumn;
+                    // }
                 }
+                
+                
                 if (currentElemIndex < nextIndex || !flIter.hasNext()) {
                     insertCol(cols, currentIndex, currentElemIndex, currentElements.toArray(new CTCol[]{}), true, haveOverrideColumn);
                     if (flIter.hasNext()) {