package com.fasterxml.jackson.datatype.hppc.deser;
import java.io.IOException;
import java.util.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.type.LogicalType;
import com.carrotsearch.hppc.*;
public class HppcContainerDeserializers
{
protected final static HashMap<Class<?>, Class<?>> _concreteMapping =
new HashMap<Class<?>, Class<?>>();
static {
_concreteMapping.put(IntContainer.class, IntArrayList.class);
_concreteMapping.put(IntIndexedContainer.class, IntArrayList.class);
_concreteMapping.put(IntSet.class, IntHashSet.class);
_concreteMapping.put(IntDeque.class, IntArrayDeque.class);
}
public static JsonDeserializer<?> findDeserializer(DeserializationConfig config,
final JavaType origType)
throws JsonMappingException
{
JavaType type = origType;
Class<?> raw = type.getRawClass();
if (IntContainer.class.isAssignableFrom(raw)) {
if (type.isAbstract()) {
Class<?> concrete = _concreteMapping.get(raw);
if (concrete != null) {
type = config.getTypeFactory().constructSpecializedType(type, concrete);
raw = concrete;
}
}
if (IntIndexedContainer.class.isAssignableFrom(raw)) {
return new IntIndexedContainerDeserializer(type, config);
}
if (IntSet.class.isAssignableFrom(raw)) {
return new IntSetDeserializer(type, config);
}
if (IntDeque.class.isAssignableFrom(raw)) {
return new IntDequeDeserializer(type, config);
}
throw JsonMappingException.from((JsonParser)null, "Unrecognized HPPC IntContainer type: "+origType);
} else if (LongContainer.class.isAssignableFrom(raw)) {
} else if (FloatContainer.class.isAssignableFrom(raw)) {
} else if (DoubleContainer.class.isAssignableFrom(raw)) {
} else if (ByteContainer.class.isAssignableFrom(raw)) {
} else if (ShortContainer.class.isAssignableFrom(raw)) {
} else if (CharContainer.class.isAssignableFrom(raw)) {
}
return null;
}
public static boolean hasDeserializerFor(DeserializationConfig config,
final Class<?> rawType) {
return IntContainer.class.isAssignableFrom(rawType);
}
@SuppressWarnings("serial")
static abstract class IntContainerDeserializerBase<T>
extends ContainerDeserializerBase<T>
{
public IntContainerDeserializerBase(JavaType type, DeserializationConfig config)
{
super(type, config);
}
@Override
public LogicalType logicalType() {
return LogicalType.Collection;
}
@Override
public void deserializeContents(JsonParser p, DeserializationContext ctxt,
T container)
throws IOException
{
JsonToken t;
while ((t = p.nextToken()) != JsonToken.END_ARRAY) {
int value;
if (t == JsonToken.VALUE_NUMBER_INT || t == JsonToken.VALUE_NUMBER_FLOAT) {
value = p.getIntValue();
} else {
if (t != JsonToken.VALUE_NULL) {
ctxt.handleUnexpectedToken(_valueClass, p);
return;
}
value = 0;
}
add(container, value);
}
}
protected abstract void add(T container, int value);
}
static class IntSetDeserializer extends IntContainerDeserializerBase<IntSet>
{
private static final long serialVersionUID = 1L;
public IntSetDeserializer(JavaType type, DeserializationConfig config)
{
super(type, config);
}
@Override
protected void add(IntSet container, int value) {
container.add(value);
}
}
static class IntIndexedContainerDeserializer extends IntContainerDeserializerBase<IntIndexedContainer>
{
private static final long serialVersionUID = 1L;
public IntIndexedContainerDeserializer(JavaType type, DeserializationConfig config)
{
super(type, config);
}
@Override
protected void add(IntIndexedContainer container, int value) {
container.add(value);
}
}
static class IntDequeDeserializer extends IntContainerDeserializerBase<IntDeque>
{
private static final long serialVersionUID = 1L;
public IntDequeDeserializer(JavaType type, DeserializationConfig config)
{
super(type, config);
}
@Override
protected void add(IntDeque container, int value) {
container.addLast(value);
}
}
}