ObjectIntIdentityMap .java

net.minecraft.util.ObjectIntIdentityMap (class): members: identityMap, getByValue, objectList, put, iterator, get. imports: Iterators, Predicates, Lists.

net.minecraft.utilclass43 linescommon1.1 KB

Implements

API Surface (4)

void put(T key, int value)
int get(T key)
T getByValue(int value)
Iterator<T> iterator()

Fields & Constants (2)

identityMap
objectList

Code Graph: Dependencies (1)

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

Full Source

ObjectIntIdentityMap.java43 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.util;
2
3
import com.google.common.base.Predicates;
4
import com.google.common.collect.Iterators;
5
import com.google.common.collect.Lists;
6
import java.util.IdentityHashMap;
7
import java.util.Iterator;
8
import java.util.List;
9
10
public class ObjectIntIdentityMap<T> implements IObjectIntIterable<T>
11
{
12
    private final IdentityHashMap<T, Integer> identityMap = new IdentityHashMap(512);
13
    private final List<T> objectList = Lists.<T>newArrayList();
14
15
    public void put(T key, int value)
16
    {
17
        this.identityMap.put(key, Integer.valueOf(value));
18
19
        while (this.objectList.size() <= value)
20
        {
21
            this.objectList.add(null);
22
        }
23
24
        this.objectList.set(value, key);
25
    }
26
27
    public int get(T key)
28
    {
29
        Integer integer = (Integer)this.identityMap.get(key);
30
        return integer == null ? -1 : integer.intValue();
31
    }
32
33
    public final T getByValue(int value)
34
    {
35
        return (T)(value >= 0 && value < this.objectList.size() ? this.objectList.get(value) : null);
36
    }
37
38
    public Iterator<T> iterator()
39
    {
40
        return Iterators.filter(this.objectList.iterator(), Predicates.notNull());
41
    }
42
}
43

Deobfuscated MCP 1.8.9 source of ObjectIntIdentityMap from Marcelektro/MavenMCP-1.8.9 (net/minecraft/util/ObjectIntIdentityMap.java), stored verbatim.