SPR-6788: fixed compareTo() consistency with equals
This commit is contained in:
parent
0f7f749ada
commit
7832381dd2
|
|
@ -324,11 +324,15 @@ public class MediaType implements Comparable<MediaType> {
|
||||||
if (comp != 0) {
|
if (comp != 0) {
|
||||||
return comp;
|
return comp;
|
||||||
}
|
}
|
||||||
Iterator<String> thisAttributes = new TreeSet<String>(this.parameters.keySet()).iterator();
|
TreeSet<String> thisAttributes = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
|
||||||
Iterator<String> otherAttributes = new TreeSet<String>(other.parameters.keySet()).iterator();
|
thisAttributes.addAll(this.parameters.keySet());
|
||||||
while (thisAttributes.hasNext()) {
|
TreeSet<String> otherAttributes = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
|
||||||
String thisAttribute = thisAttributes.next();
|
otherAttributes.addAll(other.parameters.keySet());
|
||||||
String otherAttribute = otherAttributes.next();
|
Iterator<String> thisAttributesIterator = thisAttributes.iterator();
|
||||||
|
Iterator<String> otherAttributesIterator = otherAttributes.iterator();
|
||||||
|
while (thisAttributesIterator.hasNext()) {
|
||||||
|
String thisAttribute = thisAttributesIterator.next();
|
||||||
|
String otherAttribute = otherAttributesIterator.next();
|
||||||
comp = thisAttribute.compareToIgnoreCase(otherAttribute);
|
comp = thisAttribute.compareToIgnoreCase(otherAttribute);
|
||||||
if (comp != 0) {
|
if (comp != 0) {
|
||||||
return comp;
|
return comp;
|
||||||
|
|
@ -355,7 +359,7 @@ public class MediaType implements Comparable<MediaType> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
MediaType otherType = (MediaType) other;
|
MediaType otherType = (MediaType) other;
|
||||||
return (this.type.equals(otherType.type) && this.subtype.equals(otherType.subtype) &&
|
return (this.type.equalsIgnoreCase(otherType.type) && this.subtype.equalsIgnoreCase(otherType.subtype) &&
|
||||||
this.parameters.equals(otherType.parameters));
|
this.parameters.equals(otherType.parameters));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -214,6 +214,12 @@ public class MediaTypeTests {
|
||||||
assertEquals("Media types not equal", m1, m2);
|
assertEquals("Media types not equal", m1, m2);
|
||||||
assertEquals("compareTo() not consistent with equals", 0, m1.compareTo(m2));
|
assertEquals("compareTo() not consistent with equals", 0, m1.compareTo(m2));
|
||||||
assertEquals("compareTo() not consistent with equals", 0, m2.compareTo(m1));
|
assertEquals("compareTo() not consistent with equals", 0, m2.compareTo(m1));
|
||||||
|
|
||||||
|
m1 = MediaType.parseMediaType("text/html; q=0.7; charset=iso-8859-1");
|
||||||
|
m2 = MediaType.parseMediaType("text/html; Q=0.7; charset=iso-8859-1");
|
||||||
|
assertEquals("Media types not equal", m1, m2);
|
||||||
|
assertEquals("compareTo() not consistent with equals", 0, m1.compareTo(m2));
|
||||||
|
assertEquals("compareTo() not consistent with equals", 0, m2.compareTo(m1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -232,6 +238,8 @@ public class MediaTypeTests {
|
||||||
m2 = new MediaType("audio", "basic", Collections.singletonMap("foo", "Bar"));
|
m2 = new MediaType("audio", "basic", Collections.singletonMap("foo", "Bar"));
|
||||||
assertTrue("Invalid comparison result", m1.compareTo(m2) != 0);
|
assertTrue("Invalid comparison result", m1.compareTo(m2) != 0);
|
||||||
assertTrue("Invalid comparison result", m2.compareTo(m1) != 0);
|
assertTrue("Invalid comparison result", m2.compareTo(m1) != 0);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue