diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2014-02-09 21:19:20 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2014-02-09 21:19:20 +0000 |
commit | 4b9d47af5a000ad70e8befdac6a27164f122e1b6 (patch) | |
tree | 30c3a90ba5d7bbf414d3cbc92f009c9fe09c2e2c /src/java/org | |
parent | 71d856448e1ccc41cf80a40d172d09b9ea502dae (diff) | |
download | poi-4b9d47af5a000ad70e8befdac6a27164f122e1b6.tar.gz poi-4b9d47af5a000ad70e8befdac6a27164f122e1b6.zip |
FindBugs fix
- fixed "Class defines equals() and uses Object.hashCode()"
- see http://findbugs.sourceforge.net/bugDescriptions.html#HE_EQUALS_USE_HASHCODE
- implemented UnicodeString.ExtRst.hashCode() + junit-test
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1566427 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org')
8 files changed, 86 insertions, 10 deletions
diff --git a/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java b/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java index f13d7f0eb4..026f99754b 100644 --- a/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java +++ b/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java @@ -90,7 +90,13 @@ public final class HyperlinkRecord extends StandardRecord { && _d3 == other._d3 && _d4 == other._d4; } - public int getD1() { + @Override + public int hashCode() { + assert false : "hashCode not designed"; + return 42; // any arbitrary constant will do + } + + public int getD1() { return _d1; } diff --git a/src/java/org/apache/poi/hssf/record/common/UnicodeString.java b/src/java/org/apache/poi/hssf/record/common/UnicodeString.java index 9e9ca03925..a9ba7b5ea4 100644 --- a/src/java/org/apache/poi/hssf/record/common/UnicodeString.java +++ b/src/java/org/apache/poi/hssf/record/common/UnicodeString.java @@ -18,14 +18,21 @@ package org.apache.poi.hssf.record.common; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.List; -import org.apache.poi.hssf.record.cont.ContinuableRecordInput; import org.apache.poi.hssf.record.RecordInputStream; +import org.apache.poi.hssf.record.cont.ContinuableRecordInput; import org.apache.poi.hssf.record.cont.ContinuableRecordOutput; -import org.apache.poi.util.*; +import org.apache.poi.util.BitField; +import org.apache.poi.util.BitFieldFactory; +import org.apache.poi.util.LittleEndianInput; +import org.apache.poi.util.LittleEndianOutput; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; +import org.apache.poi.util.StringUtil; /** * Title: Unicode String<p/> @@ -88,6 +95,12 @@ public class UnicodeString implements Comparable<UnicodeString> { // TODO - make return _character - r._character; } + @Override + public int hashCode() { + assert false : "hashCode not designed"; + return 42; // any arbitrary constant will do + } + public String toString() { return "character="+_character+",fontIndex="+_fontIndex; } @@ -248,17 +261,33 @@ public class UnicodeString implements Comparable<UnicodeString> { // TODO - make if(result != 0) return result; result = phRuns[i].realTextFirstCharacterOffset - o.phRuns[i].realTextFirstCharacterOffset; if(result != 0) return result; - result = phRuns[i].realTextFirstCharacterOffset - o.phRuns[i].realTextLength; + result = phRuns[i].realTextLength - o.phRuns[i].realTextLength; if(result != 0) return result; } - result = extraData.length - o.extraData.length; - if(result != 0) return result; + result = Arrays.hashCode(extraData)-Arrays.hashCode(o.extraData); - // If we get here, it's the same - return 0; + return result; } - + + @Override + public int hashCode() { + int hash = reserved; + hash = 31*hash+formattingFontIndex; + hash = 31*hash+formattingOptions; + hash = 31*hash+numberOfRuns; + hash = 31*hash+phoneticText.hashCode(); + + if (phRuns != null) { + for (PhRun ph : phRuns) { + hash = 31*hash+ph.phoneticTextFirstCharacterOffset; + hash = 31*hash+ph.realTextFirstCharacterOffset; + hash = 31*hash+ph.realTextLength; + } + } + return hash; + } + protected ExtRst clone() { ExtRst ext = new ExtRst(); ext.reserved = reserved; diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFChildAnchor.java b/src/java/org/apache/poi/hssf/usermodel/HSSFChildAnchor.java index be69c2a98d..a7a88c6b6b 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFChildAnchor.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFChildAnchor.java @@ -140,4 +140,10 @@ public final class HSSFChildAnchor extends HSSFAnchor { return anchor.getDx1() == getDx1() && anchor.getDx2() == getDx2() && anchor.getDy1() == getDy1() && anchor.getDy2() == getDy2(); } + + @Override + public int hashCode() { + assert false : "hashCode not designed"; + return 42; // any arbitrary constant will do + } } diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFClientAnchor.java b/src/java/org/apache/poi/hssf/usermodel/HSSFClientAnchor.java index b1df28f221..0a65bbd8ff 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFClientAnchor.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFClientAnchor.java @@ -275,6 +275,12 @@ public final class HSSFClientAnchor extends HSSFAnchor implements ClientAnchor { } @Override + public int hashCode() { + assert false : "hashCode not designed"; + return 42; // any arbitrary constant will do + } + + @Override public int getDx1() { return _escherClientAnchor.getDx1(); } diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java b/src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java index 434b7eff34..76572de746 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java @@ -301,6 +301,7 @@ public final class HSSFRichTextString implements Comparable<HSSFRichTextString>, return _string.compareTo(r._string); } + @Override public boolean equals(Object o) { if (o instanceof HSSFRichTextString) { return _string.equals(((HSSFRichTextString)o)._string); @@ -309,6 +310,13 @@ public final class HSSFRichTextString implements Comparable<HSSFRichTextString>, } + @Override + public int hashCode() { + assert false : "hashCode not designed"; + return 42; // any arbitrary constant will do + } + + /** * @return the plain text representation of this string. */ diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java b/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java index 6f6340afa3..1ef2acfc74 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java @@ -23,10 +23,10 @@ import java.util.NoSuchElementException; import org.apache.poi.hssf.record.CellValueRecordInterface; import org.apache.poi.hssf.record.ExtendedFormatRecord; import org.apache.poi.hssf.record.RowRecord; +import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.util.Configurator; /** @@ -684,6 +684,7 @@ public final class HSSFRow implements Row { return -1; } + @Override public boolean equals(Object obj) { if (!(obj instanceof HSSFRow)) @@ -698,4 +699,10 @@ public final class HSSFRow implements Row { } return false; } + + @Override + public int hashCode() { + assert false : "hashCode not designed"; + return 42; // any arbitrary constant will do + } } diff --git a/src/java/org/apache/poi/ss/util/CellReference.java b/src/java/org/apache/poi/ss/util/CellReference.java index b43eb1bfc6..0b063ec8b1 100644 --- a/src/java/org/apache/poi/ss/util/CellReference.java +++ b/src/java/org/apache/poi/ss/util/CellReference.java @@ -517,4 +517,10 @@ public class CellReference { && _isRowAbs == cr._isColAbs && _isColAbs == cr._isColAbs; } + + @Override + public int hashCode() { + assert false : "hashCode not designed"; + return 42; // any arbitrary constant will do + } } diff --git a/src/java/org/apache/poi/ss/util/Region.java b/src/java/org/apache/poi/ss/util/Region.java index d0c373838c..b39681917a 100644 --- a/src/java/org/apache/poi/ss/util/Region.java +++ b/src/java/org/apache/poi/ss/util/Region.java @@ -164,6 +164,14 @@ public class Region implements Comparable<Region> { return (compareTo(r) == 0); } + + @Override + public int hashCode() { + assert false : "hashCode not designed"; + return 42; // any arbitrary constant will do + } + + /** * Compares that the given region is the same less than or greater than this * region. If any regional coordiant passed in is less than this regions |