adding sort by engineDrawing, fix saving into file by selected company, fix comparing by engineDrawing
This commit is contained in:
parent
bb212a8c06
commit
2bf7c06cee
@ -285,7 +285,7 @@ public class FormWarPlaneCollection extends Application implements Initializable
|
||||
File selectedFile = fileChooser.showSaveDialog(null);
|
||||
if (selectedFile != null) {
|
||||
try {
|
||||
storageCollection.saveData(selectedFile.getAbsolutePath(), listViewCollection.getSelectionModel().getSelectedItem());
|
||||
storageCollection.saveData(selectedFile.getAbsolutePath(), storageCollection.keys().get(listViewCollection.getSelectionModel().getSelectedIndex()).collectionType());
|
||||
showAlert("Сохранение прошло успешно", "Результат", Alert.AlertType.INFORMATION);
|
||||
userLogger.info("Сохранение в файл: {}", selectedFile.getName());
|
||||
} catch (Exception ex) {
|
||||
|
@ -35,6 +35,7 @@ public abstract class AbstractCompany {
|
||||
if (collection == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return collection.insert(plane, new DrawningPlaneEquatables());
|
||||
}
|
||||
|
||||
|
@ -159,8 +159,6 @@ public class StorageCollection<T extends DrawningWarPlane> {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(entry.getKey());
|
||||
sb.append(SEPARATOR_FOR_KEY_VALUE_ALL_COL);
|
||||
sb.append(entry.getValue().getCollectionType());
|
||||
sb.append(SEPARATOR_FOR_KEY_VALUE_ALL_COL);
|
||||
sb.append(entry.getValue().getMaxCount());
|
||||
sb.append(SEPARATOR_FOR_KEY_VALUE_ALL_COL);
|
||||
|
||||
@ -186,9 +184,9 @@ public class StorageCollection<T extends DrawningWarPlane> {
|
||||
* Сохранение в файл по имени коллекции
|
||||
*
|
||||
* @param path путь к файлу
|
||||
* @param collection название коллекции для сохранения
|
||||
* @param collectionType название коллекции для сохранения
|
||||
*/
|
||||
public void saveData(String path, String collection) throws IOException {
|
||||
public void saveData(String path, CollectionType collectionType) throws IOException {
|
||||
if (storages.isEmpty()) {
|
||||
throw new IllegalArgumentException("В хранилище отсутствуют коллекции для сохранения");
|
||||
}
|
||||
@ -203,7 +201,7 @@ public class StorageCollection<T extends DrawningWarPlane> {
|
||||
writer.newLine();
|
||||
|
||||
for (Map.Entry<CollectionInfo, ICollectionGenericObjects<T>> entry : storages.entrySet()) {
|
||||
if ((entry.getValue().getCount() == 0) || !entry.getKey().equals(collection)) {
|
||||
if ((entry.getValue().getCount() == 0) || entry.getKey().name().equals(collectionType.name())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -2,9 +2,6 @@ package com.projectairfighter.drawnings;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* Comparison by color, speed, weight.
|
||||
*/
|
||||
public class DrawningPlaneCompareByColor implements Comparator<DrawningWarPlane> {
|
||||
|
||||
@Override
|
||||
@ -17,20 +14,17 @@ public class DrawningPlaneCompareByColor implements Comparator<DrawningWarPlane>
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Compare by body color name
|
||||
int bodyColorCompare = y.entityWarPlane.getBodyColor().toString().compareTo(x.entityWarPlane.getBodyColor().toString());
|
||||
|
||||
if (bodyColorCompare != 0) {
|
||||
return bodyColorCompare;
|
||||
}
|
||||
|
||||
// Compare by speed
|
||||
int speedCompare = Integer.compare(y.entityWarPlane.getSpeed(), x.entityWarPlane.getSpeed());
|
||||
if (speedCompare != 0) {
|
||||
return speedCompare;
|
||||
}
|
||||
|
||||
// Compare by weight
|
||||
return Integer.compare((int) y.entityWarPlane.getWeight(), (int) x.entityWarPlane.getWeight());
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,6 @@ package com.projectairfighter.drawnings;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* Comparison by type, speed, weight.
|
||||
*/
|
||||
public class DrawningPlaneCompareByType implements Comparator<DrawningWarPlane> {
|
||||
|
||||
@Override
|
||||
@ -17,18 +14,43 @@ public class DrawningPlaneCompareByType implements Comparator<DrawningWarPlane>
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Compare by type name
|
||||
if (!x.getClass().getName().equals(y.getClass().getName())) {
|
||||
return y.getClass().getName().compareTo(x.getClass().getName());
|
||||
}
|
||||
|
||||
// Compare by speed
|
||||
int speedCompare = Integer.compare(y.entityWarPlane.getSpeed(), x.entityWarPlane.getSpeed());
|
||||
if (speedCompare != 0) {
|
||||
return speedCompare;
|
||||
}
|
||||
|
||||
// Compare by weight
|
||||
return Integer.compare((int) y.entityWarPlane.getWeight(), (int) x.entityWarPlane.getWeight());
|
||||
int weightCompare = Integer.compare((int) y.entityWarPlane.getWeight(), (int) x.entityWarPlane.getWeight());
|
||||
if (weightCompare != 0) {
|
||||
return weightCompare;
|
||||
}
|
||||
|
||||
int engineCountCompare = Integer.compare(getEngineCount(y), getEngineCount(x));
|
||||
if (engineCountCompare != 0) {
|
||||
return engineCountCompare;
|
||||
}
|
||||
|
||||
return getEngineType(x).compareTo(getEngineType(y));
|
||||
}
|
||||
|
||||
private int getEngineCount(DrawningWarPlane plane) {
|
||||
if (plane instanceof IDrawableExtras) {
|
||||
return ((IDrawableExtras) plane).getCountEngines();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private String getEngineType(DrawningWarPlane plane) {
|
||||
if (plane.entityWarPlane.getEngineDrawing() instanceof RectangleEngineDrawing) {
|
||||
return "Rectangle";
|
||||
} else if (plane.entityWarPlane.getEngineDrawing() instanceof TriangleEngineDrawing) {
|
||||
return "Triangle";
|
||||
} else if (plane.entityWarPlane.getEngineDrawing() instanceof EllipticalEngineDrawing) {
|
||||
return "Elliptical";
|
||||
}
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,7 @@ import com.projectairfighter.entities.EntityAirFighter;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* Implementation of the comparison of two drawing class objects.
|
||||
*/
|
||||
|
||||
public class DrawningPlaneEquatables implements Comparator<DrawningWarPlane> {
|
||||
@Override
|
||||
public int compare(DrawningWarPlane x, DrawningWarPlane y) {
|
||||
@ -21,7 +19,7 @@ public class DrawningPlaneEquatables implements Comparator<DrawningWarPlane> {
|
||||
if (x.entityWarPlane.getBodyColor() != y.entityWarPlane.getBodyColor()) return 0;
|
||||
|
||||
if ((x.entityWarPlane.getEngineDrawing().getCountEngines() != y.entityWarPlane.getEngineDrawing().getCountEngines()
|
||||
&& !x.entityWarPlane.getEngineDrawing().getClass().getSimpleName().equals(y.entityWarPlane.getEngineDrawing().getClass().getSimpleName())))
|
||||
|| !x.entityWarPlane.getEngineDrawing().getClass().getSimpleName().equals(y.entityWarPlane.getEngineDrawing().getClass().getSimpleName())))
|
||||
return 0;
|
||||
|
||||
|
||||
|
@ -1,14 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="WARN">
|
||||
<Appenders>
|
||||
<!-- Appender for user actions (INFO level) -->
|
||||
<!-- Управление действиями пользователя (INFO level) -->
|
||||
<File name="UserActionsFile" fileName="logs/user_actions.log">
|
||||
<PatternLayout>
|
||||
<pattern>%d{dd.MM.yyyy} - %msg%n</pattern>
|
||||
</PatternLayout>
|
||||
</File>
|
||||
|
||||
<!-- Appender for all errors (WARN, ERROR, FATAL) -->
|
||||
<!-- Управление всеми ошибками (WARN, ERROR, FATAL) -->
|
||||
<File name="ErrorFile" fileName="logs/errors.log">
|
||||
<PatternLayout>
|
||||
<pattern>%d{dd.MM.yyyy} [%level] - %msg%n</pattern>
|
||||
@ -17,17 +17,17 @@
|
||||
</Appenders>
|
||||
|
||||
<Loggers>
|
||||
<!-- Logger for user actions (INFO level) -->
|
||||
<!-- Логгер для пользователей (INFO level) -->
|
||||
<Logger name="useractions" level="info" additivity="false">
|
||||
<AppenderRef ref="UserActionsFile"/>
|
||||
</Logger>
|
||||
|
||||
<!-- Logger for errors -->
|
||||
<!-- Логгер для ошибок -->
|
||||
<Logger name="errors" level="warn" additivity="false">
|
||||
<AppenderRef ref="ErrorFile"/>
|
||||
</Logger>
|
||||
|
||||
<!-- Root logger for all errors (WARN, ERROR, FATAL) -->
|
||||
<!-- Логгер для всех ошибок (WARN, ERROR, FATAL) -->
|
||||
<Root level="warn">
|
||||
<AppenderRef ref="ErrorFile"/>
|
||||
</Root>
|
||||
|
@ -1,40 +0,0 @@
|
||||
<configuration>
|
||||
|
||||
<appender name="ACTIONS" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>logs/actions.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>logs/actions_%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<maxHistory>30</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>%date{dd.MM.yyyy HH:mm:ss} [%thread] %-5level %logger{35} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="ERRORS" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>logs/errors.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>logs/errors_%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<maxHistory>30</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>%date{dd.MM.yyyy HH:mm:ss} [%thread] %-5level %logger{35} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- Logger для действий пользователя -->
|
||||
<logger level="INFO" additivity="false">
|
||||
<appender-ref ref="ACTIONS" />
|
||||
</logger>
|
||||
|
||||
<!-- Logger для ошибок -->
|
||||
<logger level="WARN" additivity="false">
|
||||
<appender-ref ref="ERRORS" />
|
||||
</logger>
|
||||
|
||||
<!-- Root logger для остальных сообщений -->
|
||||
<root level="ERROR">
|
||||
<appender-ref ref="ERRORS" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
Loading…
x
Reference in New Issue
Block a user