/* This file is part of Cyclos (www.cyclos.org). A project of the Social Trade Organisation (www.socialtrade.org). Cyclos is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Cyclos is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Cyclos; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package nl.strohalm.cyclos.utils; import java.util.Collection; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.ListIterator; import nl.strohalm.cyclos.utils.query.IteratorList; /** * Basic implementation for iterator lists, using a delegate iterator * @author luis */ public class IteratorListImpl<E> implements IteratorList<E> { protected Iterator<E> iterator; private final boolean empty; public IteratorListImpl(final Iterator<E> iterator) { this.iterator = iterator; this.empty = !iterator.hasNext(); } @Override public boolean add(final E o) { throw new UnsupportedOperationException(); } @Override public void add(final int index, final E element) { throw new UnsupportedOperationException(); } @Override public boolean addAll(final Collection<? extends E> c) { throw new UnsupportedOperationException(); } @Override public boolean addAll(final int index, final Collection<? extends E> c) { throw new UnsupportedOperationException(); } @Override public void clear() { throw new UnsupportedOperationException(); } @Override public boolean contains(final Object o) { throw new UnsupportedOperationException(); } @Override public boolean containsAll(final Collection<?> c) { throw new UnsupportedOperationException(); } @Override public E get(final int index) { throw new UnsupportedOperationException(); } @Override public Iterator<E> getIterator() { return iterator; } @Override public boolean hasNext() { return iterator.hasNext(); } @Override public int indexOf(final Object o) { throw new UnsupportedOperationException(); } @Override public boolean isEmpty() { return empty; } @Override public Iterator<E> iterator() { return this; } @Override public int lastIndexOf(final Object o) { throw new UnsupportedOperationException(); } @Override public ListIterator<E> listIterator() { throw new UnsupportedOperationException(); } @Override public ListIterator<E> listIterator(final int index) { throw new UnsupportedOperationException(); } @Override public E next() { return iterator.next(); } @Override public void remove() { throw new UnsupportedOperationException(); } @Override public E remove(final int index) { throw new UnsupportedOperationException(); } @Override public boolean remove(final Object o) { throw new UnsupportedOperationException(); } @Override public boolean removeAll(final Collection<?> c) { throw new UnsupportedOperationException(); } @Override public boolean retainAll(final Collection<?> c) { throw new UnsupportedOperationException(); } @Override public E set(final int index, final E element) { throw new UnsupportedOperationException(); } @Override public int size() { throw new UnsupportedOperationException(); } @Override public List<E> subList(final int fromIndex, final int toIndex) { throw new UnsupportedOperationException(); } @Override public Object[] toArray() { final List<E> list = new LinkedList<E>(); for (final E e : this) { list.add(e); } return list.toArray(); } @Override @SuppressWarnings("unchecked") public <T> T[] toArray(final T[] a) { final List<T> list = new LinkedList<T>(); for (final E e : this) { list.add((T) e); } return list.toArray(a); } }