// this compacts the representation of a hint map, which is
// otherwise excessive
xstream.registerConverter(new Converter() {
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
HintMap map = (HintMap) source;
for (Iterator<Entry<String, Float>> iterator = map.entrySet().iterator(); iterator.hasNext();) {
Entry<String, Float> entry = iterator.next();
writer.addAttribute(entry.getKey().toString(), entry.getValue().toString());
}
}
@SuppressWarnings("unchecked")
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
HintMap properties = new HintMap();
for (Iterator iterator = reader.getAttributeNames(); iterator.hasNext();) {
String n = (String) iterator.next();
String v = reader.getAttribute(n);
Float f = Float.parseFloat(v);
properties.put(n, f);
}
return properties;
}