che commit
This commit is contained in:
parent
a70ce74c29
commit
1252238fc4
@ -170,7 +170,7 @@ public class FormAirplaneCollection {
|
||||
if(listBoxStorages.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
AirplaneGenericStorage<DrawningAirplane, DrawningObjectAirplane> _monorails = _storage.Get(listBoxStorages.getSelectedValue());
|
||||
AirplaneGenericStorage<DrawningAirplane, DrawningObjectAirplane> _airplanes = _storage.Get(listBoxStorages.getSelectedValue());
|
||||
if(_airplanes == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -1,47 +1,48 @@
|
||||
package src.Generics;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SetGeneric <T extends Object>{
|
||||
private final Object[] _places;
|
||||
private final List<T> _places;
|
||||
public int Count;
|
||||
private final int _maxCount;
|
||||
public SetGeneric(int count){
|
||||
_places = new Object[count];
|
||||
Count = count;
|
||||
_maxCount = count;
|
||||
_places = new ArrayList<>();
|
||||
}
|
||||
public int Insert(T airplane){
|
||||
return Insert(airplane, 0);
|
||||
}
|
||||
public int Insert(T airplane, int position){
|
||||
if(!(position >= 0 && position < Count))
|
||||
return -1;
|
||||
if(_places[position] == null){
|
||||
_places[position] = airplane;
|
||||
}
|
||||
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] = airplane;
|
||||
}
|
||||
return position;
|
||||
}
|
||||
public boolean Remove(int position){
|
||||
if(!(position >= 0 && position < Count))
|
||||
public boolean Insert(T monorail){
|
||||
if(_places.size() == _maxCount)
|
||||
return false;
|
||||
_places[position] = null;
|
||||
Insert(monorail, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean Insert(T monorail, int position){
|
||||
if (!(position >= 0 && position <= _places.size() && _places.size() < _maxCount))
|
||||
return false;
|
||||
_places.add(position, monorail);
|
||||
Count++;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean Remove(int position){
|
||||
if(!(position >= 0 && position < _places.size()))
|
||||
return false;
|
||||
_places.remove(position);
|
||||
return true;
|
||||
}
|
||||
public T Get(int position){
|
||||
if(!(position >= 0 && position < Count))
|
||||
return null;
|
||||
return (T)_places[position];
|
||||
return (T)_places.get(position);
|
||||
}
|
||||
public ArrayList<T> GetAirplanes(int maxAirplanes){
|
||||
ArrayList<T> toRet = new ArrayList<>();
|
||||
for(int i = 0; i < _places.size(); i++){
|
||||
toRet.add(_places.get(i));
|
||||
if(i == maxAirplanes)
|
||||
return toRet;
|
||||
}
|
||||
return toRet;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user