package ru.job4j;

import java.util.Arrays;

public class SimpleArray<T> {

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

    public SimpleArray(int size) {
        this.objects = new Object[size];
    }

    public T add(T value) {
        if (index < objects.length) {
            this.objects[index++] = value;
            return value;
        } else {
            throw new ArrayIndexOutOfBoundsException();
        }
    }

    public T get(int pos) {
        if (pos >= 0 && pos < objects.length) {
            return (T) this.objects[pos];
        } else {
            throw new ArrayIndexOutOfBoundsException();
        }
    }

    public boolean delete(int pos) {
        if (pos >= 0 && pos < objects.length) {
            this.objects[pos] = null;
            return true;
        } else {
            return false;
        }
    }

    public T update(T value) {
        T oldValue = null;
        for (int i = 0; i < objects.length; i++) {
            if (value.equals(objects[i])) {
                oldValue = (T) objects[i];
                this.objects[i] = value;
            }
        }
        return oldValue;
    }
}

@@ -444,17 +444,31 @@
    p
-ublic T g
+rivate boolean correctS
 et(i
@@ -477,36 +477,39 @@
  pos) %7B%0A        
-if (
+return 
 pos %3E= 0 && pos 
@@ -516,32 +516,96 @@
 %3C objects.length
+;%0A    %7D%0A%0A    public T get(int pos) %7B%0A        if (correctSet(pos)
 ) %7B%0A            
@@ -777,40 +777,23 @@
 if (
-pos %3E= 0 && pos %3C objects.length
+correctSet(pos)
 ) %7B%0A

task 156