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 */
017 package org.apache.commons.collections.iterators;
018
019 import 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 Commons Collections 3.0
027 * @version $Revision: 646777 $ $Date: 2008-04-10 13:33:15 +0100 (Thu, 10 Apr 2008) $
028 *
029 * @author Rodney Waldhoff
030 * @author Stephen Colebourne
031 */
032 public class AbstractListIteratorDecorator implements ListIterator {
033
034 /** The iterator being decorated */
035 protected final ListIterator iterator;
036
037 //-----------------------------------------------------------------------
038 /**
039 * Constructor that decorates the specified iterator.
040 *
041 * @param iterator the iterator to decorate, must not be null
042 * @throws IllegalArgumentException if the collection is null
043 */
044 public AbstractListIteratorDecorator(ListIterator iterator) {
045 super();
046 if (iterator == null) {
047 throw new IllegalArgumentException("ListIterator must not be null");
048 }
049 this.iterator = iterator;
050 }
051
052 /**
053 * Gets the iterator being decorated.
054 *
055 * @return the decorated iterator
056 */
057 protected ListIterator getListIterator() {
058 return iterator;
059 }
060
061 //-----------------------------------------------------------------------
062 public boolean hasNext() {
063 return iterator.hasNext();
064 }
065
066 public Object next() {
067 return iterator.next();
068 }
069
070 public int nextIndex() {
071 return iterator.nextIndex();
072 }
073
074 public boolean hasPrevious() {
075 return iterator.hasPrevious();
076 }
077
078 public Object previous() {
079 return iterator.previous();
080 }
081
082 public int previousIndex() {
083 return iterator.previousIndex();
084 }
085
086 public void remove() {
087 iterator.remove();
088 }
089
090 public void set(Object obj) {
091 iterator.set(obj);
092 }
093
094 public void add(Object obj) {
095 iterator.add(obj);
096 }
097
098 }