All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scorex.util.Collections Maven / Gradle / Ivy

The newest version!
package scorex.util;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class Collections {
    private Collections() {
    }

    public static  List unmodifiableList(List list) {
        return new UnmodifiableList<>(list);
    }

    private static class UnmodifiableList implements List {
        final List list;

        UnmodifiableList(List list) {
            this.list = list;
        }

        public boolean equals(Object o) {return o == this || list.equals(o);}
        public int hashCode()           {return list.hashCode();}

        public E get(int index) {return list.get(index);}
        public E set(int index, E element) {
            throw new UnsupportedOperationException();
        }
        public void add(int index, E element) {
            throw new UnsupportedOperationException();
        }
        public E remove(int index) {
            throw new UnsupportedOperationException();
        }
        public int indexOf(Object o)            {return list.indexOf(o);}
        public int lastIndexOf(Object o)        {return list.lastIndexOf(o);}
        public boolean addAll(int index, Collection c) {
            throw new UnsupportedOperationException();
        }

        public ListIterator listIterator()   {return listIterator(0);}

        public ListIterator listIterator(final int index) {
            return new ListIterator() {
                private final ListIterator i
                        = list.listIterator(index);

                public boolean hasNext()     {return i.hasNext();}
                public E next()              {return i.next();}
                public boolean hasPrevious() {return i.hasPrevious();}
                public E previous()          {return i.previous();}
                public int nextIndex()       {return i.nextIndex();}
                public int previousIndex()   {return i.previousIndex();}

                public void remove() {
                    throw new UnsupportedOperationException();
                }
                public void set(E e) {
                    throw new UnsupportedOperationException();
                }
                public void add(E e) {
                    throw new UnsupportedOperationException();
                }
            };
        }

        public List subList(int fromIndex, int toIndex) {
            return new UnmodifiableList<>(list.subList(fromIndex, toIndex));
        }

        public int size()                          {return list.size();}
        public boolean isEmpty()                   {return list.isEmpty();}
        public boolean contains(Object o)          {return list.contains(o);}
        public Object[] toArray()                  {return list.toArray();}
        public  T[] toArray(T[] a)              {return list.toArray(a);}
        public String toString()                   {return list.toString();}

        public Iterator iterator() {
            return new Iterator() {
                private final Iterator i = list.iterator();

                public boolean hasNext() {return i.hasNext();}
                public E next()          {return i.next();}
                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }

        public boolean add(E e) {
            throw new UnsupportedOperationException();
        }
        public boolean remove(Object o) {
            throw new UnsupportedOperationException();
        }
        public boolean containsAll(Collection coll) {
            return list.containsAll(coll);
        }
        public boolean addAll(Collection coll) {
            throw new UnsupportedOperationException();
        }
        public boolean removeAll(Collection coll) {
            throw new UnsupportedOperationException();
        }
        public boolean retainAll(Collection coll) {
            throw new UnsupportedOperationException();
        }
        public void clear() {
            throw new UnsupportedOperationException();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy