ICU-3931 Fixed SelectFormat serialization, equals(); TestMessageFormat.testSelectFormatToPattern()

X-SVN-Rev: 27309
This commit is contained in:
Norbert Lindenberg 2010-01-18 09:07:21 +00:00
parent f38f2c1036
commit c575e21d3a
3 changed files with 15 additions and 25 deletions

View file

@ -154,7 +154,7 @@ import java.util.Map;
public class SelectFormat extends Format{
// Generated by serialver from JDK 1.5
static final long serialVersionUID = 1L;
private static final long serialVersionUID = 2993154333257524984L;
/*
* The applied pattern string.
@ -504,19 +504,15 @@ public class SelectFormat extends Format{
}
/**
* Returns true if this equals the provided <code>SelectFormat<code>.
* @param rhs the SelectFormat to compare against
* @return true if this equals rhs
* {@inheritDoc}
* @draft ICU 4.4
*/
public boolean equals(SelectFormat rhs) {
if( parsedValues == null && rhs.parsedValues == null){
return true;
public boolean equals(Object obj) {
if (!(obj instanceof SelectFormat)) {
return false;
}
if( parsedValues != null && rhs.parsedValues != null){
return parsedValues.equals(rhs.parsedValues);
}
return false;
SelectFormat sf = (SelectFormat) obj;
return pattern == null ? sf.pattern == null : pattern.equals(sf.pattern);
}
/**
@ -524,7 +520,7 @@ public class SelectFormat extends Format{
* @draft ICU 4.4
*/
public int hashCode() {
if( pattern!=null){
if (pattern != null) {
return pattern.hashCode();
}
return 0;
@ -545,10 +541,9 @@ public class SelectFormat extends Format{
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException {
/* To Do
if ( pattern != null ){
in.defaultReadObject();
if (pattern != null) {
applyPattern(pattern);
}
*/
}
}

View file

@ -79,7 +79,6 @@ public class SelectFormatAPITest extends TestFmwk {
errln("Exception encountered in TestEquals 2 " + e.getMessage());
}
/* To Do
//Check equality for 2 objects
try {
Object selFmt5 = new SelectFormat();
@ -91,7 +90,6 @@ public class SelectFormatAPITest extends TestFmwk {
} catch (Exception e){
errln("Exception encountered in TestEquals 3" + e.getMessage());
}
*/
}
/**

View file

@ -1470,28 +1470,25 @@ public class TestMessageFormat extends com.ibm.icu.dev.test.TestFmwk {
public void testSelectFormatToPattern() {
String[] patterns = {
//Pattern with some text at start and at end
"{0} est {1, select, female {all\\u00E9e} other {all\\u00E9}} \\u00E0 Paris.",
"{0} est {1,select, female {all\\u00E9e} other {all\\u00E9}} \\u00E0 Paris.",
//Pattern with some text at start
"{0} est {1, select, female {all\\u00E9e} other {all\\u00E9}}",
"{0} est {1,select, female {all\\u00E9e} other {all\\u00E9}}",
//Pattern with some text at end
"{1, select, female {all\\u00E9e} other {all\\u00E9}} \\u00E0 Paris.",
"{1, select,female {all\\u00E9e} other {all\\u00E9}} \\u00E0 Paris.",
//Pattern with no text at any end
"{1, select, female {all\\u00E9e} other {all\\u00E9}}.",
"{1, select,female {all\\u00E9e} other {all\\u00E9}}.",
//Quoted French pattern
"{0} est {1, select, female {all\\u00E9e c''est} other {all\\u00E9 c''est}} \\u00E0 Paris.",
"{0} est {1,select, female {all\\u00E9e c''est} other {all\\u00E9 c''est}} \\u00E0 Paris.",
};
for (int i = 0; i < patterns.length; ++i) {
String pattern = patterns[i];
MessageFormat mf = new MessageFormat(pattern);
MessageFormat mf2 = new MessageFormat(mf.toPattern());
/*
//To do
if (!mf.equals(mf2)) {
errln("message formats not equal for pattern:\n*** '"
+ pattern + "'\n*** '" + mf.toPattern() + "'");
}
*/
}
}