checked serialization of TransformerMap and added a test for it
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@795994 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bf740630ae
commit
9d5d0da39b
|
@ -32,8 +32,6 @@ import org.apache.commons.math.MathException;
|
|||
* @version $Revision$ $Date$
|
||||
*/
|
||||
public class TransformerMap implements NumberTransformer, Serializable {
|
||||
// TODO: Add Serializable documentation
|
||||
// TODO: Check Serializable implementation
|
||||
|
||||
/** Serializable version identifier */
|
||||
private static final long serialVersionUID = 4605318041528645258L;
|
||||
|
@ -154,4 +152,41 @@ public class TransformerMap implements NumberTransformer, Serializable {
|
|||
return value;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (other == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
TransformerMap rhs = (TransformerMap) other;
|
||||
if (! defaultTransformer.equals(rhs.defaultTransformer)) {
|
||||
return false;
|
||||
}
|
||||
if (map.size() != rhs.map.size()) {
|
||||
return false;
|
||||
}
|
||||
for (Map.Entry<Class<?>, NumberTransformer> entry : map.entrySet()) {
|
||||
if (! entry.getValue().equals(rhs.map.get(entry.getKey()))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (ClassCastException cce) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = defaultTransformer.hashCode();
|
||||
for (NumberTransformer t : map.values()) {
|
||||
hash = hash * 31 + t.hashCode();
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
package org.apache.commons.math.util;
|
||||
|
||||
import org.apache.commons.math.TestUtils;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
|
@ -101,4 +103,12 @@ public class TransformerMapTest extends TestCase {
|
|||
map.putTransformer(TransformerMapTest.class, expected);
|
||||
assertTrue(map.transformers().contains(expected));
|
||||
}
|
||||
|
||||
public void testSerial(){
|
||||
NumberTransformer expected = new DefaultTransformer();
|
||||
TransformerMap map = new TransformerMap();
|
||||
map.putTransformer(TransformerMapTest.class, expected);
|
||||
assertEquals(map, TestUtils.serializeAndRecover(map));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue