Skip to content

Commit

Permalink
Better deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
jodastephen committed Nov 7, 2016
1 parent 8b5d91c commit edf371f
Showing 1 changed file with 0 additions and 251 deletions.
251 changes: 0 additions & 251 deletions src/main/java/org/joda/beans/ser/GuavaSerIteratorFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package org.joda.beans.ser;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -89,27 +88,6 @@ public SerIterator create(final Object value, final MetaProperty<?> prop, Class<
Class<?> valueType = JodaBeanUtils.extractTypeClass(prop, beanClass, 3, 2);
return table((Table<?, ?, ?>) value, declaredType, rowType, colType, valueType, EMPTY_VALUE_TYPES);
}
if (value instanceof ImmutableList) {
Class<?> valueType = defaultToObjectClass(JodaBeanUtils.collectionType(prop, beanClass));
List<Class<?>> valueTypeTypes = JodaBeanUtils.collectionTypeTypes(prop, beanClass);
return immutableList((Collection<?>) value, declaredType, valueType, valueTypeTypes);
}
if (value instanceof ImmutableSortedSet) {
Class<?> valueType = defaultToObjectClass(JodaBeanUtils.collectionType(prop, beanClass));
List<Class<?>> valueTypeTypes = JodaBeanUtils.collectionTypeTypes(prop, beanClass);
return immutableSortedSet((Collection<?>) value, declaredType, valueType, valueTypeTypes);
}
if (value instanceof ImmutableSet) {
Class<?> valueType = defaultToObjectClass(JodaBeanUtils.collectionType(prop, beanClass));
List<Class<?>> valueTypeTypes = JodaBeanUtils.collectionTypeTypes(prop, beanClass);
return immutableSet((Collection<?>) value, declaredType, valueType, valueTypeTypes);
}
if (value instanceof ImmutableMap) {
Class<?> keyType = defaultToObjectClass(JodaBeanUtils.mapKeyType(prop, beanClass));
Class<?> valueType = defaultToObjectClass(JodaBeanUtils.mapValueType(prop, beanClass));
List<Class<?>> valueTypeTypes = JodaBeanUtils.mapValueTypeTypes(prop, beanClass);
return immutableMap((Map<?, ?>) value, declaredType, keyType, valueType, valueTypeTypes);
}
return super.create(value, prop, beanClass);
}

Expand Down Expand Up @@ -185,18 +163,6 @@ public SerIterable createIterable(final String metaTypeDescription, final JodaBe
if (metaTypeDescription.equals("Table")) {
return table(Object.class, Object.class, Object.class, EMPTY_VALUE_TYPES);
}
if (metaTypeDescription.equals("ImmutableList")) {
return immutableList(Object.class, EMPTY_VALUE_TYPES);
}
if (metaTypeDescription.equals("ImmutableSortedSet")) {
return immutableSortedSet(Object.class, EMPTY_VALUE_TYPES);
}
if (metaTypeDescription.equals("ImmutableSet")) {
return immutableSet(Object.class, EMPTY_VALUE_TYPES);
}
if (metaTypeDescription.equals("ImmutableMap")) {
return immutableMap(Object.class, Object.class, EMPTY_VALUE_TYPES);
}
return super.createIterable(metaTypeDescription, settings, knownTypes);
}

Expand Down Expand Up @@ -938,221 +904,4 @@ public List<Class<?>> valueTypeTypes() {
};
}

/**
* Gets an iterator wrapper for {@code ImmutableList}.
*
* @param coll the collection, not null
* @param declaredType the declared type, not null
* @param valueType the value type, not null
* @param valueTypeTypes the generic parameters of the value type
* @return the iterator, not null
*/
@SuppressWarnings("rawtypes")
public static final SerIterator immutableList(
final Collection<?> coll, final Class<?> declaredType, final Class<?> valueType, final List<Class<?>> valueTypeTypes) {
return new SerIterator() {
private final Iterator it = coll.iterator();
private Object current;

@Override
public String metaTypeName() {
return "ImmutableList";
}
@Override
public boolean metaTypeRequired() {
return ImmutableList.class.isAssignableFrom(declaredType) == false;
}
@Override
public int size() {
return coll.size();
}
@Override
public boolean hasNext() {
return it.hasNext();
}
@Override
public void next() {
current = it.next();
}
@Override
public Class<?> valueType() {
return valueType;
}
@Override
public List<Class<?>> valueTypeTypes() {
return valueTypeTypes;
}
@Override
public Object value() {
return current;
}
};
}

