package com.kduda.battleships.models.units;

import java.util.ArrayList;

public enum UnitFactory {
    INSTANCE;
    ArrayList<Unit> units;

    UnitFactory() {
        initializeUnitsList();
    }

    public void initializeUnitsList() {
        units = new ArrayList<>();
        units.add(createGroundLevelUnit(UnitType.Ship, 4));

        units.add(createGroundLevelUnit(UnitType.Ship, 3));
        units.add(createGroundLevelUnit(UnitType.Ship, 3));

        units.add(createGroundLevelUnit(UnitType.Ship, 2));
        units.add(createGroundLevelUnit(UnitType.Ship, 2));
        units.add(createGroundLevelUnit(UnitType.Ship, 2));

        units.add(createGroundLevelUnit(UnitType.Ship, 1));
        units.add(createGroundLevelUnit(UnitType.Ship, 1));
        units.add(createGroundLevelUnit(UnitType.Ship, 1));

        units.add(createGroundLevelUnit(UnitType.Tank, 4));

        units.add(createGroundLevelUnit(UnitType.Tank, 3));
        units.add(createGroundLevelUnit(UnitType.Tank, 3));

        units.add(createGroundLevelUnit(UnitType.Tank, 2));
        units.add(createGroundLevelUnit(UnitType.Tank, 2));
        units.add(createGroundLevelUnit(UnitType.Tank, 2));

        units.add(createPlane());
        units.add(createPlane());
        units.add(createPlane());
    }

    public Unit createNextUnit() {

        return null;
    }

    Unit createGroundLevelUnit(UnitType type, int size) {
        switch (type) {
            case Ship:
                return new Ship(size);
            case Tank:
                return new Tank(size);
        }
        return null;
    }

    Unit createPlane() {
        return new Plane();
    }
}

@@ -65,16 +65,43 @@
 rayList;
+%0Aimport java.util.Iterator;
 %0A%0Apublic
@@ -160,16 +160,50 @@
 %3E units;
+%0A    Iterator%3CUnit%3E unitsIterator;
 %0A%0A    Un
@@ -254,27 +254,20 @@
 %0A    %7D%0A%0A
+
     
-public 
 void ini
@@ -1335,70 +1335,49 @@
 ));%0A
+%0A
     
-%7D%0A%0A
     
-public Unit createNextUnit() %7B%0A%0A        return null
+unitsIterator = units.iterator()
 ;%0A  
@@ -1683,11 +1683,166 @@
 );%0A    %7D
+%0A%0A    public Unit getNextUnit() %7B%0A        if (unitsIterator.hasNext())%0A            return unitsIterator.next();%0A        else%0A            return null;%0A    %7D
 %0A%7D%0A

Add factory implementation