net.sf.javagimmicks.collections8.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.collections8.composite;
import java.util.AbstractList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Spliterator;
class CompositeList extends AbstractList
{
protected final List extends List> _lists;
CompositeList(final List extends List> lists)
{
_lists = lists;
}
@Override
public E get(int index)
{
for (final 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, final E element)
{
for (final 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 (final 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 (final List list : _lists)
{
result += list.size();
}
return result;
}
@Override
public ListIterator listIterator(final int index)
{
if (index < 0 || index > size())
{
throw new IndexOutOfBoundsException();
}
return new CompositeListIterator(_lists, index);
}
@Override
public Iterator iterator()
{
return CompositeIterator.fromCollectionList(_lists);
}
@Override
public Spliterator spliterator()
{
return CompositeSpliterator.fromCollectionList(_lists);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy