44 lines
1.0 KiB
Java
44 lines
1.0 KiB
Java
|
public class SetPlanesGeneric<T> {
|
||
|
private T[] _places;
|
||
|
|
||
|
public int Count() {
|
||
|
return _places.length;
|
||
|
}
|
||
|
|
||
|
public SetPlanesGeneric(int count) {
|
||
|
_places = (T[]) (new Object[count]);
|
||
|
}
|
||
|
|
||
|
public int Insert(T plane) {
|
||
|
for (int i = 0; i < _places.length; i++) {
|
||
|
if (_places[i] == null) {
|
||
|
_places[i] = plane;
|
||
|
return i;
|
||
|
}
|
||
|
}
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
public int Insert(T plane, 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] = plane;
|
||
|
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];
|
||
|
}
|
||
|
}
|