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
021import org.apache.commons.collections4.ResettableListIterator;
022
023/**
024 * Provides an implementation of an empty list iterator.
025 * <p>
026 * This class provides an implementation of an empty list iterator. This class
027 * provides for binary compatibility between Commons Collections 2.1.1 and 3.1
028 * due to issues with {@code IteratorUtils}.
029 *
030 * @param <E> the type of elements returned by this iterator.
031 * @since 2.1.1 and 3.1
032 */
033public class EmptyListIterator<E> extends AbstractEmptyIterator<E> implements
034        ResettableListIterator<E> {
035
036    /**
037     * Singleton instance of the iterator.
038     * @since 3.1
039     */
040    @SuppressWarnings("rawtypes")
041    public static final ResettableListIterator RESETTABLE_INSTANCE = new EmptyListIterator<>();
042
043    /**
044     * Singleton instance of the iterator.
045     * @since 2.1.1 and 3.1
046     */
047    @SuppressWarnings("rawtypes")
048    public static final ListIterator INSTANCE = RESETTABLE_INSTANCE;
049
050    /**
051     * Gets a typed instance of the iterator.
052     * @param <E> the element type
053     * @return {@link ListIterator}&lt;E&gt;
054     */
055    public static <E> ListIterator<E> emptyListIterator() {
056        return INSTANCE;
057    }
058
059    /**
060     * Gets a typed instance of the iterator.
061     * @param <E> the element type
062     * @return {@link ResettableListIterator}&lt;E&gt;
063     */
064    public static <E> ResettableListIterator<E> resettableEmptyListIterator() {
065        return RESETTABLE_INSTANCE;
066    }
067
068    /**
069     * Constructs a new instance.
070     */
071    protected EmptyListIterator() {
072    }
073
074}