2022-11-25 13:49:46 +04:00
|
|
|
import java.util.ArrayList;
|
2022-12-02 11:17:40 +04:00
|
|
|
import java.util.ListIterator;
|
2022-11-25 13:49:46 +04:00
|
|
|
|
2022-11-15 18:20:34 +04:00
|
|
|
public class SetAircraftsGeneric<T>
|
|
|
|
{
|
2022-11-25 13:49:46 +04:00
|
|
|
private ArrayList<T> _places;
|
|
|
|
private int _maxCount;
|
2022-11-15 18:20:34 +04:00
|
|
|
public int getCount() {
|
2022-11-25 13:49:46 +04:00
|
|
|
return _places.size();
|
2022-11-15 18:20:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public SetAircraftsGeneric(int count)
|
|
|
|
{
|
2022-11-25 13:49:46 +04:00
|
|
|
_places = new ArrayList<>();
|
|
|
|
_maxCount = count;
|
2022-11-15 18:20:34 +04:00
|
|
|
}
|
2022-11-25 13:49:46 +04:00
|
|
|
public int Insert(T aircraft)
|
2022-11-15 18:20:34 +04:00
|
|
|
{
|
2022-11-25 13:49:46 +04:00
|
|
|
if (_places.size() == _maxCount) return -1;
|
|
|
|
_places.add(0, aircraft);
|
|
|
|
return 0;
|
2022-11-15 18:20:34 +04:00
|
|
|
}
|
2022-11-25 13:49:46 +04:00
|
|
|
public int Insert(T aircraft, int position)
|
2022-11-15 18:20:34 +04:00
|
|
|
{
|
2022-11-25 13:49:46 +04:00
|
|
|
if (_places.size() == _maxCount) return -1;
|
|
|
|
_places.add(position, aircraft);
|
2022-11-15 18:20:34 +04:00
|
|
|
return position;
|
|
|
|
}
|
|
|
|
|
|
|
|
public T Remove(int position)
|
|
|
|
{
|
2022-11-25 13:49:46 +04:00
|
|
|
if(position > _maxCount || position < 0) return null;
|
|
|
|
T res = _places.get(position);
|
|
|
|
_places.remove(res);
|
2022-11-15 18:20:34 +04:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2022-12-02 11:17:40 +04:00
|
|
|
public ListIterator<T> GetElems() {
|
|
|
|
return _places.listIterator();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Clear() {
|
|
|
|
_places.clear();
|
|
|
|
}
|
|
|
|
|
2022-11-15 18:20:34 +04:00
|
|
|
public T Get(int position)
|
|
|
|
{
|
2022-11-25 13:49:46 +04:00
|
|
|
return _places.get(position);
|
2022-11-15 18:20:34 +04:00
|
|
|
}
|
|
|
|
}
|