Перенос всей базовой части

This commit is contained in:
Данила Мочалов 2022-10-21 21:59:22 +04:00
parent b28bb84cf8
commit 7611f197fa
3 changed files with 14 additions and 13 deletions

View File

@ -77,7 +77,7 @@ public class FormMapWithSetLocomotives extends JComponent {
DrawningObjectLocomotive locomotive = new DrawningObjectLocomotive(formLocomotive.getSelectedLocomotive()); DrawningObjectLocomotive locomotive = new DrawningObjectLocomotive(formLocomotive.getSelectedLocomotive());
//TODO //TODO
if (_mapLocomotivesCollectionGeneric.Plus(locomotive)) { if (_mapLocomotivesCollectionGeneric.Plus(locomotive) != -1) {
JOptionPane.showMessageDialog(formFrame, "Object added", "Success", JOptionPane.OK_CANCEL_OPTION); JOptionPane.showMessageDialog(formFrame, "Object added", "Success", JOptionPane.OK_CANCEL_OPTION);
bufferImg = _mapLocomotivesCollectionGeneric.ShowSet(); bufferImg = _mapLocomotivesCollectionGeneric.ShowSet();
repaint(); repaint();
@ -112,7 +112,7 @@ public class FormMapWithSetLocomotives extends JComponent {
return; return;
} }
int position = Integer.parseInt(finalMaskedTextFieldPosition.getText()); int position = Integer.parseInt(finalMaskedTextFieldPosition.getText());
if (_mapLocomotivesCollectionGeneric.Minus(position)) { if (_mapLocomotivesCollectionGeneric.Minus(position) != null) {
JOptionPane.showMessageDialog(formFrame, "Object removed", "Success", JOptionPane.OK_CANCEL_OPTION); JOptionPane.showMessageDialog(formFrame, "Object removed", "Success", JOptionPane.OK_CANCEL_OPTION);
bufferImg = _mapLocomotivesCollectionGeneric.ShowSet(); bufferImg = _mapLocomotivesCollectionGeneric.ShowSet();
repaint(); repaint();

View File

@ -30,12 +30,12 @@ public class MapWithSetLocomotivesGeneric
/// Добавление /// Добавление
//TODO //TODO
public boolean Plus(T locomotive) public int Plus(T locomotive)
{ {
return this._setLocomotives.Insert(locomotive); return this._setLocomotives.Insert(locomotive);
} }
/// Удаление /// Удаление
public boolean Minus(int position) public T Minus(int position)
{ {
return this._setLocomotives.Remove(position); return this._setLocomotives.Remove(position);
} }

View File

@ -10,15 +10,15 @@ public class SetLocomotivesGeneric <T>
_places = (T[]) new Object[count]; _places = (T[]) new Object[count];
} }
public boolean Insert (T locomotive) { public int Insert (T locomotive) {
return Insert(locomotive, 0); return Insert(locomotive, 0);
} }
public boolean Insert (T locomotive, int position) { public int Insert (T locomotive, int position) {
if (position >= _places.length || position < 0) return false; if (position >= _places.length || position < 0) return -1;
if (_places[position] == null) { if (_places[position] == null) {
_places[position] = locomotive; _places[position] = locomotive;
return true; return position;
} }
int emptyEl = -1; int emptyEl = -1;
@ -32,20 +32,21 @@ public class SetLocomotivesGeneric <T>
} }
if (emptyEl == -1) if (emptyEl == -1)
{ {
return false; return -1;
} }
for (int i = emptyEl; i > position; i--) for (int i = emptyEl; i > position; i--)
{ {
_places[i] = _places[i - 1]; _places[i] = _places[i - 1];
} }
_places[position] = locomotive; _places[position] = locomotive;
return true; return position;
} }
public boolean Remove (int position) { public T Remove (int position) {
if (position >= _places.length || position < 0) return false; if (position >= _places.length || position < 0) return null;
T result = _places[position];
_places[position] = null; _places[position] = null;
return true; return result;
} }
public T Get(int position) public T Get(int position)