Mochalov D.V. Hard LabWork03 #3
@ -77,7 +77,7 @@ public class FormMapWithSetLocomotives extends JComponent {
|
||||
|
||||
DrawningObjectLocomotive locomotive = new DrawningObjectLocomotive(formLocomotive.getSelectedLocomotive());
|
||||
//TODO
|
||||
if (_mapLocomotivesCollectionGeneric.Plus(locomotive)) {
|
||||
if (_mapLocomotivesCollectionGeneric.Plus(locomotive) != -1) {
|
||||
JOptionPane.showMessageDialog(formFrame, "Object added", "Success", JOptionPane.OK_CANCEL_OPTION);
|
||||
bufferImg = _mapLocomotivesCollectionGeneric.ShowSet();
|
||||
repaint();
|
||||
@ -112,7 +112,7 @@ public class FormMapWithSetLocomotives extends JComponent {
|
||||
return;
|
||||
}
|
||||
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);
|
||||
bufferImg = _mapLocomotivesCollectionGeneric.ShowSet();
|
||||
repaint();
|
||||
|
@ -30,12 +30,12 @@ public class MapWithSetLocomotivesGeneric
|
||||
|
||||
/// Добавление
|
||||
//TODO
|
||||
public boolean Plus(T locomotive)
|
||||
public int Plus(T locomotive)
|
||||
{
|
||||
return this._setLocomotives.Insert(locomotive);
|
||||
}
|
||||
/// Удаление
|
||||
public boolean Minus(int position)
|
||||
public T Minus(int position)
|
||||
{
|
||||
return this._setLocomotives.Remove(position);
|
||||
}
|
||||
|
@ -10,15 +10,15 @@ public class SetLocomotivesGeneric <T>
|
||||
_places = (T[]) new Object[count];
|
||||
}
|
||||
|
||||
public boolean Insert (T locomotive) {
|
||||
public int Insert (T locomotive) {
|
||||
return Insert(locomotive, 0);
|
||||
}
|
||||
|
||||
public boolean Insert (T locomotive, int position) {
|
||||
if (position >= _places.length || position < 0) return false;
|
||||
public int Insert (T locomotive, int position) {
|
||||
if (position >= _places.length || position < 0) return -1;
|
||||
if (_places[position] == null) {
|
||||
_places[position] = locomotive;
|
||||
return true;
|
||||
return position;
|
||||
}
|
||||
|
||||
int emptyEl = -1;
|
||||
@ -32,20 +32,21 @@ public class SetLocomotivesGeneric <T>
|
||||
}
|
||||
if (emptyEl == -1)
|
||||
{
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
for (int i = emptyEl; i > position; i--)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
_places[position] = locomotive;
|
||||
return true;
|
||||
return position;
|
||||
}
|
||||
|
||||
public boolean Remove (int position) {
|
||||
if (position >= _places.length || position < 0) return false;
|
||||
public T Remove (int position) {
|
||||
if (position >= _places.length || position < 0) return null;
|
||||
T result = _places[position];
|
||||
_places[position] = null;
|
||||
return true;
|
||||
return result;
|
||||
}
|
||||
|
||||
public T Get(int position)
|
||||
|
Loading…
Reference in New Issue
Block a user