Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/* Copyright (c) 2014 Karol Stasiak
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 */

import java.util.*;
import javax.annotation.Nonnull;

public class Main {
    /**
     * Wraps an <code>ListIterator</code> and returns a <code>ListIterator</code>
     * that cannot modify the underlying list.
     * All methods that could be used to modify the list throw
     * <code>UnsupportedOperationException</code>
     * @param underlying original list iterator
     * @param <T> element type
     * @return unmodifiable list iterator
     */
    @Nonnull
    public static <T> ListIterator<T> unmodifiableListIterator(final @Nonnull ListIterator<T> underlying) {
        return new ListIterator<T>() {
            public boolean hasNext() {
                return underlying.hasNext();
            }

            public T next() {
                return underlying.next();
            }

            public boolean hasPrevious() {
                return underlying.hasPrevious();
            }

            public T previous() {
                return underlying.previous();
            }

            public int nextIndex() {
                return underlying.nextIndex();
            }

            public int previousIndex() {
                return underlying.previousIndex();
            }

            public void remove() {
                throw new UnsupportedOperationException();
            }

            public void set(T t) {
                throw new UnsupportedOperationException();
            }

            public void add(T t) {
                throw new UnsupportedOperationException();
            }
        };
    }
}