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</code>.
029 *
030 * @since 2.1.1 and 3.1
031 * @version $Id: EmptyListIterator.html 972421 2015-11-14 20:00:04Z tn $
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<Object>();
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     * Get a typed instance of the iterator.
052     * @param <E> the element type
053     * @return {@link ResettableListIterator}<E>
054     */
055    @SuppressWarnings("unchecked")
056    public static <E> ResettableListIterator<E> resettableEmptyListIterator() {
057        return (ResettableListIterator<E>) RESETTABLE_INSTANCE;
058    }
059
060    /**
061     * Get a typed instance of the iterator.
062     * @param <E> the element type
063     * @return {@link ListIterator}<E>
064     */
065    @SuppressWarnings("unchecked")
066    public static <E> ListIterator<E> emptyListIterator() {
067        return (ListIterator<E>) INSTANCE;
068    }
069
070    /**
071     * Constructor.
072     */
073    protected EmptyListIterator() {
074        super();
075    }
076
077}