From bd3cd2243edd852a90abeee3a4bc5cb790dffef2 Mon Sep 17 00:00:00 2001 From: Andreas Beeker Date: Sun, 26 Jan 2014 16:26:59 +0000 Subject: [PATCH] TreeSet without JDK 6 method usages git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1561511 13f79535-47bb-0310-9956-ffa450edef68 --- .../xssf/usermodel/helpers/ColumnHelper.java | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java index e8751ef89..4f64c7a4d 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java @@ -123,15 +123,31 @@ public class ColumnHelper { if (col.equals(overrideColumn)) haveOverrideColumn = overrideColumn; while (currentIndex <= nextIndex && !currentElements.isEmpty()) { Set currentIndexElements = new HashSet(); - 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()) {