package net.minecraft.data.models.blockstates;

import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.function.Function;
import com.google.common.collect.ImmutableList;
import java.util.List;
import net.minecraft.world.level.block.state.properties.Property;
import java.util.Comparator;

public final class Selector {
    private static final Selector EMPTY;
    private static final Comparator<Property.Value<?>> COMPARE_BY_NAME;
    private final List<Property.Value<?>> values;
    
    public Selector extend(final Property.Value<?> a) {
        return new Selector(ImmutableList.<Property.Value<?>>builder().addAll(this.values).add(a).build());
    }
    
    public Selector extend(final Selector ip) {
        return new Selector((List<Property.Value<?>>)ImmutableList.builder().addAll(this.values).addAll(ip.values).build());
    }
    
    private Selector(final List<Property.Value<?>> list) {
        this.values = list;
    }
    
    public static Selector empty() {
        return Selector.EMPTY;
    }
    
    public static Selector of(final Property.Value<?>... arr) {
        return new Selector(ImmutableList.<Property.Value<?>>copyOf(arr));
    }
    
    @Override
    public boolean equals(final Object object) {
        return this == object || (object instanceof Selector && this.values.equals(((Selector)object).values));
    }
    
    @Override
    public int hashCode() {
        return this.values.hashCode();
    }
    
    public String getKey() {
        return this.values.stream().sorted(Selector.COMPARE_BY_NAME).map(Property.Value::toString).collect(Collectors.joining(","));
    }
    
    @Override
    public String toString() {
        return this.getKey();
    }
    
    static {
        EMPTY = new Selector(ImmutableList.of());
        COMPARE_BY_NAME = Comparator.<Property.Value<?>, Comparable>comparing(a -> a.getProperty().getName());
    }
}
