package net.ranides.assira.collection.lists;

import java.util.List;

/**
 * Immutable view of list, providing elements in reversed order.
 *
 * Please note, that it impossible to implement mutable reversed list in reasonable way, because
 * #add operation shifts elements always in one direction (forward).
 *
 * @param <T> T
 */
public class ReversedList<T> extends VirtualList<T> {

    private final List<T> content;

    /**
     * Creates new reversed view backed by provided list.
     * @param content content
     */
    public ReversedList(List<T> content) {
        this.content = content;
    }

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

    @Override
    public T get(int index) {
        return content.get(content.size() - index - 1);
    }

}
