Hi again,

I apologize for not doing it the right way. I'll paste the modifications I did 
hoping it would be clear:

In StylesTable.java

Add this variable:
private final Map<String, Integer> bordersIndices = new HashMap();

The method putBorder becomes:

    public int putBorder(XSSFCellBorder border) {
      Object key = border.getKey();
      Integer index = this.bordersIndices.get(key);
      if (index != null) return index;
//        int idx = borders.indexOf(border);
//        if (idx != -1) {
//            return idx;
//        }
        borders.add(border);
        border.setThemesTable(theme);
        index = borders.size() - 1;
        this.bordersIndices.put(key, index);
        return index;
//        return borders.size() - 1;
    }

In XSSFCellBorder.java

Add these:

String key = ""; //To avoid null tests

public String getKey() { return this.key; }
private void updateKey()  {   this.key = this.border.toString();  }

Modify these by calling this.updateKey():

    public XSSFCellBorder(CTBorder border, IndexedColorMap colorMap) {
        this.border = border;
        this._indexedColorMap = colorMap;
        this.updateKey();
    }
    public void setBorderStyle(BorderSide side, BorderStyle style) {
        getBorder(side, 
true).setStyle(STBorderStyle.Enum.forInt(style.ordinal() + 1));
        this.updateKey();
    }

    public void setBorderColor(BorderSide side, XSSFColor color) {
        CTBorderPr borderPr = getBorder(side, true);
        if (color == null) borderPr.unsetColor();
        else
            borderPr.setColor(color.getCTColor());
        this.updateKey();
    }

    private CTBorderPr getBorder(BorderSide side, boolean ensure) {
        CTBorderPr borderPr;
        switch (side) {
            case TOP:
                borderPr = border.getTop();
                if (ensure && borderPr == null)
                {
                  borderPr = border.addNewTop();
                  this.updateKey();
                }
                break;
            case RIGHT:
                borderPr = border.getRight();
                if (ensure && borderPr == null)
                {
                  borderPr = border.addNewRight();
                  this.updateKey();
                }
                break;
            case BOTTOM:
                borderPr = border.getBottom();
                if (ensure && borderPr == null)
                {
                  borderPr = border.addNewBottom();
                  this.updateKey();
                }
                break;
            case LEFT:
                borderPr = border.getLeft();
                if (ensure && borderPr == null)
                {
                  borderPr = border.addNewLeft();
                  this.updateKey();
                }
                break;
            default:
                throw new IllegalArgumentException("No suitable side specified 
for the border");
        }
        return borderPr;
    }

Modify these:

    public int hashCode() {
//        return border.toString().hashCode();
        return this.key.hashCode();
    }

    public boolean equals(Object o) {
        if (!(o instanceof XSSFCellBorder)) return false;

        XSSFCellBorder cf = (XSSFCellBorder) o;
//        return border.toString().equals(cf.getCTBorder().toString());
        return this.key.equals(cf.key);
    }



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to