51 lines
1.1 KiB
Java
51 lines
1.1 KiB
Java
public class SetAircraftsGeneric<T>
|
|
{
|
|
private T[] _places;
|
|
|
|
public int getCount() {
|
|
return _places.length;
|
|
}
|
|
|
|
public SetAircraftsGeneric(int count)
|
|
{
|
|
_places = (T[])(new Object[count]);
|
|
}
|
|
public int Insert(T car)
|
|
{
|
|
for(int i = 0; i < _places.length; i++)
|
|
{
|
|
if (_places[i] == null)
|
|
{
|
|
_places[i] = car;
|
|
return i;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
public int Insert(T car, int position)
|
|
{
|
|
int index = position;
|
|
|
|
while (_places[index] != null && index < _places.length) index++;
|
|
|
|
if (index == _places.length) return -1;
|
|
for (int i = index; i > position; --i) _places[i] = _places[i - 1];
|
|
|
|
_places[position] = car;
|
|
return position;
|
|
}
|
|
|
|
public T Remove(int position)
|
|
{
|
|
if(position >= _places.length) return null;
|
|
T res = _places[position];
|
|
_places[position] = null;
|
|
return res;
|
|
}
|
|
|
|
public T Get(int position)
|
|
{
|
|
return _places[position];
|
|
}
|
|
}
|