61 lines
2.1 KiB
Java
61 lines
2.1 KiB
Java
package Scripts.CollectionGenericObjects;
|
|
|
|
import Scripts.Drawing.DrawingModernMonorail;
|
|
import Scripts.Drawing.DrawingMonorail;
|
|
import Scripts.Entities.EntityModernMonorail;
|
|
import Scripts.Entities.EntityMonorail;
|
|
import Scripts.Wheels.IDrawingWheels;
|
|
|
|
import java.lang.reflect.Array;
|
|
import java.util.Random;
|
|
|
|
public class AdditionalCollection <T extends EntityMonorail, U extends IDrawingWheels>{
|
|
public T[] CollectionEntity;
|
|
public U[] CollectionWheels;
|
|
public AdditionalCollection(int size, Class<T> type1, Class<T> type2) {
|
|
CollectionEntity = (T[]) Array.newInstance(type1, size);
|
|
CollectionWheels = (U[]) Array.newInstance(type2, size);
|
|
CountEntities = size;
|
|
CountWheels = size;
|
|
}
|
|
public int CountEntities;
|
|
public int CountWheels;
|
|
public int Insert(T entity) {
|
|
int index = 0;
|
|
while (index < CountEntities) {
|
|
if (CollectionEntity[index] == null)
|
|
{
|
|
CollectionEntity[index] = entity;
|
|
return index;
|
|
}
|
|
++index;
|
|
}
|
|
return -1;
|
|
}
|
|
public int Insert(U decks) {
|
|
int index = 0;
|
|
while (index < CountWheels) {
|
|
if (CollectionWheels[index] == null)
|
|
{
|
|
CollectionWheels[index] = decks;
|
|
return index;
|
|
}
|
|
++index;
|
|
}
|
|
return -1;
|
|
}
|
|
public DrawingMonorail CreateAdditionalCollectionStormtrooper() {
|
|
Random random = new Random();
|
|
if (CollectionEntity == null || CollectionWheels == null) return null;
|
|
T entity = CollectionEntity[random.nextInt(CountEntities)];
|
|
U wheels = CollectionWheels[random.nextInt(CountWheels)];
|
|
DrawingMonorail drawingBaseStormtrooper = null;
|
|
if (entity instanceof EntityModernMonorail) {
|
|
drawingBaseStormtrooper = new DrawingModernMonorail((EntityModernMonorail)entity, wheels);
|
|
}
|
|
else {
|
|
drawingBaseStormtrooper = new DrawingMonorail(entity, wheels);
|
|
}
|
|
return drawingBaseStormtrooper;
|
|
}
|
|
} |