package com.datarecovery.master.utils;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.ArrayList;
import java.util.Collection;

public class ReverseArrayList<T> extends ArrayList<T> {

    public ReverseArrayList(int initialCapacity) {
        super(initialCapacity);
    }

    public ReverseArrayList() {
        super();
    }

    public ReverseArrayList(@NonNull Collection<? extends T> c) {
        super(c);
    }

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

    @Override
    public int indexOf(@Nullable Object o) {
        int index = super.indexOf(o);
        if (index == -1) {
            return index;
        }
        return size() - index - 1;
    }
}
