diff options
author | Debajit Ghosh <debajit@google.com> | 2009-09-22 20:32:21 -0700 |
---|---|---|
committer | Debajit Ghosh <debajit@google.com> | 2009-09-23 10:44:18 -0700 |
commit | 78a5b8106a4768f7a67e5a29c58f23cd95f6c47c (patch) | |
tree | 6951fa282d90fe7f8eb024bf38433525445d805e /core/java/android/text/util | |
parent | 6c644f248f553898248b8a6948fac4d62874fedd (diff) | |
download | frameworks_base-78a5b8106a4768f7a67e5a29c58f23cd95f6c47c.zip frameworks_base-78a5b8106a4768f7a67e5a29c58f23cd95f6c47c.tar.gz frameworks_base-78a5b8106a4768f7a67e5a29c58f23cd95f6c47c.tar.bz2 |
add hashCode() and equals() to Rfc822Token, as well as a convenience tokenizer method to Rfc822Tokenizer, as part of a calendar guest bugfix.
Diffstat (limited to 'core/java/android/text/util')
-rw-r--r-- | core/java/android/text/util/Rfc822Token.java | 26 | ||||
-rw-r--r-- | core/java/android/text/util/Rfc822Tokenizer.java | 25 |
2 files changed, 48 insertions, 3 deletions
diff --git a/core/java/android/text/util/Rfc822Token.java b/core/java/android/text/util/Rfc822Token.java index 7fe11bc..0edeeb5 100644 --- a/core/java/android/text/util/Rfc822Token.java +++ b/core/java/android/text/util/Rfc822Token.java @@ -168,5 +168,31 @@ public class Rfc822Token { return sb.toString(); } + + public int hashCode() { + int result = 17; + if (mName != null) result = 31 * result + mName.hashCode(); + if (mAddress != null) result = 31 * result + mAddress.hashCode(); + if (mComment != null) result = 31 * result + mComment.hashCode(); + return result; + } + + private static boolean stringEquals(String a, String b) { + if (a == null) { + return (b == null); + } else { + return (a.equals(b)); + } + } + + public boolean equals(Object o) { + if (!(o instanceof Rfc822Token)) { + return false; + } + Rfc822Token other = (Rfc822Token) o; + return (stringEquals(mName, other.mName) && + stringEquals(mAddress, other.mAddress) && + stringEquals(mComment, other.mComment)); + } } diff --git a/core/java/android/text/util/Rfc822Tokenizer.java b/core/java/android/text/util/Rfc822Tokenizer.java index d4e78b0..cb39f7d 100644 --- a/core/java/android/text/util/Rfc822Tokenizer.java +++ b/core/java/android/text/util/Rfc822Tokenizer.java @@ -19,6 +19,7 @@ package android.text.util; import android.widget.MultiAutoCompleteTextView; import java.util.ArrayList; +import java.util.Collection; /** * This class works as a Tokenizer for MultiAutoCompleteTextView for @@ -27,18 +28,22 @@ import java.util.ArrayList; * into a series of Rfc822Tokens. */ public class Rfc822Tokenizer implements MultiAutoCompleteTextView.Tokenizer { + /** * This constructor will try to take a string like * "Foo Bar (something) <foo\@google.com>, * blah\@google.com (something)" - * and convert it into one or more Rfc822Tokens. + * and convert it into one or more Rfc822Tokens, output into the supplied + * collection. + * * It does *not* decode MIME encoded-words; charset conversion * must already have taken place if necessary. * It will try to be tolerant of broken syntax instead of * returning an error. + * + * @hide */ - public static Rfc822Token[] tokenize(CharSequence text) { - ArrayList<Rfc822Token> out = new ArrayList<Rfc822Token>(); + public static void tokenize(CharSequence text, Collection<Rfc822Token> out) { StringBuilder name = new StringBuilder(); StringBuilder address = new StringBuilder(); StringBuilder comment = new StringBuilder(); @@ -148,7 +153,21 @@ public class Rfc822Tokenizer implements MultiAutoCompleteTextView.Tokenizer { name.toString(), comment.toString())); } + } + /** + * This method will try to take a string like + * "Foo Bar (something) <foo\@google.com>, + * blah\@google.com (something)" + * and convert it into one or more Rfc822Tokens. + * It does *not* decode MIME encoded-words; charset conversion + * must already have taken place if necessary. + * It will try to be tolerant of broken syntax instead of + * returning an error. + */ + public static Rfc822Token[] tokenize(CharSequence text) { + ArrayList<Rfc822Token> out = new ArrayList<Rfc822Token>(); + tokenize(text, out); return out.toArray(new Rfc822Token[out.size()]); } |