package ru.job4j;

import java.lang.reflect.ParameterizedType;
import java.util.NoSuchElementException;

/**
 * Task 5.2.1
 * Create generic
 *
 * @author Anton Vasilyuk
 * @version 1.0
 * @since 0.1
 */
public class SimpleList<T> {

    private Object[] objects;
    private int index = 0;

    public SimpleList(int size) {
        this.objects = new Object[size];
        //Class<T> t = (Class<T>) ((ParameterizedType) (getClass().getGenericSuperclass())).getActualTypeArguments()[0];
        //try {
        //    T value = t.newInstance();
         //   System.out.printf("string: +" + value);
        //} catch (Exception e) {
        //    e.printStackTrace();
        //}
    }

    public void add(T value) {
        if (value == null) {throw new NullPointerException("Element is null");}
        if (validate()) {
            this.objects[index++] = value;
        } else {
            throw new ArrayIndexOutOfBoundsException("Too far");
        }
    }

    public T get (int position) {
        return (T) this.objects[position];
    }

    public void update(int position, T value) {
        if (value != null) {
            this.objects[position] = value;
        } else {throw new NullPointerException("this value is null");}
    }

    public void delete(int position) {

        if (this.objects[position] != null) {
            this.objects[position] = null;
        } else {
            throw new NoSuchElementException("In this no element");
        }
        index--;
    }

    public boolean validate() {
        return this.objects.length > index;
    }
}
@@ -365,320 +365,8 @@
 %5D;%0A 
-       //Class%3CT%3E t = (Class%3CT%3E) ((ParameterizedType) (getClass().getGenericSuperclass())).getActualTypeArguments()%5B0%5D;%0A        //try %7B%0A        //    T value = t.newInstance();%0A         //   System.out.printf(%22string: +%22 + value);%0A        //%7D catch (Exception e) %7B%0A        //    e.printStackTrace();%0A        //%7D%0A
     

add file for chapter_003_5.2.1