diff options
| author | The Android Open Source Project <initial-contribution@android.com> | 2013-11-22 11:18:57 -0800 |
|---|---|---|
| committer | The Android Open Source Project <initial-contribution@android.com> | 2013-11-22 11:18:57 -0800 |
| commit | dbccd44a638ae8705a5b14bff8b2dd74abc26045 (patch) | |
| tree | 14bfabaf3f3c7be86dfc064e919e00433a0cf2bb /core/java/android/text/SpannableStringInternal.java | |
| parent | ecfae4f899873f224e1aeed076dc8a41f8884487 (diff) | |
| parent | b873a17ce7be0a9771c24999adca6964431728f6 (diff) | |
Merge commit 'b873a17ce7be0a9771c24999adca6964431728f6' into HEAD
Change-Id: I938755073e70602cc8f51ce9bd420fdcf870cecd
Diffstat (limited to 'core/java/android/text/SpannableStringInternal.java')
| -rw-r--r-- | core/java/android/text/SpannableStringInternal.java | 49 |
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; |
