import java.util.ArrayList; public class SetBattleshipGeneric { private final ArrayList _places; private final int _maxCount; public int Count() { return _places.size(); } public SetBattleshipGeneric(int count) { _maxCount = count; _places = new ArrayList<>();; } public int Insert(T battleship) { return Insert(battleship, 0); } public int Insert(T battleship, int position) { if (position >= _maxCount|| position < 0) return -1; _places.add(position, battleship); return position; } public T Remove (int position) { if (position >= _places.size() || position < 0) return null; T result = _places.get(position); _places.remove(position); return result; } public T Get(int position) { if (position >= Count() || position < 0) { return null; } return _places.get(position); } public Iterable GetBattleships() { return _places; } }