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);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-10-26 19:25:51 +02:00
|
|
|
public boolean contains(T obj)
|
|
|
|
{
|
|
|
|
return list.contains(obj);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-10-26 19:25:51 +02:00
|
|
|
public void clear()
|
|
|
|
{
|
|
|
|
list.clear();
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-10-26 19:25:51 +02:00
|
|
|
public T get(int index)
|
|
|
|
{
|
2013-10-27 16:44:19 +01:00
|
|
|
if(index > size()-1)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-10-26 19:25:51 +02:00
|
|
|
return list.get(index);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-10-26 19:25:51 +02:00
|
|
|
public void add(T obj)
|
|
|
|
{
|
|
|
|
if(!list.contains(obj))
|
|
|
|
{
|
|
|
|
list.add(obj);
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-10-26 19:25:51 +02:00
|
|
|
public void add(int index, T obj)
|
|
|
|
{
|
|
|
|
if(!list.contains(obj))
|
|
|
|
{
|
2013-11-24 19:12:42 +01:00
|
|
|
if(index > size())
|
|
|
|
{
|
|
|
|
for(int i = size(); i <= index-1; i++)
|
|
|
|
{
|
|
|
|
list.add(i, null);
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-10-26 19:25:51 +02:00
|
|
|
list.add(index, obj);
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-10-29 23:54:36 +01:00
|
|
|
public boolean isEmpty()
|
2013-10-27 22:47:17 +01:00
|
|
|
{
|
2013-10-29 23:54:36 +01:00
|
|
|
return list.isEmpty();
|
2013-10-27 22:47:17 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-10-29 23:54:36 +01:00
|
|
|
public void remove(int index)
|
2013-10-28 19:42:28 +01:00
|
|
|
{
|
2013-10-29 23:54:36 +01:00
|
|
|
if(isEmpty() || index > size()-1)
|
2013-10-28 19:42:28 +01:00
|
|
|
{
|
2013-10-29 23:54:36 +01:00
|
|
|
return;
|
2013-10-28 19:42:28 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-10-29 23:54:36 +01:00
|
|
|
list.remove(index);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-10-29 23:54:36 +01:00
|
|
|
public void replace(int index, T obj)
|
|
|
|
{
|
|
|
|
if(get(index) != null)
|
2013-10-28 19:42:28 +01:00
|
|
|
{
|
|
|
|
remove(index);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-10-28 19:42:28 +01:00
|
|
|
add(index, obj);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-10-27 22:47:17 +01:00
|
|
|
public void remove(T obj)
|
|
|
|
{
|
|
|
|
list.remove(obj);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-10-26 19:25:51 +02:00
|
|
|
public int indexOf(T obj)
|
|
|
|
{
|
|
|
|
return list.indexOf(obj);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-10-26 19:25:51 +02:00
|
|
|
public int size()
|
|
|
|
{
|
|
|
|
return list.size();
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-10-28 19:42:28 +01:00
|
|
|
@Override
|
|
|
|
public int hashCode()
|
|
|
|
{
|
|
|
|
return list.hashCode();
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-10-28 19:42:28 +01:00
|
|
|
@Override
|
|
|
|
public boolean equals(Object obj)
|
|
|
|
{
|
|
|
|
return list.equals(obj);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-10-26 19:25:51 +02:00
|
|
|
@Override
|
2014-03-08 02:00:25 +01:00
|
|
|
public Iterator iterator()
|
2013-10-26 19:25:51 +02:00
|
|
|
{
|
|
|
|
return list.iterator();
|
|
|
|
}
|
|
|
|
}
|