Merge change 26537 into eclair

* changes:
  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:
Android (Google) Code Review
2009-09-23 16:17:02 -04:00
2 changed files with 48 additions and 3 deletions

View File

@@ -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));
}
}

View File

@@ -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) &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()]);
}