// 
// Decompiled by Procyon v0.6.0
// 

package it.unimi.dsi.fastutil.ints;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.function.IntPredicate;
import java.util.Objects;
import java.util.function.Function;

public final class Int2BooleanFunctions
{
    public static final EmptyFunction EMPTY_FUNCTION;
    
    private Int2BooleanFunctions() {
    }
    
    public static Int2BooleanFunction singleton(final int key, final boolean value) {
        return new Singleton(key, value);
    }
    
    public static Int2BooleanFunction singleton(final Integer key, final Boolean value) {
        return new Singleton(key, value);
    }
    
    public static Int2BooleanFunction synchronize(final Int2BooleanFunction f) {
        return new SynchronizedFunction(f);
    }
    
    public static Int2BooleanFunction synchronize(final Int2BooleanFunction f, final Object sync) {
        return new SynchronizedFunction(f, sync);
    }
    
    public static Int2BooleanFunction unmodifiable(final Int2BooleanFunction f) {
        return new UnmodifiableFunction(f);
    }
    
    public static Int2BooleanFunction primitive(final Function<? super Integer, ? extends Boolean> f) {
        Objects.requireNonNull(f);
        if (f instanceof Int2BooleanFunction) {
            return (Int2BooleanFunction)f;
        }
        if (f instanceof IntPredicate) {
            final IntPredicate obj = (IntPredicate)f;
            Objects.requireNonNull(obj);
            return obj::test;
        }
        return new PrimitiveFunction(f);
    }
    
    static {
        EMPTY_FUNCTION = new EmptyFunction();
    }
    
    public static class EmptyFunction extends AbstractInt2BooleanFunction implements Serializable, Cloneable
    {
        private static final long serialVersionUID = -7046029254386353129L;
        
        protected EmptyFunction() {
        }
        
        @Override
        public boolean get(final int k) {
            return false;
        }
        
        @Override
        public boolean getOrDefault(final int k, final boolean defaultValue) {
            return defaultValue;
        }
        
        @Override
        public boolean containsKey(final int k) {
            return false;
        }
        
        @Override
        public boolean defaultReturnValue() {
            return false;
        }
        
        @Override
        public void defaultReturnValue(final boolean defRetValue) {
            throw new UnsupportedOperationException();
        }
        
        @Override
        public int size() {
            return 0;
        }
        
        @Override
        public void clear() {
        }
        
        public Object clone() {
            return Int2BooleanFunctions.EMPTY_FUNCTION;
        }
        
        @Override
        public int hashCode() {
            return 0;
        }
        
        @Override
        public boolean equals(final Object o) {
            return o instanceof Function && ((Function)o).size() == 0;
        }
        
        @Override
        public String toString() {
            return "{}";
        }
        
        private Object readResolve() {
            return Int2BooleanFunctions.EMPTY_FUNCTION;
        }
    }
    
    public static class Singleton extends AbstractInt2BooleanFunction implements Serializable, Cloneable
    {
        private static final long serialVersionUID = -7046029254386353129L;
        protected final int key;
        protected final boolean value;
        
        protected Singleton(final int key, final boolean value) {
            this.key = key;
            this.value = value;
        }
        
        @Override
        public boolean containsKey(final int k) {
            return this.key == k;
        }
        
        @Override
        public boolean get(final int k) {
            return (this.key == k) ? this.value : this.defRetValue;
        }
        
        @Override
        public boolean getOrDefault(final int k, final boolean defaultValue) {
            return (this.key == k) ? this.value : defaultValue;
        }
        
        @Override
        public int size() {
            return 1;
        }
        
        public Object clone() {
            return this;
        }
    }
    
    public static class SynchronizedFunction implements Int2BooleanFunction, Serializable
    {
        private static final long serialVersionUID = -7046029254386353129L;
        protected final Int2BooleanFunction function;
        protected final Object sync;
        
        protected SynchronizedFunction(final Int2BooleanFunction f, final Object sync) {
            if (f == null) {
                throw new NullPointerException();
            }
            this.function = f;
            this.sync = sync;
        }
        
        protected SynchronizedFunction(final Int2BooleanFunction f) {
            if (f == null) {
                throw new NullPointerException();
            }
            this.function = f;
            this.sync = this;
        }
        
        @Override
        public boolean test(final int operand) {
            synchronized (this.sync) {
                return this.function.test(operand);
            }
        }
        
        @Deprecated
        @Override
        public Boolean apply(final Integer key) {
            synchronized (this.sync) {
                return this.function.apply(key);
            }
        }
        
        @Override
        public int size() {
            synchronized (this.sync) {
                return this.function.size();
            }
        }
        
        @Override
        public boolean defaultReturnValue() {
            synchronized (this.sync) {
                return this.function.defaultReturnValue();
            }
        }
        
        @Override
        public void defaultReturnValue(final boolean defRetValue) {
            synchronized (this.sync) {
                this.function.defaultReturnValue(defRetValue);
            }
        }
        
        @Override
        public boolean containsKey(final int k) {
            synchronized (this.sync) {
                return this.function.containsKey(k);
            }
        }
        
        @Deprecated
        @Override
        public boolean containsKey(final Object k) {
            synchronized (this.sync) {
                return this.function.containsKey(k);
            }
        }
        
        @Override
        public boolean put(final int k, final boolean v) {
            synchronized (this.sync) {
                return this.function.put(k, v);
            }
        }
        
        @Override
        public boolean get(final int k) {
            synchronized (this.sync) {
                return this.function.get(k);
            }
        }
        
