am 193a6261: Merge change 26537 into eclair

Merge commit '193a6261894619985866220c320017f0831d6055' into eclair-plus-aosp

* commit '193a6261894619985866220c320017f0831d6055':
  add hashCode() and equals() to Rfc822Token, as well as a convenience tokenizer method to Rfc822Tokenizer, as part of a calendar guest bugfix.
This commit is contained in:
Debajit Ghosh
2009-09-23 13:45:55 -07:00
committed by Android Git Automerger
2 changed files with 48 additions and 3 deletions

View File

@@ -168,5 +168,31 @@ public class Rfc822Token {
return sb.toString(); 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));
}
} }

View File

@@ -19,6 +19,7 @@ package android.text.util;
import android.widget.MultiAutoCompleteTextView; import android.widget.MultiAutoCompleteTextView;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
/** /**
* This class works as a Tokenizer for MultiAutoCompleteTextView for * This class works as a Tokenizer for MultiAutoCompleteTextView for
@@ -27,18 +28,22 @@ import java.util.ArrayList;
* into a series of Rfc822Tokens. * into a series of Rfc822Tokens.
*/ */
public class Rfc822Tokenizer implements MultiAutoCompleteTextView.Tokenizer { public class Rfc822Tokenizer implements MultiAutoCompleteTextView.Tokenizer {
/** /**
* This constructor will try to take a string like * This constructor will try to take a string like
* "Foo Bar (something) <foo\@google.com>, * "Foo Bar (something) <foo\@google.com>,
* blah\@google.com (something)" * 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 * It does *not* decode MIME encoded-words; charset conversion
* must already have taken place if necessary. * must already have taken place if necessary.
* It will try to be tolerant of broken syntax instead of * It will try to be tolerant of broken syntax instead of
* returning an error. * returning an error.
*
* @hide
*/ */
public static Rfc822Token[] tokenize(CharSequence text) { public static void tokenize(CharSequence text, Collection<Rfc822Token> out) {
ArrayList<Rfc822Token> out = new ArrayList<Rfc822Token>();
StringBuilder name = new StringBuilder(); StringBuilder name = new StringBuilder();
StringBuilder address = new StringBuilder(); StringBuilder address = new StringBuilder();
StringBuilder comment = new StringBuilder(); StringBuilder comment = new StringBuilder();
@@ -148,7 +153,21 @@ public class Rfc822Tokenizer implements MultiAutoCompleteTextView.Tokenizer {
name.toString(), name.toString(),
comment.toString())); comment.toString()));
} }
}
/**
* This method will try to take a string like
* "Foo Bar (something) &lt;foo\@google.com&gt;,
* 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()]); return out.toArray(new Rfc822Token[out.size()]);
} }