net.sf.javagimmicks.collections.composite.CompositeList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gimmicks Show documentation
Show all versions of gimmicks Show documentation
Utility classes, APIs and tools for Java
package net.sf.javagimmicks.collections.composite;
import java.util.AbstractList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
class CompositeList extends AbstractList
{
protected final List extends List> _lists;
CompositeList(List extends List> lists)
{
_lists = lists;
}
@Override
public E get(int index)
{
for(List list : _lists)
{
final int listSize = list.size();
if(index < listSize)
{
return list.get(index);
}
index -= listSize;
}
throw new IndexOutOfBoundsException();
}
@Override
public E set(int index, E element)
{
for(List list : _lists)
{
final int listSize = list.size();
if(index < listSize)
{
return list.set(index, element);
}
index -= listSize;
}
throw new IndexOutOfBoundsException();
}
@Override
public E remove(int index)
{
for(List list : _lists)
{
final int listSize = list.size();
if(index < listSize)
{
return list.remove(index);
}
index -= listSize;
}
throw new IndexOutOfBoundsException();
}
@Override
public int size()
{
int result = 0;
for(List list : _lists)
{
result += list.size();
}
return result;
}
@Override
public ListIterator listIterator(int index)
{
if(index < 0 || index > size())
{
throw new IndexOutOfBoundsException();
}
return new CompositeListIterator(_lists, index);
}
@Override
public Iterator iterator()
{
return CompositeIterator.fromCollectionList(_lists);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy