From: Sergey Vladimirov Date: Thu, 7 Jul 2011 09:51:21 +0000 (+0000) Subject: add toString() methods to PieceDescriptor and TextPiece; add hashCode() to PieceDescr... X-Git-Tag: REL_3_8_BETA4~292 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=588a5a6aff718ba8349a1825c8ad5eb05a9c3c65;p=poi.git add toString() methods to PieceDescriptor and TextPiece; add hashCode() to PieceDescriptor git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1143733 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/PieceDescriptor.java b/src/scratchpad/src/org/apache/poi/hwpf/model/PieceDescriptor.java index 2af7b7a6f3..5d3c50911b 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/PieceDescriptor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/PieceDescriptor.java @@ -97,10 +97,40 @@ public final class PieceDescriptor return 8; } - public boolean equals(Object o) - { - PieceDescriptor pd = (PieceDescriptor)o; + @Override + public int hashCode() + { + final int prime = 31; + int result = 1; + result = prime * result + descriptor; + result = prime * result + prm; + result = prime * result + ( unicode ? 1231 : 1237 ); + return result; + } - return descriptor == pd.descriptor && prm == pd.prm && unicode == pd.unicode; - } + @Override + public boolean equals( Object obj ) + { + if ( this == obj ) + return true; + if ( obj == null ) + return false; + if ( getClass() != obj.getClass() ) + return false; + PieceDescriptor other = (PieceDescriptor) obj; + if ( descriptor != other.descriptor ) + return false; + if ( prm != other.prm ) + return false; + if ( unicode != other.unicode ) + return false; + return true; + } + + @Override + public String toString() + { + return "PieceDescriptor (pos: " + getFilePosition() + "; " + + ( isUnicode() ? "unicode" : "non-unicode" ) + ")"; + } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java b/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java index d7bb2984b5..1ae5f604d2 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java @@ -185,4 +185,10 @@ public final class TextPiece extends PropertyNode implements Comparable { return getStart(); } + + public String toString() + { + return "TextPiece from " + getStart() + " to " + getEnd() + " (" + + getPieceDescriptor() + ")"; + } }