/**
* Gets an iterator wrapper for {@code ImmutableSortedSet}.
*
* @param coll the collection, not null
* @param declaredType the declared type, not null
* @param valueType the value type, not null
* @param valueTypeTypes the generic parameters of the value type
* @return the iterator, not null
*/
@SuppressWarnings("rawtypes")
public static final SerIterator immutableSortedSet(
final Collection<?> coll, final Class<?> declaredType, final Class<?> valueType, final List<Class<?>> valueTypeTypes) {
return new SerIterator() {
private final Iterator it = coll.iterator();
private Object current;

@Override
public String metaTypeName() {
return "ImmutableSortedSet";
}
@Override
public boolean metaTypeRequired() {
return ImmutableSortedSet.class.isAssignableFrom(declaredType) == false;
}
@Override
public int size() {
return coll.size();
}
@Override
public boolean hasNext() {
return it.hasNext();
}
@Override
public void next() {
current = it.next();
}
@Override
public Class<?> valueType() {
return valueType;
}
@Override
public List<Class<?>> valueTypeTypes() {
return valueTypeTypes;
}
@Override
public Object value() {
return current;
}
};
}

/**
* Gets an iterator wrapper for {@code ImmutableSet}.
*
* @param coll the collection, not null
* @param declaredType the declared type, not null
* @param valueType the value type, not null
* @param valueTypeTypes the generic parameters of the value type
* @return the iterator, not null
*/
@SuppressWarnings("rawtypes")
public static final SerIterator immutableSet(
final Collection<?> coll, final Class<?> declaredType, final Class<?> valueType, final List<Class<?>> valueTypeTypes) {
return new SerIterator() {
private final Iterator it = coll.iterator();
private Object current;

@Override
public String metaTypeName() {
return "ImmutableSet";
}
@Override
public boolean metaTypeRequired() {
return ImmutableSet.class.isAssignableFrom(declaredType) == false;
}
@Override
public int size() {
return coll.size();
}
@Override
public boolean hasNext() {
return it.hasNext();
}
@Override
public void next() {
current = it.next();
}
@Override
public Class<?> valueType() {
return valueType;
}
@Override
public List<Class<?>> valueTypeTypes() {
return valueTypeTypes;
}
@Override
public Object value() {
return current;
}
};
}

/**
* Gets an iterator wrapper for {@code ImmutableMap}.
*
* @param map the collection, not null
* @param declaredType the declared type, not null
* @param keyType the value type, not null
* @param valueType the value type, not null
* @param valueTypeTypes the generic parameters of the value type
* @return the iterator, not null
*/
@SuppressWarnings("rawtypes")
public static final SerIterator immutableMap(
final Map<?, ?> map, final Class<?> declaredType,
final Class<?> keyType, final Class<?> valueType, final List<Class<?>> valueTypeTypes) {
return new SerIterator() {
private final Iterator it = map.entrySet().iterator();
private Entry current;

@Override
public String metaTypeName() {
return "ImmutableMap";
}
@Override
public boolean metaTypeRequired() {
return ImmutableMap.class.isAssignableFrom(declaredType) == false;
}
@Override
public SerCategory category() {
return SerCategory.MAP;
}
@Override
public int size() {
return map.size();
}
@Override
public boolean hasNext() {
return it.hasNext();
}
@Override
public void next() {
current = (Entry) it.next();
}
@Override
public Class<?> keyType() {
return keyType;
}
@Override
public Object key() {
return current.getKey();
}
@Override
public Class<?> valueType() {
return valueType;
}
@Override
public List<Class<?>> valueTypeTypes() {
return valueTypeTypes;
}
@Override
public Object value() {
return current.getValue();
}
};
}
}

0 comments on commit edf371f

Please sign in to comment.