53 lines
1.3 KiB
Java
53 lines
1.3 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) throws StorageOverflowException
|
|
{
|
|
if (_places.size() == _maxCount) throw new StorageOverflowException(_maxCount);
|
|
_places.add(0, aircraft);
|
|
return 0;
|
|
}
|
|
public int Insert(T aircraft, int position) throws StorageOverflowException
|
|
{
|
|
if (_places.size() == _maxCount) throw new StorageOverflowException(_maxCount);
|
|
_places.add(position, aircraft);
|
|
return position;
|
|
}
|
|
|
|
public T Remove(int position) throws AircraftNotFoundException
|
|
{
|
|
if(position > _places.size() || position < 0) throw new AircraftNotFoundException(position);
|
|
T res = _places.get(position);
|
|
_places.remove(res);
|
|
|
|
if(res == null) throw new AircraftNotFoundException(position);
|
|
return res;
|
|
}
|
|
|
|
public ListIterator<T> GetElems() {
|
|
return _places.listIterator();
|
|
}
|
|
|
|
public void Clear() {
|
|
_places.clear();
|
|
}
|
|
|
|
public T Get(int position)
|
|
{
|
|
return _places.get(position);
|
|
}
|
|
}
|