        @Override
        public boolean getOrDefault(final int k, final boolean defaultValue) {
            synchronized (this.sync) {
                return this.function.getOrDefault(k, defaultValue);
            }
        }
        
        @Override
        public boolean remove(final int k) {
            synchronized (this.sync) {
                return this.function.remove(k);
            }
        }
        
        @Override
        public void clear() {
            synchronized (this.sync) {
                this.function.clear();
            }
        }
        
        @Deprecated
        @Override
        public Boolean put(final Integer k, final Boolean v) {
            synchronized (this.sync) {
                return this.function.put(k, v);
            }
        }
        
        @Deprecated
        @Override
        public Boolean get(final Object k) {
            synchronized (this.sync) {
                return this.function.get(k);
            }
        }
        
        @Deprecated
        @Override
        public Boolean getOrDefault(final Object k, final Boolean defaultValue) {
            synchronized (this.sync) {
                return this.function.getOrDefault(k, defaultValue);
            }
        }
        
        @Deprecated
        @Override
        public Boolean remove(final Object k) {
            synchronized (this.sync) {
                return this.function.remove(k);
            }
        }
        
        @Override
        public int hashCode() {
            synchronized (this.sync) {
                return this.function.hashCode();
            }
        }
        
        @Override
        public boolean equals(final Object o) {
            if (o == this) {
                return true;
            }
            synchronized (this.sync) {
                return this.function.equals(o);
            }
        }
        
        @Override
        public String toString() {
            synchronized (this.sync) {
                return this.function.toString();
            }
        }
        
        private void writeObject(final ObjectOutputStream s) throws IOException {
            synchronized (this.sync) {
                s.defaultWriteObject();
            }
        }
    }
    
    public static class UnmodifiableFunction extends AbstractInt2BooleanFunction implements Serializable
    {
        private static final long serialVersionUID = -7046029254386353129L;
        protected final Int2BooleanFunction function;
        
        protected UnmodifiableFunction(final Int2BooleanFunction f) {
            if (f == null) {
                throw new NullPointerException();
            }
            this.function = f;
        }
        
        @Override
        public int size() {
            return this.function.size();
        }
        
        @Override
        public boolean defaultReturnValue() {
            return this.function.defaultReturnValue();
        }
        
        @Override
        public void defaultReturnValue(final boolean defRetValue) {
            throw new UnsupportedOperationException();
        }
        
        @Override
        public boolean containsKey(final int k) {
            return this.function.containsKey(k);
        }
        
        @Override
        public boolean put(final int k, final boolean v) {
            throw new UnsupportedOperationException();
        }
        
        @Override
        public boolean get(final int k) {
            return this.function.get(k);
        }
        
        @Override
        public boolean getOrDefault(final int k, final boolean defaultValue) {
            return this.function.getOrDefault(k, defaultValue);
        }
        
        @Override
        public boolean remove(final int k) {
            throw new UnsupportedOperationException();
        }
        
        @Override
        public void clear() {
            throw new UnsupportedOperationException();
        }
        
        @Deprecated
        @Override
        public Boolean put(final Integer k, final Boolean v) {
            throw new UnsupportedOperationException();
        }
        
        @Deprecated
        @Override
        public Boolean get(final Object k) {
            return this.function.get(k);
        }
        
        @Deprecated
        @Override
        public Boolean getOrDefault(final Object k, final Boolean defaultValue) {
            return this.function.getOrDefault(k, defaultValue);
        }
        
        @Deprecated
        @Override
        public Boolean remove(final Object k) {
            throw new UnsupportedOperationException();
        }
        
        @Override
        public int hashCode() {
            return this.function.hashCode();
        }
        
        @Override
        public boolean equals(final Object o) {
            return o == this || this.function.equals(o);
        }
        
        @Override
        public String toString() {
            return this.function.toString();
        }
    }
    
    public static class PrimitiveFunction implements Int2BooleanFunction
    {
        protected final java.util.function.Function<? super Integer, ? extends Boolean> function;
        
        protected PrimitiveFunction(final java.util.function.Function<? super Integer, ? extends Boolean> function) {
            this.function = function;
        }
        
        @Override
        public boolean containsKey(final int key) {
            return this.function.apply(key) != null;
        }
        
        @Deprecated
        @Override
        public boolean containsKey(final Object key) {
            return key != null && this.function.apply((Integer)key) != null;
        }
        
        @Override
        public boolean get(final int key) {
            final Boolean v = (Boolean)this.function.apply(key);
            if (v == null) {
                return this.defaultReturnValue();
            }
            return v;
        }
        
        @Override
        public boolean getOrDefault(final int key, final boolean defaultValue) {
            final Boolean v = (Boolean)this.function.apply(key);
            if (v == null) {
                return defaultValue;
            }
            return v;
        }
        
        @Deprecated
        @Override
        public Boolean get(final Object key) {
            if (key == null) {
                return null;
            }
            return (Boolean)this.function.apply((Integer)key);
        }
        
        @Deprecated
        @Override
        public Boolean getOrDefault(final Object key, final Boolean defaultValue) {
            if (key == null) {
                return defaultValue;
            }
            final Boolean v;
            return ((v = (Boolean)this.function.apply((Integer)key)) == null) ? defaultValue : v;
        }
        
        @Deprecated
        @Override
        public Boolean put(final Integer key, final Boolean value) {
            throw new UnsupportedOperationException();
        }
    }
}
