diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java index bdbbf74..eeb648d 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java @@ -16,6 +16,8 @@ ==================================================================== */ package org.apache.poi.xssf.usermodel; +import java.util.Objects; + import org.apache.poi.POIXMLException; import org.apache.poi.util.Internal; import org.apache.poi.ss.usermodel.Font; @@ -553,11 +555,17 @@ * to the style table */ public long registerTo(StylesTable styles) { + return registerTo(styles, true); + } + + public long registerTo(StylesTable styles, boolean force) { this._themes = styles.getTheme(); - short idx = (short)styles.putFont(this, true); + short idx = (short)styles.putFont(this, force); this._index = idx; return idx; } + + /** * Records the Themes Table that is associated with * the current font, used when looking up theme @@ -641,10 +649,33 @@ } public boolean equals(Object o){ - if(!(o instanceof XSSFFont)) return false; + + if (this == o) + return true; + if (o == null) + return false; + if (o.getClass() != getClass()) + return false; XSSFFont cf = (XSSFFont)o; - return _ctFont.toString().equals(cf.getCTFont().toString()); + + // BUG 60845 + boolean equal = + Objects.equals(this.getItalic(), cf.getItalic()) + && Objects.equals(this.getBold(), cf.getBold()) + && Objects.equals(this.getStrikeout(), cf.getStrikeout()) + && Objects.equals(this.getCharSet(), cf.getCharSet()) + && Objects.equals(this.getBold(), cf.getBold()) + && Objects.equals(this.getColor(), cf.getColor()) + && Objects.equals(this.getFamily(), cf.getFamily()) + && Objects.equals(this.getFontHeight(), cf.getFontHeight()) + && Objects.equals(this.getFontName(), cf.getFontName()) + && Objects.equals(this.getScheme(), cf.getScheme()) + && Objects.equals(this.getThemeColor(), cf.getThemeColor()) + && Objects.equals(this.getTypeOffset(), cf.getTypeOffset()) + && Objects.equals(this.getUnderline(), cf.getUnderline()) + && Objects.equals(this.getXSSFColor(), cf.getXSSFColor()); + return equal; } } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java index b100bc2..bbaad77 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java @@ -17,6 +17,8 @@ package org.apache.poi.xssf.usermodel.extensions; +import java.util.Objects; + import org.apache.poi.ss.usermodel.BorderStyle; import org.apache.poi.xssf.model.ThemesTable; import org.apache.poi.xssf.usermodel.XSSFColor; @@ -177,9 +179,26 @@ } public boolean equals(Object o) { - if (!(o instanceof XSSFCellBorder)) return false; + + if (this == o) + return true; + if (o == null) + return false; + if (o.getClass() != getClass()) + return false; XSSFCellBorder cf = (XSSFCellBorder) o; - return border.toString().equals(cf.getCTBorder().toString()); + + // bug 60845 + boolean equal = true; + for(BorderSide side : BorderSide.values()){ + if(!Objects.equals(this.getBorderColor(side), cf.getBorderColor(side)) + || !Objects.equals(this.getBorderStyle(side), cf.getBorderStyle(side))){ + equal = false; + break; + } + } + + return equal; } } \ No newline at end of file diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellFill.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellFill.java index fd6a70e..45165df 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellFill.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellFill.java @@ -21,6 +21,9 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPatternFill; import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPatternType; import org.apache.poi.xssf.usermodel.XSSFColor; + +import java.util.Objects; + import org.apache.poi.util.Internal; /** @@ -122,7 +125,8 @@ */ public STPatternType.Enum getPatternType() { CTPatternFill ptrn = _fill.getPatternFill(); - return ptrn == null ? null : ptrn.getPatternType(); + + return ptrn == null ? STPatternType.NONE : ptrn.getPatternType(); } /** @@ -150,7 +154,7 @@ */ @Internal public CTFill getCTFill() { - return _fill; + return _fill; } @@ -159,9 +163,29 @@ } public boolean equals(Object o) { - if (!(o instanceof XSSFCellFill)) return false; + + if (this == o) + return true; + if (o == null) + return false; + if (o.getClass() != getClass()) + return false; XSSFCellFill cf = (XSSFCellFill) o; - return _fill.toString().equals(cf.getCTFill().toString()); + + // bug 60845 + // Do not compare the representing strings but the properties + // Reason: + // The strings are different if he XMLObject is a fragment (e.g. the ones from cloneStyle) + // even if they are in fact representing the same style + + + + boolean equal = + Objects.equals(this.getFillBackgroundColor(), cf.getFillBackgroundColor()) + && Objects.equals(this.getFillForegroundColor(), cf.getFillForegroundColor()) + && Objects.equals(this.getPatternType(), cf.getPatternType()); + + return equal; } }