From 62fabdd97c54756ae00f387fb3766e5d06e83dd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BE=D0=BB=D0=BE=D0=B4=D0=B8=D0=BD=20=D0=93=D0=B5?= =?UTF-8?q?=D1=80=D0=BC=D0=B0=D0=BD?= Date: Tue, 1 Sep 2026 21:55:11 +0400 Subject: [PATCH] feat(creation): complete random fill settings --- .../random/RandomDataSettingsWindow.java | 48 +++++++++++++++++++ .../creation/random/RandomFillSettings.java | 12 +++++ .../creation/random/RandomFillStrategy.java | 33 +++++++++++-- 3 files changed, 90 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/ru/project/ui/creation/random/RandomDataSettingsWindow.java b/app/src/main/java/ru/project/ui/creation/random/RandomDataSettingsWindow.java index fcba4e1..5cc80c7 100644 --- a/app/src/main/java/ru/project/ui/creation/random/RandomDataSettingsWindow.java +++ b/app/src/main/java/ru/project/ui/creation/random/RandomDataSettingsWindow.java @@ -15,6 +15,7 @@ public class RandomDataSettingsWindow extends BaseModalWindow { private final RandomFillSettings settings; private final Consumer onApply; + private final Label collectionSizeLabel; private final Label minGroupNumberLabel; private final Label maxGroupNumberLabel; private final Label minAverageGradeLabel; @@ -32,6 +33,10 @@ public class RandomDataSettingsWindow extends BaseModalWindow { Panel panel = new Panel(); panel.setLayoutManager(new LinearLayout()); + collectionSizeLabel = + new Label("Размер коллекции: " + getValueOrDefault(settings.getCollectionSize())); + + panel.addComponent(collectionSizeLabel); minGroupNumberLabel = new Label("Минимальный номер группы: " + getValueOrDefault(settings.getMinGroupNumber())); @@ -61,6 +66,8 @@ public class RandomDataSettingsWindow extends BaseModalWindow { panel.addComponent(minRecordBookNumberLabel); panel.addComponent(maxRecordBookNumberLabel); + panel.addComponent(new Button("Задать размер коллекции...", this::setCollectionSize)); + panel.addComponent(new Button("Задать минимальный номер группы", this::setMinGroupNumber)); panel.addComponent(new Button("Задать максимальный номер группы", this::setMaxGroupNumber)); @@ -82,6 +89,41 @@ public class RandomDataSettingsWindow extends BaseModalWindow { setComponent(panel); } + private void setCollectionSize() { + InputValueWindow window = + new InputValueWindow( + gui, + "Размер коллекции", + "Введите размер коллекции:", + settings.getCollectionSize() == null + ? null + : String.valueOf(settings.getCollectionSize()), + value -> { + try { + int collectionSize = Integer.parseInt(value); + + if (collectionSize <= 0) { + MessageWindow.showModal(gui, "Размер коллекции должен быть больше 0."); + + return false; + } + + settings.setCollectionSize(collectionSize); + + collectionSizeLabel.setText("Размер коллекции: " + collectionSize); + + return true; + + } catch (NumberFormatException e) { + MessageWindow.showModal(gui, "Введите целое число."); + + return false; + } + }); + + window.showModal(); + } + private void setMinGroupNumber() { showGroupNumberInput( "Минимальный номер группы", @@ -302,6 +344,12 @@ public class RandomDataSettingsWindow extends BaseModalWindow { } private void apply() { + if (settings.getCollectionSize() == null) { + MessageWindow.showModal(gui, "Сначала задайте размер коллекции."); + + return; + } + onApply.accept(settings); MessageWindow.showModal(gui, "Настройки создания коллекции случайно успешно применены."); diff --git a/app/src/main/java/ru/project/ui/creation/random/RandomFillSettings.java b/app/src/main/java/ru/project/ui/creation/random/RandomFillSettings.java index eab4334..22befaf 100644 --- a/app/src/main/java/ru/project/ui/creation/random/RandomFillSettings.java +++ b/app/src/main/java/ru/project/ui/creation/random/RandomFillSettings.java @@ -2,6 +2,8 @@ package ru.project.ui.creation.random; public class RandomFillSettings { + private Integer collectionSize; + private String minGroupNumber; private String maxGroupNumber; @@ -12,6 +14,8 @@ public class RandomFillSettings { private Integer maxRecordBookNumber; public RandomFillSettings() { + this.collectionSize = null; + this.minGroupNumber = null; this.maxGroupNumber = null; @@ -22,6 +26,14 @@ public class RandomFillSettings { this.maxRecordBookNumber = null; } + public Integer getCollectionSize() { + return collectionSize; + } + + public void setCollectionSize(Integer collectionSize) { + this.collectionSize = collectionSize; + } + public String getMinGroupNumber() { return minGroupNumber; } diff --git a/app/src/main/java/ru/project/ui/creation/random/RandomFillStrategy.java b/app/src/main/java/ru/project/ui/creation/random/RandomFillStrategy.java index bbebc93..77dd072 100644 --- a/app/src/main/java/ru/project/ui/creation/random/RandomFillStrategy.java +++ b/app/src/main/java/ru/project/ui/creation/random/RandomFillStrategy.java @@ -1,19 +1,46 @@ package ru.project.ui.creation.random; import ru.project.collection.MyList; +import ru.project.random.RandomStudentGenerator; import ru.project.student.Student; import ru.project.ui.creation.FillStrategy; public class RandomFillStrategy implements FillStrategy { - // private final RandomFillSettings settings; + private final RandomFillSettings settings; public RandomFillStrategy(RandomFillSettings settings) { - // this.settings = settings; + this.settings = settings; } @Override public MyList create() { - return null; + RandomStudentGenerator generator = new RandomStudentGenerator(); + + if (settings.getMinGroupNumber() != null) { + generator.setMinGroupNumber(settings.getMinGroupNumber()); + } + + if (settings.getMaxGroupNumber() != null) { + generator.setMaxGroupNumber(settings.getMaxGroupNumber()); + } + + if (settings.getMinAverageGrade() != null) { + generator.setMinAverageGrade(settings.getMinAverageGrade()); + } + + if (settings.getMaxAverageGrade() != null) { + generator.setMaxAverageGrade(settings.getMaxAverageGrade()); + } + + if (settings.getMinRecordBookNumber() != null) { + generator.setMinRecordBookNumber(settings.getMinRecordBookNumber()); + } + + if (settings.getMaxRecordBookNumber() != null) { + generator.setMaxRecordBookNumber(settings.getMaxRecordBookNumber()); + } + + return generator.generate(settings.getCollectionSize()); } }