PIbd-12_Karamushko_M.K._Air.../SetAircraftsGeneric.java
2022-12-02 10:17:40 +03:00

51 lines
1.1 KiB
Java

import java.util.ArrayList;
import java.util.ListIterator;
public class SetAircraftsGeneric<T>
{
private ArrayList<T> _places;
private int _maxCount;
public int getCount() {
return _places.size();
}
public SetAircraftsGeneric(int count)
{
_places = new ArrayList<>();
_maxCount = count;
}
public int Insert(T aircraft)
{
if (_places.size() == _maxCount) return -1;
_places.add(0, aircraft);
return 0;
}
public int Insert(T aircraft, int position)
{
if (_places.size() == _maxCount) return -1;
_places.add(position, aircraft);
return position;
}
public T Remove(int position)
{
if(position > _maxCount || position < 0) return null;
T res = _places.get(position);
_places.remove(res);
return res;
}
public ListIterator<T> GetElems() {
return _places.listIterator();
}
public void Clear() {
_places.clear();
}
public T Get(int position)
{
return _places.get(position);
}
}