finally it's over...
This commit is contained in:
parent
ff9af7035a
commit
2ec6b477c7
1
.gitignore
vendored
1
.gitignore
vendored
@ -76,4 +76,3 @@ fabric.properties
|
|||||||
|
|
||||||
# Android studio 3.1+ serialized cache file
|
# Android studio 3.1+ serialized cache file
|
||||||
.idea/caches/build_file_checksums.ser
|
.idea/caches/build_file_checksums.ser
|
||||||
|
|
||||||
|
18
.idea/WarshipHard.iml
generated
18
.idea/WarshipHard.iml
generated
@ -8,5 +8,23 @@
|
|||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="module-library">
|
||||||
|
<library>
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$MODULE_DIR$/../../../../Log4j/apache-log4j-2.19.0-bin/log4j-api-2.19.0.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC />
|
||||||
|
<SOURCES />
|
||||||
|
</library>
|
||||||
|
</orderEntry>
|
||||||
|
<orderEntry type="module-library">
|
||||||
|
<library>
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$MODULE_DIR$/../../../../Log4j/apache-log4j-2.19.0-bin/log4j-core-2.19.0.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC />
|
||||||
|
<SOURCES />
|
||||||
|
</library>
|
||||||
|
</orderEntry>
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
4
Errors.log
Normal file
4
Errors.log
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
[WARN ] Хранилище переполнено: Превышено допустимое количество в хранилище: 104 (12.12.2022)
|
||||||
|
[WARN ] Хранилище переполнено: Превышено допустимое количество в хранилище: 104 (12.12.2022)
|
||||||
|
[WARN ] Не удалось удалить объект на позиции104 (12.12.2022)
|
||||||
|
[FATAL] Неизвестная ошибка: Index 103 out of bounds for length 103 (12.12.2022)
|
21
Infos.log
Normal file
21
Infos.log
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
[INFO ] Переход на карту fsdfws (12.12.2022)
|
||||||
|
[INFO ] Добавлена карта: fsdfws (12.12.2022)
|
||||||
|
[INFO ] Переход на карту fsdfws (12.12.2022)
|
||||||
|
[INFO ] Загрузка карты из файла: C:\Users\Анюта\OneDrive\Документы\MapWithFullStorage (12.12.2022)
|
||||||
|
[INFO ] Переход на карту dsafwsdf (12.12.2022)
|
||||||
|
[INFO ] Переход на карту dsafwsdf (12.12.2022)
|
||||||
|
[INFO ] Объект на позиции32удален (12.12.2022)
|
||||||
|
[INFO ] Новый объект добавлен (12.12.2022)
|
||||||
|
[INFO ] Сохранение карты в файл: C:\Users\Анюта\OneDrive\Документы\MapWithFullStorage (12.12.2022)
|
||||||
|
[INFO ] Переход на карту frrfwe (12.12.2022)
|
||||||
|
[INFO ] Добавлена карта: frrfwe (12.12.2022)
|
||||||
|
[INFO ] Переход на карту frrfwe (12.12.2022)
|
||||||
|
[INFO ] Добавлена карта: frrfwe (12.12.2022)
|
||||||
|
[INFO ] Переход на карту e2rew (12.12.2022)
|
||||||
|
[INFO ] Добавлена карта: e2rew (12.12.2022)
|
||||||
|
[INFO ] Новый объект добавлен (12.12.2022)
|
||||||
|
[INFO ] Переход на карту e2rew (12.12.2022)
|
||||||
|
[INFO ] Загрузка карты из файла: C:\Users\Анюта\OneDrive\Документы\MapWithFullStorage (12.12.2022)
|
||||||
|
[INFO ] Переход на карту dsafwsdf (12.12.2022)
|
||||||
|
[INFO ] Переход на карту dsafwsdf (12.12.2022)
|
||||||
|
[INFO ] Объект на позиции103удален (12.12.2022)
|
15
src/FileDataFormatException.java
Normal file
15
src/FileDataFormatException.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class FileDataFormatException extends IOException {
|
||||||
|
public FileDataFormatException(){
|
||||||
|
}
|
||||||
|
public FileDataFormatException(String message){
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
public FileDataFormatException(String message,Throwable exception){
|
||||||
|
super(message,exception);
|
||||||
|
}
|
||||||
|
protected FileDataFormatException(Throwable exception){
|
||||||
|
super(exception);
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,7 @@ import java.io.IOException;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
public class FormMapWithSetWarships extends JFrame{
|
public class FormMapWithSetWarships extends JFrame{
|
||||||
|
|
||||||
@ -38,6 +39,12 @@ public class FormMapWithSetWarships extends JFrame{
|
|||||||
put("Вторая карта",new SecondMap());
|
put("Вторая карта",new SecondMap());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
private Logger logger;
|
||||||
|
|
||||||
|
public FormMapWithSetWarships(Logger logger){
|
||||||
|
this();
|
||||||
|
this.logger=logger;
|
||||||
|
}
|
||||||
|
|
||||||
public FormMapWithSetWarships(){
|
public FormMapWithSetWarships(){
|
||||||
setTitle("Военный корабль");
|
setTitle("Военный корабль");
|
||||||
@ -94,13 +101,12 @@ public class FormMapWithSetWarships extends JFrame{
|
|||||||
dialog.showSaveDialog(this);
|
dialog.showSaveDialog(this);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (_mapsCollection.SaveData(dialog.getSelectedFile().getAbsolutePath())) {
|
_mapsCollection.SaveData(dialog.getSelectedFile().getAbsolutePath());
|
||||||
JOptionPane.showMessageDialog(this, "Сохранение прошло успешно", "Итог", JOptionPane.INFORMATION_MESSAGE);
|
logger.info("Сохранение всех карт в файл: "+dialog.getSelectedFile().getAbsolutePath());
|
||||||
} else {
|
JOptionPane.showMessageDialog(this, "Сохранение всех карт прошло успешно", "Итог", JOptionPane.INFORMATION_MESSAGE);
|
||||||
JOptionPane.showMessageDialog(this, "Не сохранилось", "Итог", JOptionPane.ERROR_MESSAGE);
|
} catch (Exception ex) {
|
||||||
}
|
logger.error("Ошибка сохранения всех карт в файл: "+ex.getMessage());
|
||||||
} catch (IOException ex) {
|
JOptionPane.showMessageDialog(this, "Ошибка сохранения всех карт: "+ex.getMessage(), "Итог", JOptionPane.ERROR_MESSAGE);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
fileMenu.add(SaveMenuItem);
|
fileMenu.add(SaveMenuItem);
|
||||||
@ -112,14 +118,13 @@ public class FormMapWithSetWarships extends JFrame{
|
|||||||
dialog.showOpenDialog(this);
|
dialog.showOpenDialog(this);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (_mapsCollection.LoadData(dialog.getSelectedFile().getAbsolutePath())) {
|
_mapsCollection.LoadData(dialog.getSelectedFile().getAbsolutePath());
|
||||||
ReloadMaps();
|
ReloadMaps();
|
||||||
JOptionPane.showMessageDialog(this, "Загрузка прошла успешно", "Итог", JOptionPane.INFORMATION_MESSAGE);
|
logger.info("Загрузка всех карт из файла: "+dialog.getSelectedFile().getAbsolutePath());
|
||||||
} else {
|
JOptionPane.showMessageDialog(this, "Загрузка всех карт прошла успешно", "Итог", JOptionPane.INFORMATION_MESSAGE);
|
||||||
JOptionPane.showMessageDialog(this, "Не загрузилось", "Итог", JOptionPane.ERROR_MESSAGE);
|
} catch (Exception ex) {
|
||||||
}
|
logger.error("Ошибка загрузки всех карт из файла: "+ex.getMessage());
|
||||||
} catch (IOException ex) {
|
JOptionPane.showMessageDialog(this, "Ошибка загрузки всех карт"+ex.getMessage(), "Итог", JOptionPane.ERROR_MESSAGE);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
fileMenu.add(LoadMenuItem);
|
fileMenu.add(LoadMenuItem);
|
||||||
@ -131,13 +136,12 @@ public class FormMapWithSetWarships extends JFrame{
|
|||||||
dialog.showSaveDialog(this);
|
dialog.showSaveDialog(this);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (_mapsCollection.SaveMap((String) Optional.ofNullable(ListBoxMaps.getSelectedValue()).orElse(""), dialog.getSelectedFile().getAbsolutePath())) {
|
_mapsCollection.SaveMap((String) Optional.ofNullable(ListBoxMaps.getSelectedValue()).orElse(""), dialog.getSelectedFile().getAbsolutePath());
|
||||||
JOptionPane.showMessageDialog(this, "Сохранение прошло успешно", "Итог", JOptionPane.INFORMATION_MESSAGE);
|
logger.info("Сохранение карты в файл: "+dialog.getSelectedFile().getAbsolutePath());
|
||||||
} else {
|
JOptionPane.showMessageDialog(this, "Сохранение карты прошло успешно", "Итог", JOptionPane.INFORMATION_MESSAGE);
|
||||||
JOptionPane.showMessageDialog(this, "Не сохранилось", "Итог", JOptionPane.ERROR_MESSAGE);
|
} catch (Exception ex) {
|
||||||
}
|
logger.error("Ошибка сохранения карты в файл: "+ex.getMessage());
|
||||||
} catch (IOException ex) {
|
JOptionPane.showMessageDialog(this, "Ошибка сохранения карты: "+ex.getMessage(), "Итог", JOptionPane.ERROR_MESSAGE);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
fileMenu.add(SaveMapMenuItem);
|
fileMenu.add(SaveMapMenuItem);
|
||||||
@ -149,14 +153,13 @@ public class FormMapWithSetWarships extends JFrame{
|
|||||||
dialog.showOpenDialog(this);
|
dialog.showOpenDialog(this);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (_mapsCollection.LoadMap(dialog.getSelectedFile().getAbsolutePath())) {
|
_mapsCollection.LoadMap(dialog.getSelectedFile().getAbsolutePath());
|
||||||
ReloadMaps();
|
ReloadMaps();
|
||||||
JOptionPane.showMessageDialog(this, "Загрузка прошла успешно", "Итог", JOptionPane.INFORMATION_MESSAGE);
|
logger.info("Загрузка карты из файла: "+dialog.getSelectedFile().getAbsolutePath());
|
||||||
} else {
|
JOptionPane.showMessageDialog(this, "Загрузка карты прошла успешно", "Итог", JOptionPane.INFORMATION_MESSAGE);
|
||||||
JOptionPane.showMessageDialog(this, "Не загрузилось", "Итог", JOptionPane.ERROR_MESSAGE);
|
} catch (Exception ex) {
|
||||||
}
|
logger.error("Ошибка загрузки карты из файла: "+ex.getMessage());
|
||||||
} catch (IOException ex) {
|
JOptionPane.showMessageDialog(this, "Ошибка загрузки карты"+ex.getMessage(), "Итог", JOptionPane.ERROR_MESSAGE);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
fileMenu.add(LoadMapMenuItem);
|
fileMenu.add(LoadMapMenuItem);
|
||||||
@ -168,6 +171,7 @@ public class FormMapWithSetWarships extends JFrame{
|
|||||||
return;
|
return;
|
||||||
bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet();
|
bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet();
|
||||||
repaint();
|
repaint();
|
||||||
|
logger.info("Переход на карту "+ListBoxMaps.getSelectedValue());
|
||||||
});
|
});
|
||||||
|
|
||||||
DeleteMapButton.addActionListener(e -> {
|
DeleteMapButton.addActionListener(e -> {
|
||||||
@ -179,6 +183,7 @@ public class FormMapWithSetWarships extends JFrame{
|
|||||||
"Удаление",JOptionPane.YES_NO_OPTION)==0)
|
"Удаление",JOptionPane.YES_NO_OPTION)==0)
|
||||||
{
|
{
|
||||||
_mapsCollection.DelMap(ListBoxMaps.getSelectedValue().toString());
|
_mapsCollection.DelMap(ListBoxMaps.getSelectedValue().toString());
|
||||||
|
logger.info("Карта "+ListBoxMaps.getSelectedValue()+" удалена");
|
||||||
ReloadMaps();
|
ReloadMaps();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -186,16 +191,19 @@ public class FormMapWithSetWarships extends JFrame{
|
|||||||
CreateMapButton.addActionListener(e -> {
|
CreateMapButton.addActionListener(e -> {
|
||||||
if (СomboBoxSelectorMap.getSelectedIndex() == -1 || TextFieldMap.getText()==null || TextFieldMap.getText().equals(""))
|
if (СomboBoxSelectorMap.getSelectedIndex() == -1 || TextFieldMap.getText()==null || TextFieldMap.getText().equals(""))
|
||||||
{
|
{
|
||||||
|
logger.warn("При добавлении карты не все данные были заполнены");
|
||||||
JOptionPane.showMessageDialog(this,"Не все данные заполнены","Ошибка",JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(this,"Не все данные заполнены","Ошибка",JOptionPane.ERROR_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!_mapsDict.containsKey(СomboBoxSelectorMap.getSelectedItem()))
|
if (!_mapsDict.containsKey(СomboBoxSelectorMap.getSelectedItem()))
|
||||||
{
|
{
|
||||||
|
logger.warn("Карты не существует");
|
||||||
JOptionPane.showMessageDialog(this,"Нет такой карты","Ошибка",JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(this,"Нет такой карты","Ошибка",JOptionPane.ERROR_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_mapsCollection.AddMap(TextFieldMap.getText(), _mapsDict.get(СomboBoxSelectorMap.getSelectedItem().toString()));
|
_mapsCollection.AddMap(TextFieldMap.getText(), _mapsDict.get(СomboBoxSelectorMap.getSelectedItem().toString()));
|
||||||
ReloadMaps();
|
ReloadMaps();
|
||||||
|
logger.info("Добавлена карта: "+TextFieldMap.getText());
|
||||||
});
|
});
|
||||||
|
|
||||||
ButtonShowOnMap.addActionListener(e -> {
|
ButtonShowOnMap.addActionListener(e -> {
|
||||||
@ -224,14 +232,24 @@ public class FormMapWithSetWarships extends JFrame{
|
|||||||
FormWarshipConfig dialog=new FormWarshipConfig();
|
FormWarshipConfig dialog=new FormWarshipConfig();
|
||||||
dialog.addListener(obj -> {
|
dialog.addListener(obj -> {
|
||||||
if (obj!=null) {
|
if (obj!=null) {
|
||||||
DrawingObjectWarship warship = new DrawingObjectWarship(obj);
|
try {
|
||||||
|
DrawingObjectWarship warship = new DrawingObjectWarship(obj);
|
||||||
|
|
||||||
if (_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).plus(warship)>=0) {
|
if (_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).plus(warship) >= 0) {
|
||||||
JOptionPane.showMessageDialog(this, "Объект добавлен", "Успех", JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(this, "Объект добавлен", "Успех", JOptionPane.INFORMATION_MESSAGE);
|
||||||
bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet();
|
bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet();
|
||||||
repaint();
|
repaint();
|
||||||
} else {
|
logger.info("Новый объект добавлен");
|
||||||
JOptionPane.showMessageDialog(this, "Не удалось добавить объект", "Ошибка",JOptionPane.INFORMATION_MESSAGE);
|
} else {
|
||||||
|
logger.warn("Не удалось добавить объект");
|
||||||
|
JOptionPane.showMessageDialog(this, "Не удалось добавить объект", "Ошибка", JOptionPane.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
}catch (StorageOverflowException ex){
|
||||||
|
logger.warn("Хранилище переполнено: "+ex.getMessage());
|
||||||
|
JOptionPane.showMessageDialog(this, "Ошибка. Хранилище переполнено: "+ex.getMessage(), "Ошибка", JOptionPane.ERROR_MESSAGE);
|
||||||
|
}catch (Exception ex){
|
||||||
|
logger.fatal("Неизвестная ошибка: "+ex.getMessage());
|
||||||
|
JOptionPane.showMessageDialog(this, "Неизвестная ошибка: "+ex.getMessage(), "Ошибка", JOptionPane.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -252,14 +270,23 @@ public class FormMapWithSetWarships extends JFrame{
|
|||||||
if (result!=0)
|
if (result!=0)
|
||||||
return;
|
return;
|
||||||
int pos = Integer.parseInt(txt);
|
int pos = Integer.parseInt(txt);
|
||||||
if(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).minus(pos)!=null){
|
|
||||||
JOptionPane.showMessageDialog(this, "Объект удален", "Успех", JOptionPane.INFORMATION_MESSAGE);
|
try {
|
||||||
bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet();
|
if (_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).minus(pos) != null) {
|
||||||
repaint();
|
JOptionPane.showMessageDialog(this, "Объект удален", "Успех", JOptionPane.INFORMATION_MESSAGE);
|
||||||
}
|
bufferedImage = _mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet();
|
||||||
else
|
repaint();
|
||||||
{
|
logger.info("Объект на позиции"+pos+"удален");
|
||||||
JOptionPane.showMessageDialog(this,"Не удалось удалить объект","Ошибка",JOptionPane.INFORMATION_MESSAGE);
|
} else {
|
||||||
|
logger.warn("Не удалось удалить объект на позиции"+pos);
|
||||||
|
JOptionPane.showMessageDialog(this, "Не удалось удалить объект", "Ошибка", JOptionPane.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
} catch(WarshipNotFoundException ex){
|
||||||
|
logger.warn("Ошибка удаления: "+ex.getMessage());
|
||||||
|
JOptionPane.showMessageDialog(this, "Ошибка удаления: "+ex.getMessage(), "Ошибка", JOptionPane.ERROR_MESSAGE);
|
||||||
|
}catch (Exception ex){
|
||||||
|
logger.fatal("Неизвестная ошибка: "+ex.getMessage());
|
||||||
|
JOptionPane.showMessageDialog(this, "Неизвестная ошибка: "+ex.getMessage(), "Ошибка", JOptionPane.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
import org.apache.logging.log4j.*;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new FormMapWithSetWarships();
|
new FormMapWithSetWarships(LogManager.getLogger(Main.class));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -50,7 +50,7 @@ public class MapsCollection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
public boolean SaveData(String filename) throws IOException {
|
public void SaveData(String filename) throws IOException {
|
||||||
|
|
||||||
File file = new File(filename);
|
File file = new File(filename);
|
||||||
|
|
||||||
@ -66,21 +66,20 @@ public class MapsCollection {
|
|||||||
writer.println(String.format("%s%c%s", storage.getKey(), separatorDict, storage.getValue().GetData(separatorDict, separatorData)));
|
writer.println(String.format("%s%c%s", storage.getKey(), separatorDict, storage.getValue().GetData(separatorDict, separatorData)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean LoadData(String filename) throws IOException {
|
public void LoadData(String filename) throws IOException {
|
||||||
|
|
||||||
File file = new File(filename);
|
File file = new File(filename);
|
||||||
|
|
||||||
if (!file.exists())
|
if (!file.exists())
|
||||||
return false;
|
throw new FileNotFoundException("Файл не найден");
|
||||||
|
|
||||||
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
|
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
|
||||||
String currentLine = reader.readLine();
|
String currentLine = reader.readLine();
|
||||||
|
|
||||||
if (currentLine == null || !currentLine.contains("MapsCollection"))
|
if (currentLine == null || !currentLine.contains("MapsCollection"))
|
||||||
return false;
|
throw new FileDataFormatException("Формат данных не верный");
|
||||||
|
|
||||||
_mapStorages.clear();
|
_mapStorages.clear();
|
||||||
|
|
||||||
@ -95,11 +94,10 @@ public class MapsCollection {
|
|||||||
_mapStorages.get(elements[0]).LoadData(elements[2].split(separatorData + "\n?"));
|
_mapStorages.get(elements[0]).LoadData(elements[2].split(separatorData + "\n?"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
public boolean SaveMap(String mapName, String filename) throws IOException {
|
public void SaveMap(String mapName, String filename) throws IOException {
|
||||||
File file = new File(filename);
|
File file = new File(filename);
|
||||||
|
|
||||||
if (file.exists())
|
if (file.exists())
|
||||||
@ -110,7 +108,7 @@ public class MapsCollection {
|
|||||||
MapWithSetWarshipsGeneric<DrawingObjectWarship, AbstractMap> map = _mapStorages.getOrDefault(mapName, null);
|
MapWithSetWarshipsGeneric<DrawingObjectWarship, AbstractMap> map = _mapStorages.getOrDefault(mapName, null);
|
||||||
|
|
||||||
if (map == null)
|
if (map == null)
|
||||||
return false;
|
throw new IndexOutOfBoundsException();
|
||||||
|
|
||||||
try (PrintWriter writer = new PrintWriter(file)) {
|
try (PrintWriter writer = new PrintWriter(file)) {
|
||||||
writer.println("Map");
|
writer.println("Map");
|
||||||
@ -120,20 +118,19 @@ public class MapsCollection {
|
|||||||
writer.println(warship.GetInfo());
|
writer.println(warship.GetInfo());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean LoadMap(String filename) throws IOException {
|
public void LoadMap(String filename) throws IOException {
|
||||||
File file = new File(filename);
|
File file = new File(filename);
|
||||||
|
|
||||||
if (!file.exists())
|
if (!file.exists())
|
||||||
return false;
|
throw new FileNotFoundException("Файл не найден");
|
||||||
|
|
||||||
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
|
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
|
||||||
String currentLine = reader.readLine();
|
String currentLine = reader.readLine();
|
||||||
|
|
||||||
if (currentLine == null || !currentLine.contains("Map"))
|
if (currentLine == null || !currentLine.contains("Map"))
|
||||||
return false;
|
throw new FileDataFormatException("Формат данных не верный");
|
||||||
|
|
||||||
String mapName = reader.readLine();
|
String mapName = reader.readLine();
|
||||||
|
|
||||||
@ -141,7 +138,7 @@ public class MapsCollection {
|
|||||||
if (_mapStorages.containsKey(mapName)) {
|
if (_mapStorages.containsKey(mapName)) {
|
||||||
map = _mapStorages.get(mapName);
|
map = _mapStorages.get(mapName);
|
||||||
if (!map.GetMap().getClass().getSimpleName().equals(reader.readLine())) {
|
if (!map.GetMap().getClass().getSimpleName().equals(reader.readLine())) {
|
||||||
return false;
|
throw new FileDataFormatException("Формат данных не верный");
|
||||||
}
|
}
|
||||||
map._setWarship.Clear();
|
map._setWarship.Clear();
|
||||||
} else {
|
} else {
|
||||||
@ -156,7 +153,6 @@ public class MapsCollection {
|
|||||||
}
|
}
|
||||||
_mapStorages.put(mapName, map);
|
_mapStorages.put(mapName, map);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,8 +23,8 @@ public class SetWarshipsGeneric<T extends Object> implements Iterable<T>{
|
|||||||
|
|
||||||
public int Insert(T warship)
|
public int Insert(T warship)
|
||||||
{
|
{
|
||||||
if (_places.size()+1>=_maxCount)
|
if (Count()>=_maxCount)
|
||||||
return -1;
|
throw new StorageOverflowException(_maxCount);
|
||||||
_places.add(0,warship);
|
_places.add(0,warship);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -32,9 +32,7 @@ public class SetWarshipsGeneric<T extends Object> implements Iterable<T>{
|
|||||||
public int Insert(T warship, int position)
|
public int Insert(T warship, int position)
|
||||||
{
|
{
|
||||||
if (position>=_maxCount||position<0)
|
if (position>=_maxCount||position<0)
|
||||||
return -1;
|
throw new StorageOverflowException(_maxCount);
|
||||||
if (_places.size()+1>=_maxCount)
|
|
||||||
return -1;
|
|
||||||
_places.add(position,warship);
|
_places.add(position,warship);
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
@ -44,6 +42,8 @@ public class SetWarshipsGeneric<T extends Object> implements Iterable<T>{
|
|||||||
if (position>=_maxCount||position<0)
|
if (position>=_maxCount||position<0)
|
||||||
return null;
|
return null;
|
||||||
T deleted=_places.get(position);
|
T deleted=_places.get(position);
|
||||||
|
if (deleted==null)
|
||||||
|
throw new WarshipNotFoundException(position);
|
||||||
_places.remove(position);
|
_places.remove(position);
|
||||||
return deleted;
|
return deleted;
|
||||||
}
|
}
|
||||||
|
16
src/StorageOverflowException.java
Normal file
16
src/StorageOverflowException.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
public class StorageOverflowException extends RuntimeException{
|
||||||
|
public StorageOverflowException(){
|
||||||
|
}
|
||||||
|
public StorageOverflowException(String message){
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
public StorageOverflowException(String message,Throwable exception){
|
||||||
|
super(message,exception);
|
||||||
|
}
|
||||||
|
protected StorageOverflowException(Throwable exception){
|
||||||
|
super(exception);
|
||||||
|
}
|
||||||
|
public StorageOverflowException(int count){
|
||||||
|
super("Превышено допустимое количество в хранилище: "+count);
|
||||||
|
}
|
||||||
|
}
|
16
src/WarshipNotFoundException.java
Normal file
16
src/WarshipNotFoundException.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
public class WarshipNotFoundException extends RuntimeException{
|
||||||
|
public WarshipNotFoundException(){
|
||||||
|
}
|
||||||
|
public WarshipNotFoundException(String message){
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
public WarshipNotFoundException(String message,Throwable exception){
|
||||||
|
super(message,exception);
|
||||||
|
}
|
||||||
|
public WarshipNotFoundException(Throwable exception){
|
||||||
|
super(exception);
|
||||||
|
}
|
||||||
|
protected WarshipNotFoundException(int pos){
|
||||||
|
super("Корабль по позиции "+pos+" не найден");
|
||||||
|
}
|
||||||
|
}
|
27
src/log4j2.xml
Normal file
27
src/log4j2.xml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||||
|
<Configuration status="info">
|
||||||
|
<Appenders>
|
||||||
|
<File name="error" fileName="Errors.log" append="true">
|
||||||
|
<PatternLayout>
|
||||||
|
<Pattern>
|
||||||
|
[%-5level] %msg (%d{dd.MM.yyyy})%n
|
||||||
|
</Pattern>
|
||||||
|
</PatternLayout>
|
||||||
|
<ThresholdFilter level="WARN" onMatch="ACCEPT" onMismatch="DENY"/>
|
||||||
|
</File>
|
||||||
|
<File name="info" fileName="Infos.log" append="true">
|
||||||
|
<PatternLayout>
|
||||||
|
<Pattern>
|
||||||
|
[%-5level] %msg (%d{dd.MM.yyyy})%n
|
||||||
|
</Pattern>
|
||||||
|
</PatternLayout>
|
||||||
|
<ThresholdFilter level="WARN" onMatch="DENY" onMismatch="ACCEPT"/>
|
||||||
|
</File>
|
||||||
|
</Appenders>
|
||||||
|
<Loggers>
|
||||||
|
<Root level="INFO">
|
||||||
|
<AppenderRef ref="info"/>
|
||||||
|
<AppenderRef ref="error"/>
|
||||||
|
</Root>
|
||||||
|
</Loggers>
|
||||||
|
</Configuration>
|
Loading…
x
Reference in New Issue
Block a user