Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.*;

public class Main {
    /**
     * Returns a list iterator that swaps all previous/next calls.
     * <p><b>Important:</b> The returned iterator violates the {@link ListIterator#nextIndex()} and {@link ListIterator#previousIndex()} specifications.
     */
    public static <E> ListIterator<E> reverse(ListIterator<E> iterator) {
        return new ListIterator<E>() {
            @Override
            public boolean hasNext() {
                return iterator.hasPrevious();
            }

            @Override
            public E next() {
                return iterator.previous();
            }

            @Override
            public boolean hasPrevious() {
                return iterator.hasNext();
            }

            @Override
            public E previous() {
                return iterator.next();
            }

            @Override
            public int nextIndex() {
                return iterator.previousIndex();
            }

            @Override
            public int previousIndex() {
                return iterator.nextIndex();
            }

            @Override
            public void remove() {
                iterator.remove();
            }

            @Override
            public void set(E e) {
                iterator.set(e);
            }

            @Override
            public void add(E e) {
                iterator.add(e);
            }
        };
    }
}