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; 020import java.util.Objects; 021 022/** 023 * Provides basic behavior for decorating a list iterator with extra functionality. 024 * <p> 025 * All methods are forwarded to the decorated list iterator. 026 * </p> 027 * 028 * @param <E> the type of elements in this iterator. 029 * @since 3.0 030 */ 031public class AbstractListIteratorDecorator<E> implements ListIterator<E> { 032 033 /** The iterator being decorated */ 034 private final ListIterator<E> iterator; 035 036 /** 037 * Constructor that decorates the specified iterator. 038 * 039 * @param iterator the iterator to decorate, must not be null 040 * @throws NullPointerException if the iterator is null 041 */ 042 public AbstractListIteratorDecorator(final ListIterator<E> iterator) { 043 this.iterator = Objects.requireNonNull(iterator, "iterator"); 044 } 045 046 /** {@inheritDoc} */ 047 @Override 048 public void add(final E obj) { 049 iterator.add(obj); 050 } 051 052 /** 053 * Gets the iterator being decorated. 054 * 055 * @return the decorated iterator 056 */ 057 protected ListIterator<E> getListIterator() { 058 return iterator; 059 } 060 061 /** {@inheritDoc} */ 062 @Override 063 public boolean hasNext() { 064 return iterator.hasNext(); 065 } 066 067 /** {@inheritDoc} */ 068 @Override 069 public boolean hasPrevious() { 070 return iterator.hasPrevious(); 071 } 072 073 /** {@inheritDoc} */ 074 @Override 075 public E next() { 076 return iterator.next(); 077 } 078 079 /** {@inheritDoc} */ 080 @Override 081 public int nextIndex() { 082 return iterator.nextIndex(); 083 } 084 085 /** {@inheritDoc} */ 086 @Override 087 public E previous() { 088 return iterator.previous(); 089 } 090 091 /** {@inheritDoc} */ 092 @Override 093 public int previousIndex() { 094 return iterator.previousIndex(); 095 } 096 097 /** {@inheritDoc} */ 098 @Override 099 public void remove() { 100 iterator.remove(); 101 } 102 103 /** {@inheritDoc} */ 104 @Override 105 public void set(final E obj) { 106 iterator.set(obj); 107 } 108 109}