71 lines
1.2 KiB
Java
71 lines
1.2 KiB
Java
package Classes;
|
|
|
|
import java.util.*;
|
|
|
|
public class SetAircraftsGeneric<T>
|
|
{
|
|
private final ArrayList<T> _places;
|
|
|
|
public int getCount()
|
|
{
|
|
return _places.size();
|
|
}
|
|
|
|
private final int _maxCount;
|
|
|
|
public SetAircraftsGeneric(int count)
|
|
{
|
|
_maxCount = count;
|
|
_places = new ArrayList<T>();
|
|
}
|
|
|
|
public int Insert(T aircraft)
|
|
{
|
|
return Insert(aircraft, 0);
|
|
}
|
|
|
|
public int Insert(T aircraft, int position)
|
|
{
|
|
if (position > getCount() || position < 0 || getCount() == _maxCount)
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
_places.add(position, aircraft);
|
|
|
|
return position;
|
|
}
|
|
|
|
public T Remove(int position)
|
|
{
|
|
if (position < getCount() && position >= 0)
|
|
{
|
|
if (_places.get(position) != null)
|
|
{
|
|
T result = _places.get(position);
|
|
|
|
_places.remove(position);
|
|
|
|
return result;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public T get(int position)
|
|
{
|
|
|
|
if (position < _maxCount && position >= 0)
|
|
{
|
|
return _places.get(position);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
|
|
}
|