summaryrefslogtreecommitdiff
path: root/core/java/android/text/SpannableStringInternal.java
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android/text/SpannableStringInternal.java')
-rw-r--r--core/java/android/text/SpannableStringInternal.java49
1 files changed, 49 insertions, 0 deletions
diff --git a/core/java/android/text/SpannableStringInternal.java b/core/java/android/text/SpannableStringInternal.java
index 0825bf3b5665..456a3e5a6b18 100644
--- a/core/java/android/text/SpannableStringInternal.java
+++ b/core/java/android/text/SpannableStringInternal.java
@@ -358,6 +358,55 @@ import java.lang.reflect.Array;
}
}
+ // Same as SpannableStringBuilder
+ @Override
+ public boolean equals(Object o) {
+ if (o instanceof Spanned &&
+ toString().equals(o.toString())) {
+ Spanned other = (Spanned) o;
+ // Check span data
+ Object[] otherSpans = other.getSpans(0, other.length(), Object.class);
+ if (mSpanCount == otherSpans.length) {
+ for (int i = 0; i < mSpanCount; ++i) {
+ Object thisSpan = mSpans[i];
+ Object otherSpan = otherSpans[i];
+ if (thisSpan == this) {
+ if (other != otherSpan ||
+ getSpanStart(thisSpan) != other.getSpanStart(otherSpan) ||
+ getSpanEnd(thisSpan) != other.getSpanEnd(otherSpan) ||
+ getSpanFlags(thisSpan) != other.getSpanFlags(otherSpan)) {
+ return false;
+ }
+ } else if (!thisSpan.equals(otherSpan) ||
+ getSpanStart(thisSpan) != other.getSpanStart(otherSpan) ||
+ getSpanEnd(thisSpan) != other.getSpanEnd(otherSpan) ||
+ getSpanFlags(thisSpan) != other.getSpanFlags(otherSpan)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+ return false;
+ }
+
+ // Same as SpannableStringBuilder
+ @Override
+ public int hashCode() {
+ int hash = toString().hashCode();
+ hash = hash * 31 + mSpanCount;
+ for (int i = 0; i < mSpanCount; ++i) {
+ Object span = mSpans[i];
+ if (span != this) {
+ hash = hash * 31 + span.hashCode();
+ }
+ hash = hash * 31 + getSpanStart(span);
+ hash = hash * 31 + getSpanEnd(span);
+ hash = hash * 31 + getSpanFlags(span);
+ }
+ return hash;
+ }
+
private String mText;
private Object[] mSpans;
private int[] mSpanData;