package carray;

public class CArray {
    protected static class BaseArray<E> {
        protected E[] elems;

        @SuppressWarnings("unchecked")
        protected BaseArray(int capacity) {
            elems = (E[]) new Object[capacity];
        }

        public E get(int index) {
            return elems[index];
        }

        protected E set(int index, E e) {
            return elems[index] = e;
        }
    }

    public static class ConstArray<E> extends BaseArray<E> {
        public ConstArray(int capacity) {
            super(capacity);
        }
    }

    public static class Array<E> extends ConstArray<E> {
        public Array(int capacity) {
            super(capacity);
        }

        @Override
        public E set(int index, E e) {
            return super.set(index, e);
        }

        public static <E> Array<E> init(E[] a) {
            Array<E> res = new Array<E>(a.length);
            for (int i = 0; i < a.length; i++)
                res.set(i, a[i]);
            return res;
        }
    }

    public static class ConstArray_int extends BaseArray<Integer> {
        public ConstArray_int(int capacity) {
            super(capacity);
        }
    }

    public static class Array_int extends ConstArray_int {
        public Array_int(int capacity) {
            super(capacity);
        }

        @Override
        public Integer set(int index, Integer e) {
            return super.set(index, e);
        }

        public static Array_int init(int[] a) {
            Array_int res = new Array_int(a.length);
            for (int i = 0; i < a.length; i++)
                res.set(i, a[i]);
            return res;
        }
    }

    // TODO: Classes for arrays on other primitive types.
}
