diff --git a/FormMapWithSetLocomotives.java b/FormMapWithSetLocomotives.java index 62436e5..a6d8d69 100644 --- a/FormMapWithSetLocomotives.java +++ b/FormMapWithSetLocomotives.java @@ -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(); diff --git a/MapWithSetLocomotivesGeneric.java b/MapWithSetLocomotivesGeneric.java index 3933913..f92bf87 100644 --- a/MapWithSetLocomotivesGeneric.java +++ b/MapWithSetLocomotivesGeneric.java @@ -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); } diff --git a/SetLocomotivesGeneric.java b/SetLocomotivesGeneric.java index 5c32864..7256512 100644 --- a/SetLocomotivesGeneric.java +++ b/SetLocomotivesGeneric.java @@ -10,15 +10,15 @@ public class SetLocomotivesGeneric _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 } 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)