package ru.job4j.set.setonaarrays;
import java.util.Arrays;
import java.util.Iterator;
import java.util.NoSuchElementException;

public class SimpleSet<T> implements Iterable<T>, Comparable<T> {

    private Object[] container;
    private int size =0;

    public SimpleSet() {
        container = new Object[3];
    }

    public SimpleSet(int capacity) {
        container = new Object[capacity];
    }

    public void add(T value) {
        boolean ad = true;
        if (size == 0)
            container[size++] = value;
        for (Object el : container) {
            if (el != null && ((T)el).equals(value))
                ad = false;
        }
        if (ad) {
            container[size++] = value;
        }
        if (size == container.length)
            increaseContainer();
    }

    public void sort() {
        deleteNull();
        Arrays.sort(container);
    }

    public void increaseContainer() {
        this.container = Arrays.copyOf(container, container.length * 2);
    }

    public void deleteNull() {
        int count = 0;
        for (Object ob : container) {
            if (ob == null)
                count++;
        }
        this.container = Arrays.copyOf(container, container.length - count);
    }

    @Override
    public Iterator<T> iterator() {
        return new Itr();
    }

    @Override
    public int compareTo(T o) {

        return this.compareTo(o);
    }

    private class Itr<T> implements Iterator<T> {
        private int count = 0;
        @Override
        public boolean hasNext() {

            return count < size;
        }

        @Override
        public T next() {
            if (!hasNext())
                throw new NoSuchElementException();
            return (T)container[count++];
        }
    }
}

@@ -443,88 +443,152 @@
     
-boolean ad = true;%0A        if (size == 0)%0A            container%5Bsize++%5D = value;
+ensureCapacity();%0A        if (!contains(value)) %7B%0A            container%5Bsize++%5D = value;%0A        %7D%0A    %7D%0A%0A    public boolean contains(T value) %7B
 %0A   
@@ -695,17 +695,18 @@
     
-ad = fals
+return tru
 e;%0A 
@@ -726,134 +726,105 @@
     
-if (ad) %7B%0A            container%5Bsize++%5D = valu
+return fals
 e;%0A    
+%7D%0A%0A
     
-%7D%0A        if (size == container.length)%0A            increaseC
+public void sort() %7B%0A        deleteNull();%0A        Arrays.sort(c
 ontainer
 ();%0A
@@ -819,17 +819,16 @@
 ontainer
-(
 );%0A    %7D
@@ -849,68 +849,94 @@
 oid 
-sort() %7B%0A        deleteNull();%0A        Arrays.sort(c
+ensureCapacity() %7B%0A        if (size == container.length)%0A            increaseC
 ontainer
 );%0A 
@@ -923,32 +923,33 @@
 ncreaseContainer
+(
 );%0A    %7D%0A%0A    pu

task 996