/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  org.springframework.beans.BeansException
 *  org.springframework.context.ApplicationContext
 *  org.springframework.context.ApplicationContextAware
 */
package com.l7tech.server.util;

import com.l7tech.server.util.o;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class LazyPropertyChangeDispatcher
implements ApplicationContextAware,
PropertyChangeListener {
    private static final Logger a;
    private final Map<String, List<String>> b;
    private final Set<String> c;
    private final ReadWriteLock d = new ReentrantReadWriteLock(false);
    private ApplicationContext e;
    private Collection<o> f = null;
    private static final String[] g;

    public LazyPropertyChangeDispatcher(Map<?, ?> map) {
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        HashSet hashSet = new HashSet();
        if (map != null) {
            for (Map.Entry<?, ?> entry : map.entrySet()) {
                Object obj = entry.getKey();
                Object obj2 = entry.getValue();
                try {
                    if (!(obj instanceof String) || !(obj2 instanceof List)) continue;
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw LazyPropertyChangeDispatcher.a(illegalArgumentException);
                }
                String string = (String)obj;
                List list = (List)obj2;
                ArrayList<String> arrayList = new ArrayList<String>(list.size());
                for (Object e10 : list) {
                    try {
                        if (!(e10 instanceof String)) continue;
                        arrayList.add((String)e10);
                    }
                    catch (IllegalArgumentException illegalArgumentException) {
                        throw LazyPropertyChangeDispatcher.a(illegalArgumentException);
                    }
                }
                hashSet.addAll(arrayList);
                linkedHashMap.put(string, arrayList);
            }
        }
        this.b = Collections.unmodifiableMap(linkedHashMap);
        this.c = Collections.unmodifiableSet(hashSet);
    }

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        try {
            if (applicationContext == null) {
                throw new IllegalArgumentException(g[3]);
            }
        }
        catch (BeansException beansException) {
            throw LazyPropertyChangeDispatcher.a((RuntimeException)((Object)beansException));
        }
        this.d.writeLock().lock();
        try {
            if (this.e != null) {
                throw new IllegalStateException(g[0]);
            }
            this.e = applicationContext;
        }
        finally {
            this.d.writeLock().unlock();
        }
    }

    @Override
    public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
        for (o o2 : this.a(propertyChangeEvent.getPropertyName())) {
            if (!o2.b.contains(propertyChangeEvent.getPropertyName())) continue;
            try {
                o2.a.propertyChange(propertyChangeEvent);
            }
            catch (Exception exception) {
                a.log(Level.WARNING, g[4], exception);
            }
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    private Collection<o> a(String string) {
        Collection<o> collection;
        block15: {
            block16: {
                this.d.readLock().lock();
                try {
                    collection = this.f;
                }
                finally {
                    this.d.readLock().unlock();
                }
                try {
                    if (collection != null) break block15;
                    if (this.c.contains(string)) break block16;
                }
                catch (BeansException beansException) {
                    throw LazyPropertyChangeDispatcher.a((RuntimeException)((Object)beansException));
                }
                collection = Collections.emptyList();
                break block15;
            }
            this.d.writeLock().lock();
            try {
                collection = this.f;
                if (collection == null) {
                    Map<String, List<String>> map = this.b;
                    ApplicationContext applicationContext = this.e;
                    if (map == null) {
                        this.f = collection = Collections.emptyList();
                    } else {
                        ArrayList<o> arrayList = new ArrayList<o>();
                        for (Map.Entry<String, List<String>> entry : map.entrySet()) {
                            String string2 = entry.getKey();
                            try {
                                PropertyChangeListener propertyChangeListener = (PropertyChangeListener)applicationContext.getBean(string2, PropertyChangeListener.class);
                                arrayList.add(new o(propertyChangeListener, Collections.unmodifiableSet(new HashSet(entry.getValue()))));
                            }
                            catch (BeansException beansException) {
                                String[] stringArray = g;
                                a.log(Level.WARNING, stringArray[1] + string2 + stringArray[2], beansException);
                            }
                        }
                        this.f = collection = Collections.unmodifiableList(arrayList);
                    }
                }
            }
            finally {
                this.d.writeLock().unlock();
            }
        }
        return collection;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[5];
                var3_1 = 0;
                var2_2 = "\u0015>@0K&5\u0000'_2a*:\u0000+H(\u0002,'T/\\.G$0\rnC9V(7!E0Fe:\u001b:\u0010;G1t\u0004<_,G7 \rnS4C+3\u0011n\\5Q11\u001a+B|\u0005\u0002S`";
                var4_3 = "\u0015>@0K&5\u0000'_2a*:\u0000+H(\u0002,'T/\\.G$0\rnC9V(7!E0Fe:\u001b:\u0010;G1t\u0004<_,G7 \rnS4C+3\u0011n\\5Q11\u001a+B|\u0005\u0002S`".length();
                var1_4 = 33;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = LazyPropertyChangeDispatcher.a(v0, LazyPropertyChangeDispatcher.b(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "\u001f4J:A,?\n-U8k 0\n!B\"\b\"+\r0\u001a8G;~\u001c!\u001a8]#27+*_.X*=\n!^vM7=\u001b4N?G!~\u001a-I&I;=\u0016-T1\b?,\u00114_$\\6~\u001d,[8O*~\u001b2_8\\a";
                    var4_3 = "\u001f4J:A,?\n-U8k 0\n!B\"\b\"+\r0\u001a8G;~\u001c!\u001a8]#27+*_.X*=\n!^vM7=\u001b4N?G!~\u001a-I&I;=\u0016-T1\b?,\u00114_$\\6~\u001d,[8O*~\u001b2_8\\a".length();
                    var1_4 = 35;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 113;
                        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++] = LazyPropertyChangeDispatcher.a(v0, LazyPropertyChangeDispatcher.b(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;
            }
        }
        LazyPropertyChangeDispatcher.g = var5;
        LazyPropertyChangeDispatcher.a = Logger.getLogger(LazyPropertyChangeDispatcher.class.getName());
    }

    private static RuntimeException a(RuntimeException runtimeException) {
        return runtimeException;
    }

    private static char[] b(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x2F);
        }
        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 -> 15;
                    case 1 -> 53;
                    case 2 -> 75;
                    case 3 -> 39;
                    case 4 -> 89;
                    case 5 -> 62;
                    default -> 47;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

