Created class LocomotivesGenericStorage

This commit is contained in:
ekallin 2023-11-07 00:40:53 +04:00
parent 84307044fe
commit 00af902200
4 changed files with 31 additions and 15 deletions

11
.idea/java.iml generated Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

2
.idea/modules.xml generated
View File

@ -2,7 +2,7 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD.iml" filepath="$PROJECT_DIR$/.idea/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/java.iml" filepath="$PROJECT_DIR$/.idea/java.iml" />
</modules>
</component>
</project>

View File

@ -7,9 +7,11 @@ public class LocomotiveGenericCollection<T extends DrawingLocomotive,U extends I
//ширина/высота окна
private final int _pictureWidth;
private final int _pictureHeight;
//ширина/высота занимаемого места
private final int _placeSizeWidth = 150;
private final int _placeSizeHeight = 50;
/// Набор объектов
private final SetGeneric<T> _collection;
@ -24,7 +26,6 @@ public class LocomotiveGenericCollection<T extends DrawingLocomotive,U extends I
/// Перегрузка оператора сложения
//да емае, почему в яве все по-другому?...
public int AddOverload(T loco){
if(loco == null){
return -1;
@ -32,15 +33,21 @@ public class LocomotiveGenericCollection<T extends DrawingLocomotive,U extends I
return _collection.Insert(loco);
}
public T SubOverload(int pos){
return _collection.Remove(pos);
public T SubOverload(int pos)
{
T loco = _collection.Get(pos);
if (loco != null)
{
_collection.Remove(pos);
}
return loco;
}
// получение объекта imoveableObj
public U GetU(int pos)
{
return (U)_collection.Get(pos).GetMoveableObject();
}
{
return (U)_collection.Get(pos).GetMoveableObject();
}
/// Вывод всего набора объектов
public void ShowLocomotives(Graphics gr)
@ -66,7 +73,6 @@ public class LocomotiveGenericCollection<T extends DrawingLocomotive,U extends I
private void DrawObjects(Graphics g)
{
int HeightObjCount = _pictureHeight / _placeSizeHeight;
int WidthObjCount = _pictureWidth / _placeSizeWidth;
for (int i = 0; i < _collection.Count(); i++)
{
T type = _collection.Get(i);

View File

@ -48,6 +48,12 @@ public class SetGeneric<T extends DrawingLocomotive>{
return _places.get(position);
}
public T Get(int position)
{
if (position < 0 || position >= Count()) return null;
return _places.get(position);
}
public Iterable<T> GetLocomotives(final Integer maxLocomotives) {
return new Iterable<T>() {
@Override
@ -80,11 +86,4 @@ public class SetGeneric<T extends DrawingLocomotive>{
}
};
}
// public T Get(int position)
// {
// // TODO проверка позиции
// if (position < 0 || position >= Count()) return null;
// return _places[position];
// }
}