/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.ca.apim.gateway.extension.sharedstate.SharedKeyValueStore
 *  org.jetbrains.annotations.NotNull
 */
package com.l7tech.server.extension.provider.sharedstate;

import com.ca.apim.gateway.extension.sharedstate.SharedKeyValueStore;
import com.l7tech.server.extension.provider.sharedstate.SharesGatewayMemory;
import com.l7tech.server.extension.provider.sharedstate.a;
import com.l7tech.server.extension.provider.sharedstate.b;
import com.l7tech.server.extension.provider.sharedstate.c;
import java.io.Serializable;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.DelayQueue;
import java.util.concurrent.TimeUnit;
import java.util.function.BiFunction;
import java.util.function.Function;
import org.jetbrains.annotations.NotNull;

public class LocalKeyValueStore<K extends Serializable, V extends Serializable>
implements SharedKeyValueStore<K, V>,
SharesGatewayMemory {
    private final String a;
    private ConcurrentMap<K, V> b;
    private DelayQueue<b<K>> c;
    private c d;
    private static final String[] e;

    LocalKeyValueStore(@NotNull String string) {
        if (string == null) {
            LocalKeyValueStore.a(0);
        }
        this.d = new c(Runtime.getRuntime().availableProcessors() * 4);
        this.a = string;
        this.b = new ConcurrentHashMap();
        this.c = new DelayQueue();
    }

    public boolean isEmpty() {
        this.a();
        return this.b.isEmpty();
    }

    public V get(K k2) {
        try (a a10 = new a(this, this.d.a(k2));){
            this.a();
            Serializable serializable = (Serializable)this.b.get(k2);
            return (V)serializable;
        }
    }

    public V put(K k2, V v2) {
        try (a a10 = new a(this, this.d.a(k2));){
            this.a();
            Serializable serializable = (Serializable)this.b.put(k2, v2);
            return (V)serializable;
        }
    }

    public V put(K k2, V v2, long l2, TimeUnit timeUnit) {
        try (a a10 = new a(this, this.d.a(k2));){
            this.a();
            Serializable serializable = (Serializable)this.b.put(k2, v2);
            this.a(k2, l2, timeUnit);
            Serializable serializable2 = serializable;
            return (V)serializable2;
        }
    }

    public boolean putIfCondition(K k2, V v2, Function<V, Boolean> function, long l2, TimeUnit timeUnit) {
        try (a a10 = new a(this, this.d.a(k2));){
            this.a();
            Serializable serializable = (Serializable)this.b.get(k2);
            if (function.apply(serializable).booleanValue()) {
                this.b.put(k2, v2);
                this.a(k2, l2, timeUnit);
                boolean bl2 = true;
                return bl2;
            }
            boolean bl3 = false;
            return bl3;
        }
    }

    public void set(K k2, V v2) {
        this.put(k2, v2);
    }

    public void set(K k2, V v2, long l2, TimeUnit timeUnit) {
        this.put(k2, v2, l2, timeUnit);
    }

    public boolean containsKey(K k2) {
        try (a a10 = new a(this, this.d.a(k2));){
            this.a();
            boolean bl2 = this.b.containsKey(k2);
            return bl2;
        }
    }

    public V compute(K k2, BiFunction<? super K, ? super V, ? extends V> biFunction) {
        try (a a10 = new a(this, this.d.a(k2));){
            this.a();
            Serializable serializable = (Serializable)this.b.compute((K)k2, (BiFunction<? super K, ? extends V, ? extends V>)biFunction);
            return (V)serializable;
        }
    }

    public V computeIfAbsent(K k2, Function<? super K, ? extends V> function) {
        try (a a10 = new a(this, this.d.a(k2));){
            this.a();
            Serializable serializable = (Serializable)this.b.computeIfAbsent((K)k2, function);
            return (V)serializable;
        }
    }

    public V computeIfPresent(K k2, BiFunction<? super K, ? super V, ? extends V> biFunction) {
        try (a a10 = new a(this, this.d.a(k2));){
            this.a();
            Serializable serializable = (Serializable)this.b.computeIfPresent((K)k2, (BiFunction<? super K, ? extends V, ? extends V>)biFunction);
            return (V)serializable;
        }
    }

    public V remove(K k2) {
        try (a a10 = new a(this, this.d.a(k2));){
            this.a();
            Serializable serializable = (Serializable)this.b.remove(k2);
            return (V)serializable;
        }
    }

    public void delete(K k2) {
        this.remove(k2);
    }

    public void clear() {
        this.b.clear();
        this.c.clear();
    }

    public String getName() {
        return this.a;
    }

    public Set<K> keySet() {
        return Collections.unmodifiableSet(this.b.keySet());
    }

    public int size() {
        return this.b.size();
    }

    private void a() {
        b b10 = (b)this.c.poll();
        while (b10 != null) {
            this.b.remove(b10.a());
            b10 = (b)this.c.poll();
        }
    }

    private void a(K k2, long l2, TimeUnit timeUnit) {
        b<K> b10 = new b<K>(k2, com.l7tech.server.extension.provider.sharedstate.b.a.convert(l2, timeUnit));
        try {
            this.c.remove(b10);
            if (l2 > 0L) {
                this.c.put(b10);
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw LocalKeyValueStore.a(illegalArgumentException);
        }
    }

    @Override
    public boolean sharesGatewayMemory() {
        return true;
    }

    private static /* synthetic */ void a(int n2) {
        String[] stringArray = e;
        throw new IllegalArgumentException(String.format(stringArray[1], stringArray[3], stringArray[2], stringArray[0]));
    }

    private static IllegalArgumentException a(IllegalArgumentException illegalArgumentException) {
        return illegalArgumentException;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[4];
                var3_1 = 0;
                var2_2 = "7 zAzs>J;s]c(D\u007firG|mjE&`f{!F+9uZo O\u007f,f\b)hY,i{N.hY%lg\bc8Y\u007fizGzmHniz]b!";
                var4_3 = "7 zAzs>J;s]c(D\u007firG|mjE&`f{!F+9uZo O\u007f,f\b)hY,i{N.hY%lg\bc8Y\u007fizGzmHniz]b!".length();
                var1_4 = 6;
                var0_5 = -1;
lbl7:
                // 2 sources

                while (true) {
                    v0 = 16;
                    v1 = ++var0_5;
                    v2 = var2_2.substring(v1, v1 + var1_4);
                    v3 = -1;
                    break block9;
                    break;
                }
lbl13:
                // 1 sources

                while (true) {
                    var5[var3_1++] = LocalKeyValueStore.a(v0, LocalKeyValueStore.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "\u000e@\u001fa\u0004\u001c8\bL\u001aa\u001bN>\u001bJ\u0000a\rS8\bA\u0001'\u0007Ec\u001d]\u001d8\u0001O)\u001f\u0000\u0001&\tY)\t\\\u0006/\u001cNc!@\u0011/\u0004`)\u0014y\u0013\"\u001dN\u001f\u0019@\u0000+\u0004\u0003N\u001f+";
                    var4_3 = "\u000e@\u001fa\u0004\u001c8\bL\u001aa\u001bN>\u001bJ\u0000a\rS8\bA\u0001'\u0007Ec\u001d]\u001d8\u0001O)\u001f\u0000\u0001&\tY)\t\\\u0006/\u001cNc!@\u0011/\u0004`)\u0014y\u0013\"\u001dN\u001f\u0019@\u0000+\u0004\u0003N\u001f+".length();
                    var1_4 = 67;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 118;
                        v4 = ++var0_5;
                        v2 = var2_2.substring(v4, v4 + var1_4);
                        v3 = 0;
                        break block9;
                        break;
                    }
                    break;
                }
lbl28:
                // 1 sources

                while (true) {
                    var5[var3_1++] = LocalKeyValueStore.a(v0, LocalKeyValueStore.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    break block10;
                    break;
                }
            }
            switch (v3) {
                default: {
                    ** continue;
                }
                ** case 0:
lbl39:
                // 1 sources

                ** continue;
            }
        }
        LocalKeyValueStore.e = var5;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x3A);
        }
        return cArray;
    }

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String a(int n2, char[] cArray) {
        char[] cArray2;
        block11: {
            int n3;
            int n4;
            int n5;
            block10: {
                n5 = n2;
                cArray2 = cArray;
                n4 = cArray.length;
                n3 = 0;
                if (!true) break block10;
                n4 = n4;
                if (n4 <= n3) break block11;
            }
            do {
                n5 = n5;
                cArray2 = cArray2;
                int n6 = n3;
                cArray2[n6] = (char)(cArray2[n6] ^ (n5 ^ (switch (n3 % 7) {
                    case 0 -> 27;
                    case 1 -> 89;
                    case 2 -> 4;
                    case 3 -> 56;
                    case 4 -> 30;
                    case 5 -> 93;
                    default -> 58;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

