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

package com.hypixel.hytale.assetstore.map;

import it.unimi.dsi.fastutil.Hash;

public class CaseInsensitiveHashStrategy<K> implements Hash.Strategy<K>
{
    private static final CaseInsensitiveHashStrategy INSTANCE;
    
    public static <K> CaseInsensitiveHashStrategy<K> getInstance() {
        return CaseInsensitiveHashStrategy.INSTANCE;
    }
    
    @Override
    public int hashCode(final K key) {
        if (key == null) {
            return 0;
        }
        if (key instanceof final String s) {
            int hash = 0;
            for (int i = 0; i < s.length(); ++i) {
                hash = 31 * hash + Character.toLowerCase(s.charAt(i));
            }
            return hash;
        }
        return key.hashCode();
    }
    
    @Override
    public boolean equals(final K a, final K b) {
        if (a == b) {
            return true;
        }
        if (a == null || b == null) {
            return false;
        }
        if (a instanceof final String sa) {
            if (b instanceof final String sb) {
                return sa.equalsIgnoreCase(sb);
            }
        }
        return a.equals(b);
    }
    
    static {
        INSTANCE = new CaseInsensitiveHashStrategy();
    }
}
