package net.minecraft.resources;

import java.util.Collections;
import com.google.common.collect.Maps;
import java.util.function.Function;
import net.minecraft.core.Registry;
import java.util.Map;

public class ResourceKey<T> {
    private static final Map<String, ResourceKey<?>> VALUES;
    private final ResourceLocation registryName;
    private final ResourceLocation location;
    
    public static <T> ResourceKey<T> create(final ResourceKey<Registry<T>> ug, final ResourceLocation uh) {
        return ResourceKey.<T>create(ug.location, uh);
    }
    
    public static <T> ResourceKey<Registry<T>> createRegistryKey(final ResourceLocation uh) {
        return ResourceKey.<Registry<T>>create(Registry.ROOT_REGISTRY_NAME, uh);
    }
    
    private static <T> ResourceKey<T> create(final ResourceLocation uh1, final ResourceLocation uh2) {
        final String string3 = (uh1 + ":" + uh2).intern();
        return (ResourceKey<T>)ResourceKey.VALUES.computeIfAbsent(string3, string -> new ResourceKey(uh1, uh2));
    }
    
    private ResourceKey(final ResourceLocation uh1, final ResourceLocation uh2) {
        this.registryName = uh1;
        this.location = uh2;
    }
    
    @Override
    public String toString() {
        return "ResourceKey[" + this.registryName + " / " + this.location + ']';
    }
    
    public ResourceLocation location() {
        return this.location;
    }
    
    public static <T> Function<ResourceLocation, ResourceKey<T>> elementKey(final ResourceKey<Registry<T>> ug) {
        return (Function<ResourceLocation, ResourceKey<T>>)(uh -> ResourceKey.<T>create(ug, uh));
    }
    
    static {
        VALUES = Collections.<String, ResourceKey<?>>synchronizedMap(Maps.newIdentityHashMap());
    }
}
