From 7611f197fa3081efabb754531b4a95306fed2b7d Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Fri, 21 Oct 2022 21:59:22 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BD=D0=BE=D1=81=20?= =?UTF-8?q?=D0=B2=D1=81=D0=B5=D0=B9=20=D0=B1=D0=B0=D0=B7=D0=BE=D0=B2=D0=BE?= =?UTF-8?q?=D0=B9=20=D1=87=D0=B0=D1=81=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FormMapWithSetLocomotives.java | 4 ++-- MapWithSetLocomotivesGeneric.java | 4 ++-- SetLocomotivesGeneric.java | 19 ++++++++++--------- 3 files changed, 14 insertions(+), 13 deletions(-) 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)