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

package com.hypixel.hytale.server.npc.asset.builder;

import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import java.util.function.Supplier;
import java.util.List;

public class ReferenceSlotMapper<T> extends SlotMapper
{
    private final List<T> list;
    private final Supplier<T> slotSupplier;
    
    public ReferenceSlotMapper(final Supplier<T> slotSupplier) {
        this.list = new ObjectArrayList<T>();
        this.slotSupplier = slotSupplier;
    }
    
    public ReferenceSlotMapper(final Supplier<T> slotSupplier, final boolean trackNames) {
        super(trackNames);
        this.list = new ObjectArrayList<T>();
        this.slotSupplier = slotSupplier;
    }
    
    public T getReference(final String name) {
        final int slot = this.getSlot(name);
        if (slot < this.list.size()) {
            return this.list.get(slot);
        }
        final T object = this.slotSupplier.get();
        this.list.add(object);
        return object;
    }
    
    public List<T> getReferenceList() {
        return this.list;
    }
}
