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

package com.hypixel.hytale.server.core.modules.i18n.generator;

import java.util.Collections;
import java.util.List;
import java.util.Comparator;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import java.util.Collection;
import javax.annotation.Nullable;
import java.util.Iterator;
import java.util.Properties;
import java.util.Map;
import javax.annotation.Nonnull;
import java.util.LinkedHashMap;

public class TranslationMap
{
    @Nonnull
    private LinkedHashMap<String, String> map;
    
    public TranslationMap() {
        this.map = new LinkedHashMap<String, String>();
    }
    
    public TranslationMap(final Map<String, String> initial) {
        (this.map = new LinkedHashMap<String, String>()).putAll((Map<?, ?>)initial);
    }
    
    public TranslationMap(@Nonnull final Properties initial) {
        this.map = new LinkedHashMap<String, String>();
        for (final String key : initial.stringPropertyNames()) {
            this.map.put(key, initial.getProperty(key));
        }
    }
    
    @Nullable
    public String get(final String key) {
        return this.map.get(key);
    }
    
    public void put(final String key, final String value) {
        this.map.put(key, value);
    }
    
    public void removeKeys(@Nonnull final Collection<? extends String> keys) {
        this.map.keySet().removeAll(keys);
    }
    
    public int size() {
        return this.map.size();
    }
    
    public void putAbsentKeys(@Nonnull final TranslationMap other) {
        for (final Map.Entry<String, String> e : other.map.entrySet()) {
            final String key = e.getKey();
            final String otherValue = e.getValue();
            this.map.putIfAbsent(key, otherValue);
        }
    }
    
    public void sortByKeyBeforeFirstDot() {
        final List<String> keys = new ObjectArrayList<String>(this.map.keySet());
        final Comparator<String> comparator = Comparator.comparing(fullKey -> {
            final int firstDotIndex = fullKey.indexOf(46);
            return (firstDotIndex == -1) ? fullKey : fullKey.substring(0, firstDotIndex);
        }).thenComparing(fullKey -> {
            final int firstDotIndex2 = fullKey.indexOf(46);
            return (firstDotIndex2 == -1) ? "" : fullKey.substring(firstDotIndex2 + 1);
        });
        keys.sort(comparator);
        final LinkedHashMap<String, String> sorted = new LinkedHashMap<String, String>();
        for (final String key : keys) {
            sorted.put(key, this.map.get(key));
        }
        this.map = sorted;
    }
    
    @Nonnull
    public Map<String, String> asMap() {
        return Collections.unmodifiableMap((Map<? extends String, ? extends String>)this.map);
    }
}
