001/*-------------------------------------------------------------------------+
002|                                                                          |
003| Copyright 2005-2011 The ConQAT Project                                   |
004|                                                                          |
005| Licensed under the Apache License, Version 2.0 (the "License");          |
006| you may not use this file except in compliance with the License.         |
007| You may obtain a copy of the License at                                  |
008|                                                                          |
009|    http://www.apache.org/licenses/LICENSE-2.0                            |
010|                                                                          |
011| Unless required by applicable law or agreed to in writing, software      |
012| distributed under the License is distributed on an "AS IS" BASIS,        |
013| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
014| See the License for the specific language governing permissions and      |
015| limitations under the License.                                           |
016+-------------------------------------------------------------------------*/
017package org.conqat.lib.commons.collections;
018
019import java.util.ListIterator;
020
021/**
022 * This is a wrapper for a {@link ListIterator} prohibiting all calls which
023 * would modify its owning container. All prohibited methods throw an
024 * {@link UnsupportedOperationException}.
025 * 
026 * @author Benjamin Hummel
027 */
028public class UnmodifiableListIterator<T> extends UnmodifiableIterator<T> implements ListIterator<T> {
029
030        /** The underlying iterator. */
031        private final ListIterator<T> i;
032
033        /**
034         * Creates a new unmodifiable list iterator from another list iterator. All
035         * modifications to the underlying iterator will directly be visible in this
036         * wrapper.
037         */
038        public UnmodifiableListIterator(ListIterator<T> i) {
039                super(i);
040                this.i = i;
041        }
042
043        /** {@inheritDoc} */
044        @Override
045        public boolean hasPrevious() {
046                return i.hasPrevious();
047        }
048
049        /** {@inheritDoc} */
050        @Override
051        public int nextIndex() {
052                return i.nextIndex();
053        }
054
055        /** {@inheritDoc} */
056        @Override
057        public T previous() {
058                return i.previous();
059        }
060
061        /** {@inheritDoc} */
062        @Override
063        public int previousIndex() {
064                return i.previousIndex();
065        }
066
067        /**
068         * Operation is not supported.
069         */
070        @Override
071        public void add(T o) {
072                throw new UnsupportedOperationException();
073        }
074
075        /**
076         * Operation is not supported.
077         */
078        @Override
079        public void set(T o) {
080                throw new UnsupportedOperationException();
081        }
082
083}