54 lines
1.3 KiB
Java
54 lines
1.3 KiB
Java
|
|
|
|
public class SetGeneric <T extends Object>{
|
|
private final Object[] _places;
|
|
|
|
public int Count;
|
|
|
|
public SetGeneric(int count){
|
|
_places = new Object[count];
|
|
Count = count;
|
|
}
|
|
|
|
public int Insert(T catamaran){
|
|
return Insert(catamaran, 0);
|
|
}
|
|
|
|
public int Insert(T catamaran, int position){
|
|
if(!(position >= 0 && position < Count))
|
|
return -1;
|
|
if(_places[position] == null){
|
|
_places[position] = catamaran;
|
|
}
|
|
else{
|
|
int place = -1;
|
|
for(int i = position; i < Count; i++){
|
|
if(_places[i] == null){
|
|
place = i;
|
|
break;
|
|
}
|
|
}
|
|
if(place == -1)
|
|
return -1;
|
|
|
|
for(int i = place - 1; i >= position; i--)
|
|
_places[i+1] = _places[i];
|
|
_places[position] = catamaran;
|
|
}
|
|
return position;
|
|
}
|
|
|
|
public boolean Remove(int position){
|
|
if(!(position >= 0 && position < Count))
|
|
return false;
|
|
_places[position] = null;
|
|
return true;
|
|
}
|
|
|
|
public T Get(int position){
|
|
if(!(position >= 0 && position < Count))
|
|
return null;
|
|
return (T)_places[position];
|
|
}
|
|
}
|