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