/**
 * The MIT License (MIT)
 *
 * Copyright (c) 2015 Yegor Bugayenko
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package org.takes.misc;

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

/**
 * Verbose List that wraps OutOfBoundsException with custom message.
 *
 * @author I. Sokolov (happy.neko@gmail.com)
 * @version $Id$
 * @param <T> Type of item
 */
@SuppressWarnings("PMD.TooManyMethods")
public final class VerboseList<T> implements List<T> {

    /**
     * Original list.
     */
    private final transient List<T> origin;

    /**
     * Error message for IndexOutOfBoundsException.
     */
    private final transient String message;

    /**
     * Ctor.
     * @param list Original list
     * @param msg Error message for IndexOutOfBoundsException
     */
    public VerboseList(final List<T> list, final String msg) {
        this.origin = list;
        this.message = msg;
    }

    @Override
    public int size() {
        return this.origin.size();
    }

    @Override
    public boolean isEmpty() {
        return this.origin.isEmpty();
    }

    @Override
    public boolean contains(final Object obj) {
        return this.origin.contains(obj);
    }

    @Override
    public Iterator<T> iterator() {
        return new VerboseIterator<T>(this.origin.iterator(), this.message);
    }

    @Override
    public Object[] toArray() {
        return this.origin.toArray();
    }

    @SuppressWarnings("PMD.UseVarargs")
    @Override
    public <E> E[] toArray(final E[] arr) {
        return this.origin.toArray(arr);
    }

    @Override
    public boolean add(final T item) {
        return this.origin.add(item);
    }

    @Override
    public boolean remove(final Object obj) {
        return this.origin.remove(obj);
    }

    @Override
    public boolean containsAll(final Collection<?> coll) {
        return this.origin.containsAll(coll);
    }

    @Override
    public boolean addAll(final Collection<? extends T> coll) {
        return this.origin.addAll(coll);
    }

    @Override
    public boolean addAll(final int index, final Collection<? extends T> coll) {
        try {
            return this.origin.addAll(index, coll);
        } catch (final IndexOutOfBoundsException ex) {
            throw wrapException(this.message, ex);
        }
    }

    @Override
    public boolean removeAll(final Collection<?> coll) {
        return this.origin.removeAll(coll);
    }

    @Override
    public boolean retainAll(final Collection<?> coll) {
        return this.origin.retainAll(coll);
    }

    @Override
    public void clear() {
        this.origin.clear();
    }

    @Override
    public T get(final int index) {
        try {
            return this.origin.get(index);
        } catch (final IndexOutOfBoundsException ex) {
            throw wrapException(this.message, ex);
        }
    }

    @Override
    public T set(final int index, final T element) {
        try {
            return this.origin.set(index, element);
        } catch (final IndexOutOfBoundsException ex) {
            throw wrapException(this.message, ex);
        }
    }

    @Override
    public void add(final int index, final T element) {
        try {
            this.origin.add(index, element);
        } catch (final IndexOutOfBoundsException ex) {
            throw wrapException(this.message, ex);
        }
    }

    @Override
    public T remove(final int index) {
        try {
            return this.origin.remove(index);
        } catch (final IndexOutOfBoundsException ex) {
            throw wrapException(this.message, ex);
        }
    }

    @Override
    public int indexOf(final Object obj) {
        return this.origin.indexOf(obj);
    }

    @Override
    public int lastIndexOf(final Object obj) {
        return this.origin.lastIndexOf(obj);
    }

    @Override
    public ListIterator<T> listIterator() {
        return this.origin.listIterator();
    }

    @Override
    public ListIterator<T> listIterator(final int index) {
        try {
            return this.origin.listIterator(index);
        } catch (final IndexOutOfBoundsException ex) {
            throw wrapException(this.message, ex);
        }
    }

    @Override
    public List<T> subList(final int fridx, final int toidx) {
        try {
            return this.origin.subList(fridx, toidx);
        } catch (final IndexOutOfBoundsException ex) {
            throw wrapException(this.message, ex);
        }
    }

    /**
     * Wraps {@link IndexOutOfBoundsException} with custom message.
     * @param msg Error message
     * @param cause Original exception
     * @return Wrapped exception
     */
    private static IndexOutOfBoundsException wrapException(final String msg,
        final IndexOutOfBoundsException cause) {
        final IndexOutOfBoundsException ex =
            new IndexOutOfBoundsException(msg);
        ex.initCause(cause);
        return ex;
    }
}

@@ -3326,32 +3326,37 @@
           throw 
+this.
 wrapException(th
@@ -3349,38 +3349,24 @@
 apException(
-this.message, 
 ex);%0A       
@@ -3867,32 +3867,37 @@
           throw 
+this.
 wrapException(th
@@ -3890,38 +3890,24 @@
 apException(
-this.message, 
 ex);%0A       
@@ -4114,32 +4114,37 @@
           throw 
+this.
 wrapException(th
@@ -4137,38 +4137,24 @@
 apException(
-this.message, 
 ex);%0A       
@@ -4357,32 +4357,37 @@
           throw 
+this.
 wrapException(th
@@ -4380,38 +4380,24 @@
 apException(
-this.message, 
 ex);%0A       
@@ -4584,32 +4584,37 @@
           throw 
+this.
 wrapException(th
@@ -4607,38 +4607,24 @@
 apException(
-this.message, 
 ex);%0A       
@@ -5163,32 +5163,37 @@
           throw 
+this.
 wrapException(th
@@ -5186,38 +5186,24 @@
 apException(
-this.message, 
 ex);%0A       
@@ -5430,16 +5430,21 @@
   throw 
+this.
 wrapExce
@@ -5453,22 +5453,8 @@
 ion(
-this.message, 
 ex);
@@ -5551,40 +5551,8 @@
 ge.%0A
-     * @param msg Error message%0A
     
@@ -5643,15 +5643,8 @@
 ate 
-static 
 Inde
@@ -5683,25 +5683,8 @@
 ion(
-final String msg,
 %0A   
@@ -5816,19 +5816,28 @@
 ception(
-msg
+this.message
 );%0A     

make wrapException method private