001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  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.apache.commons.collections4.iterators;
018
019import java.util.ListIterator;
020
021/**
022 * Provides basic behaviour for decorating a list iterator with extra functionality.
023 * <p>
024 * All methods are forwarded to the decorated list iterator.
025 *
026 * @since 3.0
027 * @version $Id: AbstractListIteratorDecorator.html 972421 2015-11-14 20:00:04Z tn $
028 */
029public class AbstractListIteratorDecorator<E> implements ListIterator<E> {
030
031    /** The iterator being decorated */
032    private final ListIterator<E> iterator;
033
034    //-----------------------------------------------------------------------
035    /**
036     * Constructor that decorates the specified iterator.
037     *
038     * @param iterator  the iterator to decorate, must not be null
039     * @throws IllegalArgumentException if the collection is null
040     */
041    public AbstractListIteratorDecorator(final ListIterator<E> iterator) {
042        super();
043        if (iterator == null) {
044            throw new IllegalArgumentException("ListIterator must not be null");
045        }
046        this.iterator = iterator;
047    }
048
049    /**
050     * Gets the iterator being decorated.
051     *
052     * @return the decorated iterator
053     */
054    protected ListIterator<E> getListIterator() {
055        return iterator;
056    }
057
058    //-----------------------------------------------------------------------
059
060    /** {@inheritDoc} */
061    public boolean hasNext() {
062        return iterator.hasNext();
063    }
064
065    /** {@inheritDoc} */
066    public E next() {
067        return iterator.next();
068    }
069
070    /** {@inheritDoc} */
071    public int nextIndex() {
072        return iterator.nextIndex();
073    }
074
075    /** {@inheritDoc} */
076    public boolean hasPrevious() {
077        return iterator.hasPrevious();
078    }
079
080    /** {@inheritDoc} */
081    public E previous() {
082        return iterator.previous();
083    }
084
085    /** {@inheritDoc} */
086    public int previousIndex() {
087        return iterator.previousIndex();
088    }
089
090    /** {@inheritDoc} */
091    public void remove() {
092        iterator.remove();
093    }
094
095    /** {@inheritDoc} */
096    public void set(final E obj) {
097        iterator.set(obj);
098    }
099
100    /** {@inheritDoc} */
101    public void add(final E obj) {
102        iterator.add(obj);
103    }
104
105}