Mekanism-tilera-Edition/src/main/java/mekanism/common/HashList.java

112 lines
1.3 KiB
Java
Raw Normal View History

2013-10-26 19:25:51 +02:00
package mekanism.common;
import java.util.ArrayList;
import java.util.Iterator;
public class HashList<T> implements Iterable<T>
{
2013-11-02 17:00:29 +01:00
private ArrayList<T> list = new ArrayList<T>(256);
2013-10-26 19:25:51 +02:00
public boolean contains(T obj)
{
return list.contains(obj);
}
2013-10-26 19:25:51 +02:00
public void clear()
{
list.clear();
}
2013-10-26 19:25:51 +02:00
public T get(int index)
{
if(index > size()-1)
{
return null;
}
2013-10-26 19:25:51 +02:00
return list.get(index);
}
2013-10-26 19:25:51 +02:00
public void add(T obj)
{
if(!list.contains(obj))
{
list.add(obj);
}
}
2013-10-26 19:25:51 +02:00
public void add(int index, T obj)
{
if(!list.contains(obj))
{
if(index > size())
{
for(int i = size(); i <= index-1; i++)
{
list.add(i, null);
}
}
2013-10-26 19:25:51 +02:00
list.add(index, obj);
}
}
public boolean isEmpty()
2013-10-27 22:47:17 +01:00
{
return list.isEmpty();
2013-10-27 22:47:17 +01:00
}
public void remove(int index)
{
if(isEmpty() || index > size()-1)
{
return;
}
list.remove(index);
}
public void replace(int index, T obj)
{
if(get(index) != null)
{
remove(index);
}
add(index, obj);
}
2013-10-27 22:47:17 +01:00
public void remove(T obj)
{
list.remove(obj);
}
2013-10-26 19:25:51 +02:00
public int indexOf(T obj)
{
return list.indexOf(obj);
}
2013-10-26 19:25:51 +02:00
public int size()
{
return list.size();
}
@Override
public int hashCode()
{
return list.hashCode();
}
@Override
public boolean equals(Object obj)
{
return list.equals(obj);
}
2013-10-26 19:25:51 +02:00
@Override
public Iterator iterator()
2013-10-26 19:25:51 +02:00
{
return list.iterator();
}
}