/
nikolay470
/
algorithm_implementation
Обзор
Документация
Войти
/
nikolay470
/
algorithm_implementation
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/main/java/ru/gitflic/classes/PrintedCell.java
86 строк
3 KB
nikolay94
Коммит перед сменой ОС
21 июн 2026, 19:09
21 июн 2026, 19:09
24ae6bf
Код
Авторство
О чём код?
package ru.gitflic.classes; import ru.gitflic.enums.Products; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.HashMap; public class PrintedCell { public final Address address; public Products product; public LocalDate dateProduction; private final HashMap<Integer, Pallet> pallets; public final int size; public PrintedCell(Address address) { this.address = address; this.size = 15; this.pallets = new HashMap<>(size); } public void placeThePallet(Pallet pallet) throws Exception { if (this.pallets.isEmpty()) { this.product = pallet.product; this.dateProduction = pallet.dateProduction; this.pallets.put(pallet.numberPalletSheet, pallet); } else if (!this.pallets.isEmpty() && this.pallets.size() < 15) { if (this.product.equals(pallet.product) && this.dateProduction.equals(pallet.dateProduction) && pallet.isFull) { this.pallets.put(pallet.numberPalletSheet, pallet); } else { throw new Exception("Несоответствие продукции или даты производства"); } } else if (this.pallets.size() == 15) { throw new Exception("Ячейка заполнена"); } } public Pallet giveAwayPallet(int numberPalletSheet) { if (this.pallets.isEmpty()) { throw new RuntimeException("Набивная ячейка пуста"); } else { return this.pallets.remove(numberPalletSheet); } } public int getQuantPalletsInCell() { return this.pallets.size(); } public ArrayList<Pallet> getListPalletsInCell() { return (ArrayList<Pallet>) this.pallets.values(); } public Pallet getPalletForComparison() { return this.pallets.values().stream().toList().getFirst(); } public String toString() { if ( this.pallets.isEmpty() ) { return "Набивная ячейка: " + this.address.toString() + "\n" + "Колличество паллет: 0"; } else { return "Набивная ячейка: " + this.address.toString() + "\n" + "Колличество паллет: " + this.pallets.size() + "\n" + "Описание паллета." + "\n" + "Продукция: " + (this.product != null ? this.product.toString() : "нет") + "\n" + "Дата производства: " + (this.dateProduction != null ? this.dateProduction.format(DateTimeFormatter.ofPattern("dd-MM-yyyy")) : "-") + "\n"; } } public boolean equals(PrintedCell other) { if (other == null) { return false; } return this.address.equals(other.address); } }