Compare commits

...

2 Commits

View File

@ -1,11 +1,12 @@
package laba1Loco;
import java.util.ArrayList;
import java.util.Random;
public class GenericDopClass<T extends EntityTrain, U extends IWheelDrawing> {
private Object[] Trains;
private Object[] Wheels;
private ArrayList<T> Trains;
private ArrayList<U> Wheels;
private int maxCountTrains;
private int countTrains;
private int maxCountWheels;
@ -23,8 +24,8 @@ public class GenericDopClass<T extends EntityTrain, U extends IWheelDrawing> {
public GenericDopClass(int _maxCountTrains, int _maxCountWheels, int pictureWidth, int pictureHeight){
maxCountTrains = _maxCountTrains;
maxCountWheels = _maxCountWheels;
Trains = new Object[maxCountTrains];
Wheels = new Object[maxCountWheels];
Trains = new ArrayList<T>(maxCountTrains);
Wheels = new ArrayList<U>(maxCountWheels);
countTrains = 0;
countWheels = 0;
_pictureWidth = pictureWidth;
@ -37,7 +38,7 @@ public class GenericDopClass<T extends EntityTrain, U extends IWheelDrawing> {
return false;
if (countTrains > maxCountTrains)
return false;
Trains[countTrains++] = train;
Trains.add(countTrains++, train);
return true;
}
@ -46,7 +47,7 @@ public class GenericDopClass<T extends EntityTrain, U extends IWheelDrawing> {
return false;
if (countWheels > maxCountWheels)
return false;
Wheels[countWheels++] = wheel;
Wheels.add(countWheels++, wheel);
return true;
}
@ -56,11 +57,11 @@ public class GenericDopClass<T extends EntityTrain, U extends IWheelDrawing> {
int i = random.nextInt(countTrains);
int j = random.nextInt(countWheels);
DrawingTrain drawingTrain;
if (Trains[i] instanceof EntityLoco){
drawingTrain = new DrawingLoco((EntityLoco)Trains[i], (IWheelDrawing)Wheels[j], _pictureWidth, _pictureHeight);
if (Trains.get(i) instanceof EntityLoco){
drawingTrain = new DrawingLoco((EntityLoco)Trains.get(i), Wheels.get(j), _pictureWidth, _pictureHeight);
}
else{
drawingTrain = new DrawingTrain((EntityTrain)Trains[i], (IWheelDrawing)Wheels[j], _pictureWidth, _pictureHeight);
drawingTrain = new DrawingTrain(Trains.get(i), Wheels.get(j), _pictureWidth, _pictureHeight);
}
return drawingTrain;
}