package com.thoughtworks.xstream.converters.collections; import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.UnmarshallingContext; import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.mapper.Mapper; import java.util.Map; /* loaded from: classes.dex */ public class MapConverter extends AbstractCollectionConverter { static /* synthetic */ Class class$java$util$HashMap; static /* synthetic */ Class class$java$util$Hashtable; static /* synthetic */ Class class$java$util$Map; static /* synthetic */ Class class$java$util$Map$Entry; private final Class type; public MapConverter(Mapper mapper) { this(mapper, null); } static /* synthetic */ Class class$(String str) { try { return Class.forName(str); } catch (ClassNotFoundException e) { throw new NoClassDefFoundError().initCause(e); } } @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$HashMap; if (cls2 == null) { cls2 = class$("java.util.HashMap"); class$java$util$HashMap = cls2; } if (!cls.equals(cls2)) { Class cls3 = class$java$util$Hashtable; if (cls3 == null) { cls3 = class$("java.util.Hashtable"); class$java$util$Hashtable = cls3; } if (!cls.equals(cls3) && !cls.getName().equals("java.util.LinkedHashMap") && !cls.getName().equals("java.util.concurrent.ConcurrentHashMap") && !cls.getName().equals("sun.font.AttributeMap")) { 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) { Map map = (Map) obj; Mapper mapper = mapper(); Class cls = class$java$util$Map$Entry; if (cls == null) { cls = class$("java.util.Map$Entry"); class$java$util$Map$Entry = cls; } String serializedClass = mapper.serializedClass(cls); for (Map.Entry entry : map.entrySet()) { ExtendedHierarchicalStreamWriterHelper.startNode(hierarchicalStreamWriter, serializedClass, entry.getClass()); writeCompleteItem(entry.getKey(), marshallingContext, hierarchicalStreamWriter); writeCompleteItem(entry.getValue(), marshallingContext, hierarchicalStreamWriter); hierarchicalStreamWriter.endNode(); } } protected void populateMap(HierarchicalStreamReader hierarchicalStreamReader, UnmarshallingContext unmarshallingContext, Map map) { populateMap(hierarchicalStreamReader, unmarshallingContext, map, map); } protected void putCurrentEntryIntoMap(HierarchicalStreamReader hierarchicalStreamReader, UnmarshallingContext unmarshallingContext, Map map, Map map2) { map2.put(readCompleteItem(hierarchicalStreamReader, unmarshallingContext, map), readCompleteItem(hierarchicalStreamReader, unmarshallingContext, map)); } @Override // com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter, com.thoughtworks.xstream.converters.Converter public Object unmarshal(HierarchicalStreamReader hierarchicalStreamReader, UnmarshallingContext unmarshallingContext) { Map map = (Map) createCollection(unmarshallingContext.getRequiredType()); populateMap(hierarchicalStreamReader, unmarshallingContext, map); return map; } public MapConverter(Mapper mapper, Class cls) { super(mapper); this.type = cls; if (cls != null) { Class cls2 = class$java$util$Map; if (cls2 == null) { cls2 = class$("java.util.Map"); class$java$util$Map = cls2; } if (cls2.isAssignableFrom(cls)) { return; } StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(cls); stringBuffer.append(" not of type "); Class cls3 = class$java$util$Map; if (cls3 == null) { cls3 = class$("java.util.Map"); class$java$util$Map = cls3; } stringBuffer.append(cls3); throw new IllegalArgumentException(stringBuffer.toString()); } } protected void populateMap(HierarchicalStreamReader hierarchicalStreamReader, UnmarshallingContext unmarshallingContext, Map map, Map map2) { while (hierarchicalStreamReader.hasMoreChildren()) { hierarchicalStreamReader.moveDown(); putCurrentEntryIntoMap(hierarchicalStreamReader, unmarshallingContext, map, map2); hierarchicalStreamReader.moveUp(); } } }