diff options
| -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 7fe11bc430e6..0edeeb539776 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 d4e78b0dd280..cb39f7de0c1e 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()]); } |