diff --git a/src/main/java/MapWithSetArmoredCarsGeneric.java b/src/main/java/MapWithSetArmoredCarsGeneric.java index 3faf4c4..f9c72cc 100644 --- a/src/main/java/MapWithSetArmoredCarsGeneric.java +++ b/src/main/java/MapWithSetArmoredCarsGeneric.java @@ -25,14 +25,14 @@ public class MapWithSetArmoredCarsGeneric map, T car) + public int add(T car) { - return map._setCars.Insert(car); + return _setCars.Insert(car); } - public T remove(MapWithSetArmoredCarsGeneric map, int position) + public T remove(int position) { - return map._setCars.Remove(position); + return _setCars.Remove(position); } public Image ShowSet() diff --git a/src/main/java/SetArmoredCarsGeneric.java b/src/main/java/SetArmoredCarsGeneric.java index 96fac64..080961d 100644 --- a/src/main/java/SetArmoredCarsGeneric.java +++ b/src/main/java/SetArmoredCarsGeneric.java @@ -3,27 +3,22 @@ import java.util.ArrayList; public class SetArmoredCarsGeneric { private T[] _places; - public int Count = _places.length; + public int Count = getCount(); public SetArmoredCarsGeneric(int count) { _places = (T[]) new Object[count]; } - /// - /// Добавление объекта в набор - /// - /// Добавляемый автомобиль - /// + + public int getCount() { + return _places != null ? _places.length : 0; + } + public int Insert(T armoredCar) { return Insert(armoredCar, 0); } - /// - /// Добавление объекта в набор на конкретную позицию - /// - /// Добавляемый автомобиль - /// Позиция - /// + public int Insert(T armoredCar, int position) { if (position < 0 || position >= Count) @@ -53,11 +48,7 @@ public class SetArmoredCarsGeneric { _places[position] = armoredCar; return position; } - /// - /// Удаление объекта из набора с конкретной позиции - /// - /// - /// + public T Remove(int position) { if (position < 0 || position >= Count) @@ -66,11 +57,7 @@ public class SetArmoredCarsGeneric { _places[position] = null; return armoredCar; } - /// - /// Получение объекта из набора по позиции - /// - /// - /// + public T Get(int position) { if (position < 0 || position >= Count)