package androidx.emoji2.text;

import android.graphics.Typeface;
import android.util.SparseArray;
import java.io.IOException;
import java.nio.ByteBuffer;

/* JADX INFO: compiled from: MetadataRepo.java */
/* JADX INFO: loaded from: classes.dex */
public final class m {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private final y.b f2122a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final char[] f2123b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final a f2124c = new a(1024);

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private final Typeface f2125d;

    /* JADX INFO: compiled from: MetadataRepo.java */
    static class a {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private final SparseArray<a> f2126a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        private g f2127b;

        private a() {
            this(1);
        }

        a a(int i3) {
            SparseArray<a> sparseArray = this.f2126a;
            if (sparseArray == null) {
                return null;
            }
            return sparseArray.get(i3);
        }

        final g b() {
            return this.f2127b;
        }

        void c(g gVar, int i3, int i4) {
            a aVarA = a(gVar.b(i3));
            if (aVarA == null) {
                aVarA = new a();
                this.f2126a.put(gVar.b(i3), aVarA);
            }
            if (i4 > i3) {
                aVarA.c(gVar, i3 + 1, i4);
            } else {
                aVarA.f2127b = gVar;
            }
        }

        a(int i3) {
            this.f2126a = new SparseArray<>(i3);
        }
    }

    private m(Typeface typeface, y.b bVar) {
        this.f2125d = typeface;
        this.f2122a = bVar;
        this.f2123b = new char[bVar.k() * 2];
        a(bVar);
    }

    private void a(y.b bVar) {
        int iK = bVar.k();
        for (int i3 = 0; i3 < iK; i3++) {
            g gVar = new g(this, i3);
            Character.toChars(gVar.f(), this.f2123b, i3 * 2);
            h(gVar);
        }
    }

    public static m b(Typeface typeface, ByteBuffer byteBuffer) throws IOException {
        try {
            androidx.core.os.f.a("EmojiCompat.MetadataRepo.create");
            return new m(typeface, l.b(byteBuffer));
        } finally {
            androidx.core.os.f.b();
        }
    }

    public char[] c() {
        return this.f2123b;
    }

    public y.b d() {
        return this.f2122a;
    }

    int e() {
        return this.f2122a.l();
    }

    a f() {
        return this.f2124c;
    }

    Typeface g() {
        return this.f2125d;
    }

    void h(g gVar) {
        androidx.core.util.h.g(gVar, "emoji metadata cannot be null");
        androidx.core.util.h.a(gVar.c() > 0, "invalid metadata codepoint length");
        this.f2124c.c(gVar, 0, gVar.c() - 1);
    }
}
