package com.parse;

import android.os.Parcel;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import p138.p139.p143.p144.C2803;

/* JADX INFO: loaded from: classes.dex */
public final class ParseFieldOperations {
    public static Map<String, ParseFieldOperationFactory> opDecoderMap = new HashMap();

    public interface ParseFieldOperationFactory {
        ParseFieldOperation decode(Parcel parcel, ParseParcelDecoder parseParcelDecoder);

        ParseFieldOperation decode(JSONObject jSONObject, ParseDecoder parseDecoder);
    }

    public static ParseFieldOperation decode(Parcel parcel, ParseParcelDecoder parseParcelDecoder) {
        String string = parcel.readString();
        ParseFieldOperationFactory parseFieldOperationFactory = opDecoderMap.get(string);
        if (parseFieldOperationFactory != null) {
            return parseFieldOperationFactory.decode(parcel, parseParcelDecoder);
        }
        throw new RuntimeException(C2803.m4879("Unable to decode operation of type ", string));
    }

    public static ParseFieldOperation decode(JSONObject jSONObject, ParseDecoder parseDecoder) {
        String strOptString = jSONObject.optString("__op");
        ParseFieldOperationFactory parseFieldOperationFactory = opDecoderMap.get(strOptString);
        if (parseFieldOperationFactory != null) {
            return parseFieldOperationFactory.decode(jSONObject, parseDecoder);
        }
        throw new RuntimeException(C2803.m4879("Unable to decode operation of type ", strOptString));
    }

    public static ArrayList<Object> jsonArrayAsArrayList(JSONArray jSONArray) {
        ArrayList<Object> arrayList = new ArrayList<>(jSONArray.length());
        for (int i = 0; i < jSONArray.length(); i++) {
            try {
                arrayList.add(jSONArray.get(i));
            } catch (JSONException e) {
                throw new RuntimeException(e);
            }
        }
        return arrayList;
    }
}
