From 02ac7e55335db8b8e040639e7c6656f98cc35726 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Fri, 2 Dec 2022 18:34:48 +0400 Subject: [PATCH 1/4] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=B8=D1=81=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=B8=20=D0=B8=D1=85=20=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=BA=D0=B0,=20=D0=BD=D0=B5=D0=BC=D0=BD?= =?UTF-8?q?=D0=BE=D0=B3=D0=BE=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BE=D1=82=D1=80=D0=B8=D1=81=D0=BE=D0=B2=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=BE=D0=B2=20=D0=B2=20?= =?UTF-8?q?=D1=85=D1=80=D0=B0=D0=BD=D0=B8=D0=BB=D0=B8=D1=89=D0=B5=20=D0=B8?= =?UTF-8?q?=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20=D0=B8=D1=85=20=D1=85?= =?UTF-8?q?=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FormMapWithSetLocomotives.java | 169 ++++++++++++++++++++++-------- LocomotiveNotFoundException.java | 5 + MapWithSetLocomotivesGeneric.java | 20 ++-- MapsCollection.java | 114 +++++++++----------- SetLocomotivesGeneric.java | 16 +-- StorageOverflowException.java | 5 + 6 files changed, 201 insertions(+), 128 deletions(-) create mode 100644 LocomotiveNotFoundException.java create mode 100644 StorageOverflowException.java diff --git a/FormMapWithSetLocomotives.java b/FormMapWithSetLocomotives.java index 18610d1..39c7f80 100644 --- a/FormMapWithSetLocomotives.java +++ b/FormMapWithSetLocomotives.java @@ -6,6 +6,55 @@ import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import java.text.ParseException; import java.util.HashMap; + + +// Остановился на первом коммите и этом файле. Проблема в том, что в СиШарпе при throw не нужно кусок кода +// обматывать в try catch, а в жабе это необходимо. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + public class FormMapWithSetLocomotives extends JComponent { private BufferedImage bufferImg = null; @@ -113,24 +162,32 @@ public class FormMapWithSetLocomotives extends JComponent { // Кнопка добавления локомотива JButton addLocomotiveButton = new JButton("Add Locomotive"); addLocomotiveButton.addActionListener(e -> { - FormLocomotiveConfig formLocomotiveConfig = new FormLocomotiveConfig(); - formLocomotiveConfig.setVisible(true); - formLocomotiveConfig.AddListener(locomotive -> { - if (listBoxMaps.getSelectedIndex() == -1) { - return; - } - if (locomotive!=null) { - DrawningObjectLocomotive objectLocomotive = new DrawningObjectLocomotive(locomotive); - if (_mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).Plus(objectLocomotive)!= -1){ - JOptionPane.showMessageDialog(formFrame, "Object added", "Success", JOptionPane.OK_CANCEL_OPTION); - bufferImg = _mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).ShowSet(); - repaint(); + FormLocomotiveConfig formLocomotiveConfig = new FormLocomotiveConfig(); + formLocomotiveConfig.setVisible(true); + formLocomotiveConfig.AddListener(locomotive -> { + if (listBoxMaps.getSelectedIndex() == -1) { + return; } - else { - JOptionPane.showMessageDialog(formFrame, "Object cannot be added", "Error", JOptionPane.OK_CANCEL_OPTION); + if (locomotive!=null) { + try { + DrawningObjectLocomotive objectLocomotive = new DrawningObjectLocomotive(locomotive); + if (_mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).Plus(objectLocomotive)!= -1){ + JOptionPane.showMessageDialog(formFrame, "Object added", "Success", JOptionPane.OK_CANCEL_OPTION); + bufferImg = _mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).ShowSet(); + repaint(); + } + else { + JOptionPane.showMessageDialog(formFrame, "Object cannot be added", "Error", JOptionPane.OK_CANCEL_OPTION); + } + } + catch (StorageOverflowException ex) { + JOptionPane.showMessageDialog(formFrame, "Storage overflow error: "+ ex.getMessage()); + } + catch (Exception ex) { + JOptionPane.showMessageDialog(formFrame, "Unknown error: "+ ex.getMessage()); + } } - } - }); + }); }); statusPanel.add(addLocomotiveButton); @@ -149,20 +206,27 @@ public class FormMapWithSetLocomotives extends JComponent { JFormattedTextField finalMaskedTextFieldPosition = maskedTextFieldPosition; deleteLocomotiveButton.addActionListener(e -> { // логика удаления - if ((String)mapSelectComboBox.getSelectedItem() == null) { - return; + try{ + if ((String)mapSelectComboBox.getSelectedItem() == null) { + return; + } + if (finalMaskedTextFieldPosition == null) { + return; + } + int position = Integer.parseInt(finalMaskedTextFieldPosition.getText()); + if (_mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).Minus(position) != null) { + JOptionPane.showMessageDialog(formFrame, "Object removed", "Success", JOptionPane.OK_CANCEL_OPTION); + bufferImg = _mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).ShowSet(); + repaint(); + } + else{ + JOptionPane.showMessageDialog(formFrame, "Object cannot be removed", "Error", JOptionPane.OK_CANCEL_OPTION); + }} + catch (LocomotiveNotFoundException ex) { + JOptionPane.showMessageDialog(formFrame, "Locomotive not found error: " + ex.getMessage()); } - if (finalMaskedTextFieldPosition == null) { - return; - } - int position = Integer.parseInt(finalMaskedTextFieldPosition.getText()); - if (_mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).Minus(position) != null) { - JOptionPane.showMessageDialog(formFrame, "Object removed", "Success", JOptionPane.OK_CANCEL_OPTION); - bufferImg = _mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).ShowSet(); - repaint(); - } - else{ - JOptionPane.showMessageDialog(formFrame, "Object cannot be removed", "Error", JOptionPane.OK_CANCEL_OPTION); + catch (Exception ex) { + JOptionPane.showMessageDialog(formFrame, "Unknown error: "+ ex.getMessage()); } }); statusPanel.add(deleteLocomotiveButton); @@ -186,8 +250,13 @@ public class FormMapWithSetLocomotives extends JComponent { { return; } - bufferImg = _mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).ShowOnMap(); - repaint(); + try { + bufferImg = _mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).ShowOnMap(); + repaint(); + } + catch (Exception ex) { + JOptionPane.showMessageDialog(null, "Unknown error: "+ ex.getMessage()); + } }); statusPanel.add(showOnMapButton); @@ -271,10 +340,13 @@ public class FormMapWithSetLocomotives extends JComponent { fileChooser.setDialogTitle("Saving"); int result = fileChooser.showSaveDialog(FormMapWithSetLocomotives.this); if (result == JFileChooser.APPROVE_OPTION ) { - if (_mapsCollection.SaveData(fileChooser.getSelectedFile().getAbsolutePath())) { + try { + _mapsCollection.SaveData(fileChooser.getSelectedFile().getAbsolutePath()); JOptionPane.showMessageDialog(null, "Save success"); } - else JOptionPane.showMessageDialog(null, "Save failed"); + catch (Exception ex) { + JOptionPane.showMessageDialog(null, "Save error: " + ex.getMessage()); + } } }); @@ -285,13 +357,16 @@ public class FormMapWithSetLocomotives extends JComponent { fileChooser.setDialogTitle("Loading"); int result = fileChooser.showSaveDialog(FormMapWithSetLocomotives.this); if (result == JFileChooser.APPROVE_OPTION ) { - if (_mapsCollection.LoadData(fileChooser.getSelectedFile().getAbsolutePath())) { + try { + _mapsCollection.LoadData(fileChooser.getSelectedFile().getAbsolutePath()); JOptionPane.showMessageDialog(null, "Load success"); + ReloadMaps(); + repaint(); + } + catch (Exception ex) { + JOptionPane.showMessageDialog(null, "Load error: " + ex.getMessage()); } - else JOptionPane.showMessageDialog(null, "Load failed"); } - ReloadMaps(); - repaint(); }); statusPanel.add(loadButton); @@ -306,11 +381,14 @@ public class FormMapWithSetLocomotives extends JComponent { return; } if(listBoxMaps.getSelectedValue().toString() == null) return; - if (_mapsCollection.SaveMap(listBoxMaps.getSelectedValue().toString(), fileChooser.getSelectedFile().getAbsolutePath())) { + try { + _mapsCollection.SaveMap(listBoxMaps.getSelectedValue().toString(), fileChooser.getSelectedFile().getAbsolutePath()); JOptionPane.showMessageDialog(null, "Map saving success"); + repaint(); + } + catch (Exception ex) { + JOptionPane.showMessageDialog(null, "Map saving error: " + ex.getMessage()); } - else JOptionPane.showMessageDialog(null, "Map saving fail"); - repaint(); } }); statusPanel.add(saveMapButton); @@ -321,13 +399,16 @@ public class FormMapWithSetLocomotives extends JComponent { fileChooser.setDialogTitle("Loading"); int result = fileChooser.showSaveDialog(FormMapWithSetLocomotives.this); if (result == JFileChooser.APPROVE_OPTION ) { - if (_mapsCollection.LoadMap(fileChooser.getSelectedFile().getAbsolutePath())) { + try { + _mapsCollection.LoadMap(fileChooser.getSelectedFile().getAbsolutePath()); JOptionPane.showMessageDialog(null, "Load Map success"); + ReloadMaps(); + repaint(); + } + catch (Exception ex) { + JOptionPane.showMessageDialog(null, "Load Map error: " + ex.getMessage()); } - else JOptionPane.showMessageDialog(null, "Load Map failed"); } - ReloadMaps(); - repaint(); }); statusPanel.add(loadMapButton); diff --git a/LocomotiveNotFoundException.java b/LocomotiveNotFoundException.java new file mode 100644 index 0000000..5a1016b --- /dev/null +++ b/LocomotiveNotFoundException.java @@ -0,0 +1,5 @@ +public class LocomotiveNotFoundException extends Exception{ + public LocomotiveNotFoundException(int i) { + super("Не найден объект по позиции " + i); + } +} diff --git a/MapWithSetLocomotivesGeneric.java b/MapWithSetLocomotivesGeneric.java index 0df89e8..0a14654 100644 --- a/MapWithSetLocomotivesGeneric.java +++ b/MapWithSetLocomotivesGeneric.java @@ -13,9 +13,9 @@ public class MapWithSetLocomotivesGeneric /// Высота окна отрисовки private final int _pictureHeight; /// Размер занимаемого объектом места (ширина) - private final int _placeSizeWidth = 210; + private final int _placeSizeWidth = 150; /// Размер занимаемого объектом места (высота) - private final int _placeSizeHeight = 90; + private final int _placeSizeHeight = 150; public final SetLocomotivesGeneric _setLocomotives; // Список удаленных объектов @@ -39,12 +39,12 @@ public class MapWithSetLocomotivesGeneric } /// Добавление - public int Plus(T locomotive) + public int Plus(T locomotive) throws StorageOverflowException { return this._setLocomotives.Insert(locomotive); } /// Удаление - public T Minus(int position) + public T Minus(int position) throws LocomotiveNotFoundException { T temp = this._setLocomotives.Remove(position); if (temp == null) return null; @@ -62,7 +62,7 @@ public class MapWithSetLocomotivesGeneric } /// Просмотр объекта на карте - public BufferedImage ShowOnMap() + public BufferedImage ShowOnMap() throws LocomotiveNotFoundException, StorageOverflowException { Shaking(); for (var locomotive : _setLocomotives.GetLocomotives()) @@ -86,7 +86,7 @@ public class MapWithSetLocomotivesGeneric } /// "Взбалтываем" набор, чтобы все элементы оказались в начале - private void Shaking() + private void Shaking() throws LocomotiveNotFoundException, StorageOverflowException { int j = _setLocomotives.Count() - 1; for (int i = 0; i < _setLocomotives.Count(); i++) @@ -157,8 +157,8 @@ public class MapWithSetLocomotivesGeneric /// Метод прорисовки объектов private void DrawLocomotives(Graphics2D g) { - int width = _pictureWidth / _placeSizeWidth; - int height = _pictureHeight / _placeSizeHeight; + int width = _pictureWidth / _placeSizeWidth - 1; + int height = _pictureHeight / _placeSizeHeight - 1; int curWidth = 0; int curHeight = 0; @@ -166,7 +166,7 @@ public class MapWithSetLocomotivesGeneric for (var locomotive : _setLocomotives.GetLocomotives()) { // установка позиции - if (locomotive != null) locomotive.SetObject(curWidth * _placeSizeWidth + 10, curHeight * _placeSizeHeight + 18, _pictureWidth, _pictureHeight); + if (locomotive != null) locomotive.SetObject(curWidth * _placeSizeWidth + 10, curHeight * _placeSizeHeight + 80, _pictureWidth, _pictureHeight); if (locomotive != null) locomotive.DrawningObject(g); if (curWidth < width) curWidth++; else @@ -189,7 +189,7 @@ public class MapWithSetLocomotivesGeneric } /// Загрузка списка из массива строк - public void LoadData(String[] records) + public void LoadData(String[] records) throws StorageOverflowException { Collections.reverse(Arrays.asList(records)); for (var rec : records) diff --git a/MapsCollection.java b/MapsCollection.java index 0c666b0..7a2b418 100644 --- a/MapsCollection.java +++ b/MapsCollection.java @@ -2,6 +2,7 @@ import java.io.*; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.zip.DataFormatException; public class MapsCollection { /// Словарь (хранилище) с картами @@ -51,59 +52,49 @@ public class MapsCollection { } /// Сохранение информации по локомотивам в хранилище в файл - public boolean SaveData(String filename) + public void SaveData(String filename) throws IOException { File file = new File(filename); if (file.exists()) { file.delete(); } - try(BufferedWriter bw = new BufferedWriter(new FileWriter(filename))) { - bw.write("MapsCollection\n"); - for (var storage : _mapStorages.entrySet()) { - bw.write("" + storage.getKey() + separatorDict + storage.getValue().GetData(separatorDict.charAt(0), separatorData) + "\n"); - } + BufferedWriter bw = new BufferedWriter(new FileWriter(filename)); + bw.write("MapsCollection\n"); + for (var storage : _mapStorages.entrySet()) { + bw.write("" + storage.getKey() + separatorDict + storage.getValue().GetData(separatorDict.charAt(0), separatorData) + "\n"); } - catch (IOException ex) { - System.out.println(ex.getMessage()); - } - return true; } // Сохранение одной выбранной карты - public boolean SaveMap(String map_name, String filename) { + public void SaveMap(String map_name, String filename) throws IOException{ File file = new File(filename); MapWithSetLocomotivesGeneric map = Get(map_name); if (file.exists()) { file.delete(); } - try(BufferedWriter bw = new BufferedWriter(new FileWriter(filename))) { - bw.write("SingleMap\n"); - bw.write("" + map_name + "\n"); - bw.write("" + map.getClass() + "\n"); - for (var locomotive : map._setLocomotives.GetLocomotives()) { - bw.write("" + locomotive.getInfo() + "\n"); - } + BufferedWriter bw = new BufferedWriter(new FileWriter(filename)); + bw.write("SingleMap\n"); + bw.write("" + map_name + "\n"); + bw.write("" + map.getClass() + "\n"); + for (var locomotive : map._setLocomotives.GetLocomotives()) { + bw.write("" + locomotive.getInfo() + "\n"); } - catch (IOException ex) { - System.out.println(ex.getMessage()); - } - return true; + } // Загрузка одной карты - public boolean LoadMap(String filename){ - File file = new File(filename); - if (!file.exists()) - { - return false; - } - try { + public void LoadMap(String filename) throws StorageOverflowException, IOException, DataFormatException{ + File file = new File(filename); + if (!file.exists()) + { + throw new FileNotFoundException("Файл не найден"); + } BufferedReader br = new BufferedReader(new FileReader(filename)); String curLine = br.readLine(); if (!curLine.contains("SingleMap")) { - return false; + throw new DataFormatException("Неверный формат данных"); } String mapName = br.readLine(); String mapClass = br.readLine(); @@ -113,7 +104,6 @@ public class MapsCollection { _mapStorages.get(mapName)._setLocomotives.Insert(DrawningObjectLocomotive.Create(curLine)); } _mapStorages.get(mapName)._setLocomotives.ReversePlaces(); - return true; } AbstractMap map = null; switch (mapClass) @@ -133,53 +123,43 @@ public class MapsCollection { _mapStorages.get(mapName)._setLocomotives.Insert(DrawningObjectLocomotive.Create(curLine)); } _mapStorages.get(mapName)._setLocomotives.ReversePlaces(); - - } catch (IOException ex) { - System.out.println(ex.getMessage()); - } - return true; } /// Загрузка информации по локомотивам в депо из файла - public boolean LoadData(String filename) + public void LoadData(String filename) throws DataFormatException, IOException, StorageOverflowException { File file = new File(filename); if (!file.exists()) { - return false; + throw new FileNotFoundException("Файл не найден"); } - try { - BufferedReader br = new BufferedReader(new FileReader(filename)); - String curLine = br.readLine(); - if (!curLine.contains("MapsCollection")) { - return false; + + BufferedReader br = new BufferedReader(new FileReader(filename)); + String curLine = br.readLine(); + if (!curLine.contains("MapsCollection")) { + throw new DataFormatException("Неверный формат данных"); + } + + _mapStorages.clear(); + while ((curLine = br.readLine()) != null) { + var elems = curLine.split(separatorDict); + AbstractMap map = null; + switch (elems[1]) + { + case "class SimpleMap": + map = new SimpleMap(); + break; + case "class SpikeMap": + map = new SpikeMap(); + break; + case "class RailMap": + map = new RailMap(); + break; } - _mapStorages.clear(); - while ((curLine = br.readLine()) != null) { - var elems = curLine.split(separatorDict); - AbstractMap map = null; - - switch (elems[1]) - { - case "class SimpleMap": - map = new SimpleMap(); - break; - case "class SpikeMap": - map = new SpikeMap(); - break; - case "class RailMap": - map = new RailMap(); - break; - } - - _mapStorages.put(elems[0], new MapWithSetLocomotivesGeneric(_pictureWidth, _pictureHeight, map)); - _mapStorages.get(elems[0]).LoadData(elems[2].split(Character.toString(separatorData))); - } - } catch (IOException ex) { - System.out.println(ex.getMessage()); + _mapStorages.put(elems[0], new MapWithSetLocomotivesGeneric(_pictureWidth, _pictureHeight, map)); + _mapStorages.get(elems[0]).LoadData(elems[2].split(Character.toString(separatorData))); } - return true; } diff --git a/SetLocomotivesGeneric.java b/SetLocomotivesGeneric.java index 07fee4a..54cb08d 100644 --- a/SetLocomotivesGeneric.java +++ b/SetLocomotivesGeneric.java @@ -18,20 +18,22 @@ public class SetLocomotivesGeneric _places = new ArrayList<>(); } - public int Insert (T locomotive) { + public int Insert (T locomotive) throws StorageOverflowException{ return Insert(locomotive, 0); } - public int Insert (T locomotive, int position) { - if (position >= _maxCount|| position < 0) return -1; - _places.add(position, locomotive); - return position; + public int Insert (T locomotive, int position) throws StorageOverflowException{ + if (position < 0) return -1; + if (Count() >= _maxCount) throw new StorageOverflowException(_maxCount); + _places.add(position, locomotive); + return position; } - public T Remove (int position) { + public T Remove (int position) throws LocomotiveNotFoundException { if (position >= _maxCount || position < 0) return null; + if (_places.get(position) == null) throw new LocomotiveNotFoundException(position); T result = _places.get(position); - _places.remove(position); + _places.set(position, null); return result; } diff --git a/StorageOverflowException.java b/StorageOverflowException.java new file mode 100644 index 0000000..376d6a5 --- /dev/null +++ b/StorageOverflowException.java @@ -0,0 +1,5 @@ +public class StorageOverflowException extends Exception{ + public StorageOverflowException(int count) { + super("В наборе превышено допустимое количество: " + count); + } +} -- 2.25.1 From 8dd844aa1445051dcfef8c9a8d4022bf36119d36 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Fri, 2 Dec 2022 21:20:08 +0400 Subject: [PATCH 2/4] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=BB=D0=BE=D0=B3=D0=B8=D1=80=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FormLocomotive.java | 3 -- FormMapWithSetLocomotives.java | 68 ++++++++++------------------------ Main.java | 24 ++++++++++++ MapsCollection.java | 7 ++++ SetLocomotivesGeneric.java | 11 +++++- log.config | 7 ++++ 6 files changed, 66 insertions(+), 54 deletions(-) create mode 100644 Main.java create mode 100644 log.config diff --git a/FormLocomotive.java b/FormLocomotive.java index 765b90b..beab336 100644 --- a/FormLocomotive.java +++ b/FormLocomotive.java @@ -107,7 +107,4 @@ public class FormLocomotive extends JComponent{ if (_locomotive != null) _locomotive.DrawTransport(g2); super.repaint(); } - public static void main(String[] args) { - new FormMapWithSetLocomotives(); - } } diff --git a/FormMapWithSetLocomotives.java b/FormMapWithSetLocomotives.java index 39c7f80..98c25c1 100644 --- a/FormMapWithSetLocomotives.java +++ b/FormMapWithSetLocomotives.java @@ -6,55 +6,7 @@ import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import java.text.ParseException; import java.util.HashMap; - - -// Остановился на первом коммите и этом файле. Проблема в том, что в СиШарпе при throw не нужно кусок кода -// обматывать в try catch, а в жабе это необходимо. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +import java.util.logging.Logger; public class FormMapWithSetLocomotives extends JComponent { private BufferedImage bufferImg = null; @@ -127,6 +79,7 @@ public class FormMapWithSetLocomotives extends JComponent { return; } _mapsCollection.AddMap(textFieldNewMapName.getText(), _mapsDict.get(mapSelectComboBox.getSelectedItem().toString())); + Logger.getGlobal().info("Map " + textFieldNewMapName.getText() + " added"); ReloadMaps(); }); statusPanel.add(addMapButton); @@ -136,6 +89,7 @@ public class FormMapWithSetLocomotives extends JComponent { listBoxMaps.addListSelectionListener(e -> { if(listBoxMaps.getSelectedValue() == null) return; bufferImg = _mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).ShowSet(); + Logger.getGlobal().info("Map switched to " + listBoxMaps.getSelectedValue().toString()); repaint(); }); statusPanel.add(listBoxMaps); @@ -154,6 +108,7 @@ public class FormMapWithSetLocomotives extends JComponent { } if(listBoxMaps.getSelectedValue().toString() == null) return; _mapsCollection.DelMap(listBoxMaps.getSelectedValue().toString()); + Logger.getGlobal().info("Map " +listBoxMaps.getSelectedValue().toString() +" deleted"); ReloadMaps(); repaint(); }); @@ -174,6 +129,7 @@ public class FormMapWithSetLocomotives extends JComponent { if (_mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).Plus(objectLocomotive)!= -1){ JOptionPane.showMessageDialog(formFrame, "Object added", "Success", JOptionPane.OK_CANCEL_OPTION); bufferImg = _mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).ShowSet(); + Logger.getGlobal().info("Object " + locomotive + " added"); repaint(); } else { @@ -182,9 +138,11 @@ public class FormMapWithSetLocomotives extends JComponent { } catch (StorageOverflowException ex) { JOptionPane.showMessageDialog(formFrame, "Storage overflow error: "+ ex.getMessage()); + Logger.getGlobal().severe("Error " + ex.getMessage()); } catch (Exception ex) { JOptionPane.showMessageDialog(formFrame, "Unknown error: "+ ex.getMessage()); + Logger.getGlobal().severe("Error " + ex.getMessage()); } } }); @@ -217,6 +175,7 @@ public class FormMapWithSetLocomotives extends JComponent { if (_mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).Minus(position) != null) { JOptionPane.showMessageDialog(formFrame, "Object removed", "Success", JOptionPane.OK_CANCEL_OPTION); bufferImg = _mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).ShowSet(); + Logger.getGlobal().info("Locomotive deleted at position " + position); repaint(); } else{ @@ -224,9 +183,11 @@ public class FormMapWithSetLocomotives extends JComponent { }} catch (LocomotiveNotFoundException ex) { JOptionPane.showMessageDialog(formFrame, "Locomotive not found error: " + ex.getMessage()); + Logger.getGlobal().severe("Error " + ex.getMessage()); } catch (Exception ex) { JOptionPane.showMessageDialog(formFrame, "Unknown error: "+ ex.getMessage()); + Logger.getGlobal().severe("Error " + ex.getMessage()); } }); statusPanel.add(deleteLocomotiveButton); @@ -256,6 +217,7 @@ public class FormMapWithSetLocomotives extends JComponent { } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Unknown error: "+ ex.getMessage()); + Logger.getGlobal().severe("Error " + ex.getMessage()); } }); statusPanel.add(showOnMapButton); @@ -343,9 +305,11 @@ public class FormMapWithSetLocomotives extends JComponent { try { _mapsCollection.SaveData(fileChooser.getSelectedFile().getAbsolutePath()); JOptionPane.showMessageDialog(null, "Save success"); + Logger.getGlobal().info("Saved all to " + fileChooser.getSelectedFile().getAbsolutePath()); } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Save error: " + ex.getMessage()); + Logger.getGlobal().severe("Error " + ex.getMessage()); } } @@ -360,11 +324,13 @@ public class FormMapWithSetLocomotives extends JComponent { try { _mapsCollection.LoadData(fileChooser.getSelectedFile().getAbsolutePath()); JOptionPane.showMessageDialog(null, "Load success"); + Logger.getGlobal().info("Loaded all from " + fileChooser.getSelectedFile().getAbsolutePath()); ReloadMaps(); repaint(); } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Load error: " + ex.getMessage()); + Logger.getGlobal().severe("Error " + ex.getMessage()); } } }); @@ -384,10 +350,12 @@ public class FormMapWithSetLocomotives extends JComponent { try { _mapsCollection.SaveMap(listBoxMaps.getSelectedValue().toString(), fileChooser.getSelectedFile().getAbsolutePath()); JOptionPane.showMessageDialog(null, "Map saving success"); + Logger.getGlobal().info("Saved map to " + fileChooser.getSelectedFile().getAbsolutePath()); repaint(); } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Map saving error: " + ex.getMessage()); + Logger.getGlobal().severe("Error " + ex.getMessage()); } } }); @@ -402,11 +370,13 @@ public class FormMapWithSetLocomotives extends JComponent { try { _mapsCollection.LoadMap(fileChooser.getSelectedFile().getAbsolutePath()); JOptionPane.showMessageDialog(null, "Load Map success"); + Logger.getGlobal().info("Loaded map from " + fileChooser.getSelectedFile().getAbsolutePath()); ReloadMaps(); repaint(); } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Load Map error: " + ex.getMessage()); + Logger.getGlobal().severe("Error " + ex.getMessage()); } } }); diff --git a/Main.java b/Main.java new file mode 100644 index 0000000..58bd745 --- /dev/null +++ b/Main.java @@ -0,0 +1,24 @@ +import javax.swing.*; +import java.awt.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.logging.LogManager; +import java.util.logging.Logger; + +public class Main { + private static Logger logger = null; + + public static void main(String[] args) { + try { + FileInputStream stream = new FileInputStream(new File("C:/secondCourse/OOP/PIbd-23_Mochalov_D.V._Locomotive_Hard/log.config")); + LogManager.getLogManager().readConfiguration(stream); + logger = Logger.getGlobal(); + stream.close(); + + } catch (IOException e) { + throw new RuntimeException(e); + } + new FormMapWithSetLocomotives(); + } +} diff --git a/MapsCollection.java b/MapsCollection.java index 7a2b418..7d96348 100644 --- a/MapsCollection.java +++ b/MapsCollection.java @@ -2,6 +2,7 @@ import java.io.*; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.logging.Logger; import java.util.zip.DataFormatException; public class MapsCollection { @@ -64,6 +65,7 @@ public class MapsCollection { for (var storage : _mapStorages.entrySet()) { bw.write("" + storage.getKey() + separatorDict + storage.getValue().GetData(separatorDict.charAt(0), separatorData) + "\n"); } + bw.flush(); } // Сохранение одной выбранной карты @@ -81,6 +83,7 @@ public class MapsCollection { for (var locomotive : map._setLocomotives.GetLocomotives()) { bw.write("" + locomotive.getInfo() + "\n"); } + bw.flush(); } @@ -89,11 +92,13 @@ public class MapsCollection { File file = new File(filename); if (!file.exists()) { + Logger.getGlobal().severe("FileNotFoundException " + filename); throw new FileNotFoundException("Файл не найден"); } BufferedReader br = new BufferedReader(new FileReader(filename)); String curLine = br.readLine(); if (!curLine.contains("SingleMap")) { + Logger.getGlobal().severe("FileFormatException " + filename); throw new DataFormatException("Неверный формат данных"); } String mapName = br.readLine(); @@ -131,12 +136,14 @@ public class MapsCollection { File file = new File(filename); if (!file.exists()) { + Logger.getGlobal().severe("FileNotFoundException " + filename); throw new FileNotFoundException("Файл не найден"); } BufferedReader br = new BufferedReader(new FileReader(filename)); String curLine = br.readLine(); if (!curLine.contains("MapsCollection")) { + Logger.getGlobal().severe("FileFormatException " + filename); throw new DataFormatException("Неверный формат данных"); } diff --git a/SetLocomotivesGeneric.java b/SetLocomotivesGeneric.java index 54cb08d..df6fc1b 100644 --- a/SetLocomotivesGeneric.java +++ b/SetLocomotivesGeneric.java @@ -1,5 +1,6 @@ import java.util.ArrayList; import java.util.Collections; +import java.util.logging.Logger; public class SetLocomotivesGeneric { @@ -24,14 +25,20 @@ public class SetLocomotivesGeneric public int Insert (T locomotive, int position) throws StorageOverflowException{ if (position < 0) return -1; - if (Count() >= _maxCount) throw new StorageOverflowException(_maxCount); + if (Count() >= _maxCount) { + Logger.getGlobal().warning("StorageOverflowException"); + throw new StorageOverflowException(_maxCount); + } _places.add(position, locomotive); return position; } public T Remove (int position) throws LocomotiveNotFoundException { if (position >= _maxCount || position < 0) return null; - if (_places.get(position) == null) throw new LocomotiveNotFoundException(position); + if (_places.get(position) == null) { + Logger.getGlobal().warning("LocomotiveNotFoundException at " + position); + throw new LocomotiveNotFoundException(position); + } T result = _places.get(position); _places.set(position, null); return result; diff --git a/log.config b/log.config new file mode 100644 index 0000000..3e0a154 --- /dev/null +++ b/log.config @@ -0,0 +1,7 @@ +handlers = java.util.logging.FileHandler +java.util.logging.FileHandler.level = INFO +java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter +java.util.logging.SimpleFormatter.format= %4$S %5$S (%1$td.%1$tm.%1$tY) %n +java.util.logging.FileHandler.append = true +java.util.logging.FileHandler.pattern = log.txt +java.util.logging.FileHandler.limit = 100000 -- 2.25.1 From c3fc932a2a5d87b1ba2edac423642e4a3d8acab6 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sun, 4 Dec 2022 17:50:10 +0400 Subject: [PATCH 3/4] =?UTF-8?q?=D0=94=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD?= =?UTF-8?q?=20=D0=BB=D0=BE=D0=B3=D0=B3=D0=B5=D1=80,=20=D0=BB=D0=B0=D0=B17?= =?UTF-8?q?=20=D1=85=D0=B0=D1=80=D0=B4=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FormMapWithSetLocomotives.java | 96 +++++++++++++++++++--------------- Main.java | 21 ++------ MapsCollection.java | 5 -- SetLocomotivesGeneric.java | 3 -- log4j2.xml | 25 +++++++++ pom.xml | 30 +++++++++++ 6 files changed, 112 insertions(+), 68 deletions(-) create mode 100644 log4j2.xml create mode 100644 pom.xml diff --git a/FormMapWithSetLocomotives.java b/FormMapWithSetLocomotives.java index 98c25c1..65b6001 100644 --- a/FormMapWithSetLocomotives.java +++ b/FormMapWithSetLocomotives.java @@ -6,7 +6,8 @@ import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import java.text.ParseException; import java.util.HashMap; -import java.util.logging.Logger; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.Logger; public class FormMapWithSetLocomotives extends JComponent { private BufferedImage bufferImg = null; @@ -30,7 +31,12 @@ public class FormMapWithSetLocomotives extends JComponent { JScrollPane listScroller = new JScrollPane(); JList listBoxMaps; - public FormMapWithSetLocomotives() { + private final Logger logger; + + public FormMapWithSetLocomotives(Logger logger) { + + this.logger = logger; + formFrame = new JFrame("Form Map With SetLocomotives"); formFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); formFrame.setSize(750, 500); @@ -79,7 +85,7 @@ public class FormMapWithSetLocomotives extends JComponent { return; } _mapsCollection.AddMap(textFieldNewMapName.getText(), _mapsDict.get(mapSelectComboBox.getSelectedItem().toString())); - Logger.getGlobal().info("Map " + textFieldNewMapName.getText() + " added"); + logger.log(Level.INFO, "Map " + textFieldNewMapName.getText() + " added"); ReloadMaps(); }); statusPanel.add(addMapButton); @@ -89,7 +95,7 @@ public class FormMapWithSetLocomotives extends JComponent { listBoxMaps.addListSelectionListener(e -> { if(listBoxMaps.getSelectedValue() == null) return; bufferImg = _mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).ShowSet(); - Logger.getGlobal().info("Map switched to " + listBoxMaps.getSelectedValue().toString()); + logger.log(Level.INFO,"Map switched to " + listBoxMaps.getSelectedValue().toString()); repaint(); }); statusPanel.add(listBoxMaps); @@ -108,7 +114,7 @@ public class FormMapWithSetLocomotives extends JComponent { } if(listBoxMaps.getSelectedValue().toString() == null) return; _mapsCollection.DelMap(listBoxMaps.getSelectedValue().toString()); - Logger.getGlobal().info("Map " +listBoxMaps.getSelectedValue().toString() +" deleted"); + logger.log(Level.INFO,"Map " +listBoxMaps.getSelectedValue().toString() +" deleted"); ReloadMaps(); repaint(); }); @@ -117,35 +123,35 @@ public class FormMapWithSetLocomotives extends JComponent { // Кнопка добавления локомотива JButton addLocomotiveButton = new JButton("Add Locomotive"); addLocomotiveButton.addActionListener(e -> { - FormLocomotiveConfig formLocomotiveConfig = new FormLocomotiveConfig(); - formLocomotiveConfig.setVisible(true); - formLocomotiveConfig.AddListener(locomotive -> { - if (listBoxMaps.getSelectedIndex() == -1) { - return; - } - if (locomotive!=null) { - try { - DrawningObjectLocomotive objectLocomotive = new DrawningObjectLocomotive(locomotive); - if (_mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).Plus(objectLocomotive)!= -1){ - JOptionPane.showMessageDialog(formFrame, "Object added", "Success", JOptionPane.OK_CANCEL_OPTION); - bufferImg = _mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).ShowSet(); - Logger.getGlobal().info("Object " + locomotive + " added"); - repaint(); - } - else { - JOptionPane.showMessageDialog(formFrame, "Object cannot be added", "Error", JOptionPane.OK_CANCEL_OPTION); - } + FormLocomotiveConfig formLocomotiveConfig = new FormLocomotiveConfig(); + formLocomotiveConfig.setVisible(true); + formLocomotiveConfig.AddListener(locomotive -> { + if (listBoxMaps.getSelectedIndex() == -1) { + return; + } + if (locomotive!=null) { + try { + DrawningObjectLocomotive objectLocomotive = new DrawningObjectLocomotive(locomotive); + if (_mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).Plus(objectLocomotive)!= -1){ + JOptionPane.showMessageDialog(formFrame, "Object added", "Success", JOptionPane.OK_CANCEL_OPTION); + bufferImg = _mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).ShowSet(); + logger.log(Level.INFO,"Object " + locomotive + " added"); + repaint(); } - catch (StorageOverflowException ex) { - JOptionPane.showMessageDialog(formFrame, "Storage overflow error: "+ ex.getMessage()); - Logger.getGlobal().severe("Error " + ex.getMessage()); - } - catch (Exception ex) { - JOptionPane.showMessageDialog(formFrame, "Unknown error: "+ ex.getMessage()); - Logger.getGlobal().severe("Error " + ex.getMessage()); + else { + JOptionPane.showMessageDialog(formFrame, "Object cannot be added", "Error", JOptionPane.OK_CANCEL_OPTION); } } - }); + catch (StorageOverflowException ex) { + JOptionPane.showMessageDialog(formFrame, "Storage overflow error: "+ ex.getMessage()); + logger.log(Level.WARN,"Error " + ex.getMessage()); + } + catch (Exception ex) { + JOptionPane.showMessageDialog(formFrame, "Unknown error: "+ ex.getMessage()); + logger.log(Level.FATAL,"Error " + ex.getMessage()); + } + } + }); }); statusPanel.add(addLocomotiveButton); @@ -175,7 +181,7 @@ public class FormMapWithSetLocomotives extends JComponent { if (_mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).Minus(position) != null) { JOptionPane.showMessageDialog(formFrame, "Object removed", "Success", JOptionPane.OK_CANCEL_OPTION); bufferImg = _mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).ShowSet(); - Logger.getGlobal().info("Locomotive deleted at position " + position); + logger.log(Level.INFO,"Locomotive deleted at position " + position); repaint(); } else{ @@ -183,11 +189,11 @@ public class FormMapWithSetLocomotives extends JComponent { }} catch (LocomotiveNotFoundException ex) { JOptionPane.showMessageDialog(formFrame, "Locomotive not found error: " + ex.getMessage()); - Logger.getGlobal().severe("Error " + ex.getMessage()); + logger.log(Level.WARN,"Error " + ex.getMessage()); } catch (Exception ex) { JOptionPane.showMessageDialog(formFrame, "Unknown error: "+ ex.getMessage()); - Logger.getGlobal().severe("Error " + ex.getMessage()); + logger.log(Level.FATAL,"Error " + ex.getMessage()); } }); statusPanel.add(deleteLocomotiveButton); @@ -215,9 +221,13 @@ public class FormMapWithSetLocomotives extends JComponent { bufferImg = _mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).ShowOnMap(); repaint(); } + catch (StorageOverflowException ex) { + JOptionPane.showMessageDialog(formFrame, "Storage overflow error: "+ ex.getMessage()); + logger.log(Level.WARN,"Error " + ex.getMessage()); + } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Unknown error: "+ ex.getMessage()); - Logger.getGlobal().severe("Error " + ex.getMessage()); + logger.log(Level.FATAL,"Error " + ex.getMessage()); } }); statusPanel.add(showOnMapButton); @@ -305,11 +315,11 @@ public class FormMapWithSetLocomotives extends JComponent { try { _mapsCollection.SaveData(fileChooser.getSelectedFile().getAbsolutePath()); JOptionPane.showMessageDialog(null, "Save success"); - Logger.getGlobal().info("Saved all to " + fileChooser.getSelectedFile().getAbsolutePath()); + logger.log(Level.INFO,"Saved all to " + fileChooser.getSelectedFile().getAbsolutePath()); } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Save error: " + ex.getMessage()); - Logger.getGlobal().severe("Error " + ex.getMessage()); + logger.log(Level.ERROR,"Error " + ex.getMessage()); } } @@ -324,13 +334,13 @@ public class FormMapWithSetLocomotives extends JComponent { try { _mapsCollection.LoadData(fileChooser.getSelectedFile().getAbsolutePath()); JOptionPane.showMessageDialog(null, "Load success"); - Logger.getGlobal().info("Loaded all from " + fileChooser.getSelectedFile().getAbsolutePath()); + logger.log(Level.INFO,"Loaded all from " + fileChooser.getSelectedFile().getAbsolutePath()); ReloadMaps(); repaint(); } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Load error: " + ex.getMessage()); - Logger.getGlobal().severe("Error " + ex.getMessage()); + logger.log(Level.ERROR,"Error " + ex.getMessage()); } } }); @@ -350,12 +360,12 @@ public class FormMapWithSetLocomotives extends JComponent { try { _mapsCollection.SaveMap(listBoxMaps.getSelectedValue().toString(), fileChooser.getSelectedFile().getAbsolutePath()); JOptionPane.showMessageDialog(null, "Map saving success"); - Logger.getGlobal().info("Saved map to " + fileChooser.getSelectedFile().getAbsolutePath()); + logger.log(Level.INFO,"Saved map to " + fileChooser.getSelectedFile().getAbsolutePath()); repaint(); } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Map saving error: " + ex.getMessage()); - Logger.getGlobal().severe("Error " + ex.getMessage()); + logger.log(Level.ERROR,"Error " + ex.getMessage()); } } }); @@ -370,13 +380,13 @@ public class FormMapWithSetLocomotives extends JComponent { try { _mapsCollection.LoadMap(fileChooser.getSelectedFile().getAbsolutePath()); JOptionPane.showMessageDialog(null, "Load Map success"); - Logger.getGlobal().info("Loaded map from " + fileChooser.getSelectedFile().getAbsolutePath()); + logger.log(Level.INFO,"Loaded map from " + fileChooser.getSelectedFile().getAbsolutePath()); ReloadMaps(); repaint(); } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Load Map error: " + ex.getMessage()); - Logger.getGlobal().severe("Error " + ex.getMessage()); + logger.log(Level.ERROR,"Error " + ex.getMessage()); } } }); diff --git a/Main.java b/Main.java index 58bd745..9e7aef7 100644 --- a/Main.java +++ b/Main.java @@ -1,24 +1,11 @@ -import javax.swing.*; -import java.awt.*; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.logging.LogManager; -import java.util.logging.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class Main { private static Logger logger = null; public static void main(String[] args) { - try { - FileInputStream stream = new FileInputStream(new File("C:/secondCourse/OOP/PIbd-23_Mochalov_D.V._Locomotive_Hard/log.config")); - LogManager.getLogManager().readConfiguration(stream); - logger = Logger.getGlobal(); - stream.close(); - - } catch (IOException e) { - throw new RuntimeException(e); - } - new FormMapWithSetLocomotives(); + logger = LogManager.getLogger(Main.class); + new FormMapWithSetLocomotives(logger); } } diff --git a/MapsCollection.java b/MapsCollection.java index 7d96348..6efca26 100644 --- a/MapsCollection.java +++ b/MapsCollection.java @@ -2,7 +2,6 @@ import java.io.*; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; -import java.util.logging.Logger; import java.util.zip.DataFormatException; public class MapsCollection { @@ -92,13 +91,11 @@ public class MapsCollection { File file = new File(filename); if (!file.exists()) { - Logger.getGlobal().severe("FileNotFoundException " + filename); throw new FileNotFoundException("Файл не найден"); } BufferedReader br = new BufferedReader(new FileReader(filename)); String curLine = br.readLine(); if (!curLine.contains("SingleMap")) { - Logger.getGlobal().severe("FileFormatException " + filename); throw new DataFormatException("Неверный формат данных"); } String mapName = br.readLine(); @@ -136,14 +133,12 @@ public class MapsCollection { File file = new File(filename); if (!file.exists()) { - Logger.getGlobal().severe("FileNotFoundException " + filename); throw new FileNotFoundException("Файл не найден"); } BufferedReader br = new BufferedReader(new FileReader(filename)); String curLine = br.readLine(); if (!curLine.contains("MapsCollection")) { - Logger.getGlobal().severe("FileFormatException " + filename); throw new DataFormatException("Неверный формат данных"); } diff --git a/SetLocomotivesGeneric.java b/SetLocomotivesGeneric.java index df6fc1b..1e96946 100644 --- a/SetLocomotivesGeneric.java +++ b/SetLocomotivesGeneric.java @@ -1,6 +1,5 @@ import java.util.ArrayList; import java.util.Collections; -import java.util.logging.Logger; public class SetLocomotivesGeneric { @@ -26,7 +25,6 @@ public class SetLocomotivesGeneric public int Insert (T locomotive, int position) throws StorageOverflowException{ if (position < 0) return -1; if (Count() >= _maxCount) { - Logger.getGlobal().warning("StorageOverflowException"); throw new StorageOverflowException(_maxCount); } _places.add(position, locomotive); @@ -36,7 +34,6 @@ public class SetLocomotivesGeneric public T Remove (int position) throws LocomotiveNotFoundException { if (position >= _maxCount || position < 0) return null; if (_places.get(position) == null) { - Logger.getGlobal().warning("LocomotiveNotFoundException at " + position); throw new LocomotiveNotFoundException(position); } T result = _places.get(position); diff --git a/log4j2.xml b/log4j2.xml new file mode 100644 index 0000000..ee4f664 --- /dev/null +++ b/log4j2.xml @@ -0,0 +1,25 @@ + + + + + + %-5level %msg (%d{dd.MM.yyyy})%n + + + + + + %-5level %msg (%d{dd.MM.yyyy})%n + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..7203947 --- /dev/null +++ b/pom.xml @@ -0,0 +1,30 @@ + + + 4.0.0 + + groupId + PIbd-23_Mochalov_D.V._Locomotive_Hard + 1.0-SNAPSHOT + + + 19 + 19 + UTF-8 + + + + + org.apache.logging.log4j + log4j-api + 2.19.0 + + + org.apache.logging.log4j + log4j-core + 2.19.0 + + + + \ No newline at end of file -- 2.25.1 From a76cf5299ee11d476dee84462867b9dbc4d8a810 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sun, 4 Dec 2022 17:50:36 +0400 Subject: [PATCH 4/4] =?UTF-8?q?=D0=94=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD?= =?UTF-8?q?=20=D0=BB=D0=BE=D0=B3=D0=B3=D0=B5=D1=80,=20=D0=BB=D0=B0=D0=B17?= =?UTF-8?q?=20=D1=85=D0=B0=D1=80=D0=B4=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- log.config | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 log.config diff --git a/log.config b/log.config deleted file mode 100644 index 3e0a154..0000000 --- a/log.config +++ /dev/null @@ -1,7 +0,0 @@ -handlers = java.util.logging.FileHandler -java.util.logging.FileHandler.level = INFO -java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter -java.util.logging.SimpleFormatter.format= %4$S %5$S (%1$td.%1$tm.%1$tY) %n -java.util.logging.FileHandler.append = true -java.util.logging.FileHandler.pattern = log.txt -java.util.logging.FileHandler.limit = 100000 -- 2.25.1