package com.google.common.collect; import com.google.common.collect.Multiset; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.lang.reflect.Field; import java.util.Collection; import java.util.Iterator; import java.util.Map; /* loaded from: classes2.dex */ final class Serialization { private Serialization() { } /* JADX INFO: Access modifiers changed from: package-private */ public static int readCount(ObjectInputStream objectInputStream) throws IOException { return objectInputStream.readInt(); } /* JADX INFO: Access modifiers changed from: package-private */ public static void writeMap(Map map, ObjectOutputStream objectOutputStream) throws IOException { objectOutputStream.writeInt(map.size()); for (Map.Entry entry : map.entrySet()) { objectOutputStream.writeObject(entry.getKey()); objectOutputStream.writeObject(entry.getValue()); } } /* JADX INFO: Access modifiers changed from: package-private */ public static void populateMap(Map map, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException { populateMap(map, objectInputStream, objectInputStream.readInt()); } /* JADX INFO: Access modifiers changed from: package-private */ /* JADX WARN: Multi-variable type inference failed */ public static void populateMap(Map map, ObjectInputStream objectInputStream, int i) throws IOException, ClassNotFoundException { for (int i2 = 0; i2 < i; i2++) { map.put(objectInputStream.readObject(), objectInputStream.readObject()); } } /* JADX INFO: Access modifiers changed from: package-private */ public static void writeMultiset(Multiset multiset, ObjectOutputStream objectOutputStream) throws IOException { objectOutputStream.writeInt(multiset.entrySet().size()); for (Multiset.Entry entry : multiset.entrySet()) { objectOutputStream.writeObject(entry.getElement()); objectOutputStream.writeInt(entry.getCount()); } } /* JADX INFO: Access modifiers changed from: package-private */ public static void populateMultiset(Multiset multiset, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException { populateMultiset(multiset, objectInputStream, objectInputStream.readInt()); } /* JADX INFO: Access modifiers changed from: package-private */ /* JADX WARN: Multi-variable type inference failed */ public static void populateMultiset(Multiset multiset, ObjectInputStream objectInputStream, int i) throws IOException, ClassNotFoundException { for (int i2 = 0; i2 < i; i2++) { multiset.add(objectInputStream.readObject(), objectInputStream.readInt()); } } /* JADX INFO: Access modifiers changed from: package-private */ public static void writeMultimap(Multimap multimap, ObjectOutputStream objectOutputStream) throws IOException { objectOutputStream.writeInt(multimap.asMap().size()); for (Map.Entry> entry : multimap.asMap().entrySet()) { objectOutputStream.writeObject(entry.getKey()); objectOutputStream.writeInt(entry.getValue().size()); Iterator it = entry.getValue().iterator(); while (it.hasNext()) { objectOutputStream.writeObject(it.next()); } } } /* JADX INFO: Access modifiers changed from: package-private */ public static void populateMultimap(Multimap multimap, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException { populateMultimap(multimap, objectInputStream, objectInputStream.readInt()); } /* JADX INFO: Access modifiers changed from: package-private */ /* JADX WARN: Multi-variable type inference failed */ public static void populateMultimap(Multimap multimap, ObjectInputStream objectInputStream, int i) throws IOException, ClassNotFoundException { for (int i2 = 0; i2 < i; i2++) { Collection collection = multimap.get(objectInputStream.readObject()); int readInt = objectInputStream.readInt(); for (int i3 = 0; i3 < readInt; i3++) { collection.add(objectInputStream.readObject()); } } } /* JADX INFO: Access modifiers changed from: package-private */ public static FieldSetter getFieldSetter(Class cls, String str) { try { return new FieldSetter<>(cls.getDeclaredField(str)); } catch (NoSuchFieldException e) { throw new AssertionError(e); } } /* loaded from: classes2.dex */ static final class FieldSetter { private final Field field; private FieldSetter(Field field) { this.field = field; field.setAccessible(true); } /* JADX INFO: Access modifiers changed from: package-private */ public final void set(T t, Object obj) { try { this.field.set(t, obj); } catch (IllegalAccessException e) { throw new AssertionError(e); } } /* JADX INFO: Access modifiers changed from: package-private */ public final void set(T t, int i) { try { this.field.set(t, Integer.valueOf(i)); } catch (IllegalAccessException e) { throw new AssertionError(e); } } } }