Initial commit
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
package com.thoughtworks.xstream.converters.collections;
|
||||
|
||||
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 com.thoughtworks.xstream.mapper.Mapper;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class CollectionConverter extends AbstractCollectionConverter {
|
||||
static /* synthetic */ Class class$java$util$ArrayList;
|
||||
static /* synthetic */ Class class$java$util$Collection;
|
||||
static /* synthetic */ Class class$java$util$HashSet;
|
||||
static /* synthetic */ Class class$java$util$LinkedHashSet;
|
||||
static /* synthetic */ Class class$java$util$LinkedList;
|
||||
static /* synthetic */ Class class$java$util$Vector;
|
||||
private final Class type;
|
||||
|
||||
public CollectionConverter(Mapper mapper) {
|
||||
this(mapper, null);
|
||||
}
|
||||
|
||||
static /* synthetic */ Class class$(String str) {
|
||||
try {
|
||||
return Class.forName(str);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new NoClassDefFoundError().initCause(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void addCurrentElementToCollection(HierarchicalStreamReader hierarchicalStreamReader, UnmarshallingContext unmarshallingContext, Collection collection, Collection collection2) {
|
||||
collection2.add(readItem(hierarchicalStreamReader, unmarshallingContext, collection));
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter, com.thoughtworks.xstream.converters.ConverterMatcher
|
||||
public boolean canConvert(Class cls) {
|
||||
Object obj = this.type;
|
||||
if (obj != null) {
|
||||
return cls.equals(obj);
|
||||
}
|
||||
Class cls2 = class$java$util$ArrayList;
|
||||
if (cls2 == null) {
|
||||
cls2 = class$("java.util.ArrayList");
|
||||
class$java$util$ArrayList = cls2;
|
||||
}
|
||||
if (!cls.equals(cls2)) {
|
||||
Class cls3 = class$java$util$HashSet;
|
||||
if (cls3 == null) {
|
||||
cls3 = class$("java.util.HashSet");
|
||||
class$java$util$HashSet = cls3;
|
||||
}
|
||||
if (!cls.equals(cls3)) {
|
||||
Class cls4 = class$java$util$LinkedList;
|
||||
if (cls4 == null) {
|
||||
cls4 = class$("java.util.LinkedList");
|
||||
class$java$util$LinkedList = cls4;
|
||||
}
|
||||
if (!cls.equals(cls4)) {
|
||||
Class cls5 = class$java$util$Vector;
|
||||
if (cls5 == null) {
|
||||
cls5 = class$("java.util.Vector");
|
||||
class$java$util$Vector = cls5;
|
||||
}
|
||||
if (!cls.equals(cls5)) {
|
||||
Class cls6 = class$java$util$LinkedHashSet;
|
||||
if (cls6 == null) {
|
||||
cls6 = class$("java.util.LinkedHashSet");
|
||||
class$java$util$LinkedHashSet = cls6;
|
||||
}
|
||||
if (!cls.equals(cls6)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter
|
||||
protected Object createCollection(Class cls) {
|
||||
Class cls2 = this.type;
|
||||
if (cls2 != null) {
|
||||
cls = cls2;
|
||||
}
|
||||
return super.createCollection(cls);
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter, com.thoughtworks.xstream.converters.Converter
|
||||
public void marshal(Object obj, HierarchicalStreamWriter hierarchicalStreamWriter, MarshallingContext marshallingContext) {
|
||||
Iterator it = ((Collection) obj).iterator();
|
||||
while (it.hasNext()) {
|
||||
writeCompleteItem(it.next(), marshallingContext, hierarchicalStreamWriter);
|
||||
}
|
||||
}
|
||||
|
||||
protected void populateCollection(HierarchicalStreamReader hierarchicalStreamReader, UnmarshallingContext unmarshallingContext, Collection collection) {
|
||||
populateCollection(hierarchicalStreamReader, unmarshallingContext, collection, collection);
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter, com.thoughtworks.xstream.converters.Converter
|
||||
public Object unmarshal(HierarchicalStreamReader hierarchicalStreamReader, UnmarshallingContext unmarshallingContext) {
|
||||
Collection collection = (Collection) createCollection(unmarshallingContext.getRequiredType());
|
||||
populateCollection(hierarchicalStreamReader, unmarshallingContext, collection);
|
||||
return collection;
|
||||
}
|
||||
|
||||
public CollectionConverter(Mapper mapper, Class cls) {
|
||||
super(mapper);
|
||||
this.type = cls;
|
||||
if (cls != null) {
|
||||
Class cls2 = class$java$util$Collection;
|
||||
if (cls2 == null) {
|
||||
cls2 = class$("java.util.Collection");
|
||||
class$java$util$Collection = cls2;
|
||||
}
|
||||
if (cls2.isAssignableFrom(cls)) {
|
||||
return;
|
||||
}
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append(cls);
|
||||
stringBuffer.append(" not of type ");
|
||||
Class cls3 = class$java$util$Collection;
|
||||
if (cls3 == null) {
|
||||
cls3 = class$("java.util.Collection");
|
||||
class$java$util$Collection = cls3;
|
||||
}
|
||||
stringBuffer.append(cls3);
|
||||
throw new IllegalArgumentException(stringBuffer.toString());
|
||||
}
|
||||
}
|
||||
|
||||
protected void populateCollection(HierarchicalStreamReader hierarchicalStreamReader, UnmarshallingContext unmarshallingContext, Collection collection, Collection collection2) {
|
||||
while (hierarchicalStreamReader.hasMoreChildren()) {
|
||||
hierarchicalStreamReader.moveDown();
|
||||
addCurrentElementToCollection(hierarchicalStreamReader, unmarshallingContext, collection, collection2);
|
||||
hierarchicalStreamReader.moveUp();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user