mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Standard code formatting
This commit is contained in:
@@ -22,7 +22,6 @@ import com.thoughtworks.xstream.converters.MarshallingContext;
|
||||
import com.thoughtworks.xstream.converters.UnmarshallingContext;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
||||
import net.openhft.chronicle.values.ValueModel;
|
||||
import net.openhft.chronicle.values.Values;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -45,71 +44,6 @@ class AbstractChronicleMapConverter<K, V> implements Converter {
|
||||
this.mapClazz = map.getClass();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConvert(Class aClass) {
|
||||
//noinspection unchecked
|
||||
return mapClazz.isAssignableFrom(aClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void marshal(Object o, HierarchicalStreamWriter writer, MarshallingContext
|
||||
marshallingContext) {
|
||||
|
||||
for (Map.Entry e : (Iterable<Map.Entry>) ((Map) o).entrySet()) {
|
||||
|
||||
writer.startNode("entry");
|
||||
{
|
||||
final Object key = e.getKey();
|
||||
writer.startNode(key.getClass().getName());
|
||||
marshallingContext.convertAnother(key);
|
||||
writer.endNode();
|
||||
|
||||
Object value = e.getValue();
|
||||
writer.startNode(value.getClass().getName());
|
||||
marshallingContext.convertAnother(value);
|
||||
writer.endNode();
|
||||
}
|
||||
writer.endNode();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object unmarshal(HierarchicalStreamReader reader,
|
||||
UnmarshallingContext context) {
|
||||
// empty map
|
||||
if ("[\"\"]".equals(reader.getValue()))
|
||||
return null;
|
||||
if (!"cmap".equals(reader.getNodeName()))
|
||||
throw new ConversionException("should be under 'cmap' node");
|
||||
reader.moveDown();
|
||||
while (reader.hasMoreChildren()) {
|
||||
reader.moveDown();
|
||||
|
||||
final String nodeName0 = reader.getNodeName();
|
||||
|
||||
if (!nodeName0.equals("entry"))
|
||||
throw new ConversionException("unable to convert node named=" + nodeName0);
|
||||
|
||||
final K k;
|
||||
final V v;
|
||||
|
||||
reader.moveDown();
|
||||
k = deserialize(context, reader);
|
||||
reader.moveUp();
|
||||
|
||||
reader.moveDown();
|
||||
v = deserialize(context, reader);
|
||||
reader.moveUp();
|
||||
|
||||
if (k != null)
|
||||
map.put(k, v);
|
||||
|
||||
reader.moveUp();
|
||||
}
|
||||
reader.moveUp();
|
||||
return null;
|
||||
}
|
||||
|
||||
private static <E> E deserialize(@NotNull UnmarshallingContext unmarshallingContext,
|
||||
@NotNull HierarchicalStreamReader reader) {
|
||||
|
||||
@@ -151,7 +85,72 @@ class AbstractChronicleMapConverter<K, V> implements Converter {
|
||||
} catch (Exception e1) {
|
||||
throw new ConversionException("class=" + clazz, e1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConvert(Class aClass) {
|
||||
//noinspection unchecked
|
||||
return mapClazz.isAssignableFrom(aClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void marshal(Object o, HierarchicalStreamWriter writer, MarshallingContext
|
||||
marshallingContext) {
|
||||
|
||||
for (Map.Entry e : (Iterable<Map.Entry>) ((Map) o).entrySet()) {
|
||||
|
||||
writer.startNode("entry");
|
||||
{
|
||||
final Object key = e.getKey();
|
||||
writer.startNode(key.getClass().getName());
|
||||
marshallingContext.convertAnother(key);
|
||||
writer.endNode();
|
||||
|
||||
Object value = e.getValue();
|
||||
writer.startNode(value.getClass().getName());
|
||||
marshallingContext.convertAnother(value);
|
||||
writer.endNode();
|
||||
}
|
||||
writer.endNode();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object unmarshal(HierarchicalStreamReader reader,
|
||||
UnmarshallingContext context) {
|
||||
// empty map
|
||||
if ("[\"\"]".equals(reader.getValue()))
|
||||
return null;
|
||||
if (!"cmap".equals(reader.getNodeName()))
|
||||
throw new ConversionException("should be under 'cmap' node");
|
||||
reader.moveDown();
|
||||
while (reader.hasMoreChildren()) {
|
||||
reader.moveDown();
|
||||
|
||||
final String nodeName0 = reader.getNodeName();
|
||||
|
||||
if (!nodeName0.equals("entry"))
|
||||
throw new ConversionException("unable to convert node named=" + nodeName0);
|
||||
|
||||
final K k;
|
||||
final V v;
|
||||
|
||||
reader.moveDown();
|
||||
k = deserialize(context, reader);
|
||||
reader.moveUp();
|
||||
|
||||
reader.moveDown();
|
||||
v = deserialize(context, reader);
|
||||
reader.moveUp();
|
||||
|
||||
if (k != null)
|
||||
map.put(k, v);
|
||||
|
||||
reader.moveUp();
|
||||
}
|
||||
reader.moveUp();
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import com.thoughtworks.xstream.converters.MarshallingContext;
|
||||
import com.thoughtworks.xstream.converters.UnmarshallingContext;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
||||
import net.openhft.chronicle.hash.impl.util.CharSequences;
|
||||
|
||||
public class CharSequenceConverter implements Converter {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user