PropertyEnum .java

net.minecraft.block.properties.PropertyEnum (class): members: nameToValue, allowedValues, getAllowedValues, create, getName. imports: Collections2, Maps.

net.minecraft.block.propertiesclass69 linescommonextends Enum<T>2.2 KB

API Surface (2)

Collection<T> getAllowedValues()
String getName(T value)

Fields & Constants (2)

allowedValues
nameToValue

String literals (1)

"Multiple values have the same name \'"

Code Graph: Dependencies (2)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

PropertyEnum.java69 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.block.properties;
2
3
import com.google.common.base.Predicate;
4
import com.google.common.base.Predicates;
5
import com.google.common.collect.Collections2;
6
import com.google.common.collect.ImmutableSet;
7
import com.google.common.collect.Lists;
8
import com.google.common.collect.Maps;
9
import java.util.Collection;
10
import java.util.Map;
11
import net.minecraft.util.IStringSerializable;
12
13
public class PropertyEnum<T extends Enum<T> & IStringSerializable> extends PropertyHelper<T>
14
{
15
    private final ImmutableSet<T> allowedValues;
16
    private final Map<String, T> nameToValue = Maps.<String, T>newHashMap();
17
18
    protected PropertyEnum(String name, Class<T> valueClass, Collection<T> allowedValues)
19
    {
20
        super(name, valueClass);
21
        this.allowedValues = ImmutableSet.copyOf(allowedValues);
22
23
        for (T t : allowedValues)
24
        {
25
            String s = ((IStringSerializable)t).getName();
26
27
            if (this.nameToValue.containsKey(s))
28
            {
29
                throw new IllegalArgumentException("Multiple values have the same name \'" + s + "\'");
30
            }
31
32
            this.nameToValue.put(s, t);
33
        }
34
    }
35
36
    public Collection<T> getAllowedValues()
37
    {
38
        return this.allowedValues;
39
    }
40
41
    /**
42
     * Get the name for the given value.
43
     */
44
    public String getName(T value)
45
    {
46
        return ((IStringSerializable)value).getName();
47
    }
48
49
    public static <T extends Enum<T> & IStringSerializable> PropertyEnum<T> create(String name, Class<T> clazz)
50
    {
51
        return create(name, clazz, Predicates.<T>alwaysTrue());
52
    }
53
54
    public static <T extends Enum<T> & IStringSerializable> PropertyEnum<T> create(String name, Class<T> clazz, Predicate<T> filter)
55
    {
56
        return create(name, clazz, Collections2.<T>filter(Lists.newArrayList(clazz.getEnumConstants()), filter));
57
    }
58
59
    public static <T extends Enum<T> & IStringSerializable> PropertyEnum<T> create(String name, Class<T> clazz, T... values)
60
    {
61
        return create(name, clazz, Lists.newArrayList(values));
62
    }
63
64
    public static <T extends Enum<T> & IStringSerializable> PropertyEnum<T> create(String name, Class<T> clazz, Collection<T> values)
65
    {
66
        return new PropertyEnum(name, clazz, values);
67
    }
68
}
69

Deobfuscated MCP 1.8.9 source of PropertyEnum from Marcelektro/MavenMCP-1.8.9 (net/minecraft/block/properties/PropertyEnum.java), stored verbatim.