/
nikolay470
/
algorithm_implementation
Обзор
Документация
Войти
/
nikolay470
/
algorithm_implementation
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/main/java/ru/gitflic/classes/Pallet.java
146 строк
4 KB
nikolay94
Коммит перед сменой ОС
21 июн 2026, 19:09
21 июн 2026, 19:09
24ae6bf
Код
Авторство
О чём код?
package ru.gitflic.classes; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.HashMap; import ru.gitflic.enums.Products; public class Pallet { private static int count = 1; public int numberPalletSheet = 0; private Address address = Address.NULL(); public Zone zone = Zone.NULL(); public Products product = Products.NULL; public LocalDate dateProduction = LocalDate.of(1, 1, 1); public int dateExpirationInMonths = 0; public int party = 0; public HashMap<String, Box> boxes = new HashMap<>(); public boolean isFull = false; public boolean isInOrder = false; private String executor = ""; private static final int[] quantBoxesInFullPallet = new int[] {63, 84, 90, 96, 120}; public static Pallet NULL() { return new Pallet(); } public Pallet( Address address, Products product, LocalDate dateProduction, int dateExpirationInMonths, int party, HashMap<String, Box> boxes ) { this.numberPalletSheet = count; count++; this.address = address; this.zone = Zone.NULL(); this.product = product; this.dateProduction = dateProduction; this.dateExpirationInMonths = dateExpirationInMonths; this.party = party; this.boxes = boxes; this.isFull = this.isFull(); } public Pallet( Zone zone, Products product, LocalDate dateProduction, int dateExpirationInMonths, int party, HashMap<String, Box> boxes ) { this.numberPalletSheet = count; count++; this.address = Address.NULL(); this.zone = zone; this.product = product; this.dateProduction = dateProduction; this.dateExpirationInMonths = dateExpirationInMonths; this.party = party; this.boxes = boxes; this.isFull = this.isFull(); this.isInOrder = false; this.executor = null; } private Pallet() {} private boolean isFull() { for (int i = 0; i < Pallet.quantBoxesInFullPallet.length; i++) { if (this.boxes.size() == Pallet.quantBoxesInFullPallet[i]) { return true; } } return false; } public String getExecutor() { return this.executor; } public void take(String loginOfEmployee) throws Exception { if (this.executor.isEmpty()) { this.address = Address.NULL(); this.executor = loginOfEmployee; } else { throw new Exception("Палет находится у исполнителя."); } } public Address getAddress() { return this.address; } public void placement(Address address) { if (!this.executor.isEmpty()) { this.executor = ""; this.address = address; } else { throw new RuntimeException("Палет не у исполнителя"); } } @Override public String toString() { String result = ""; if (this.address.equals(Address.NULL())) { result += "Адрес: " + this.address + "\n"; } else { result += "Зона: " + this.zone + "\n"; } result += "Номер ПЛ: " + this.numberPalletSheet + "\n" + "Продукция: " + this.product.toString() + "\n" + "Дата производства: " + this.dateProduction .format(DateTimeFormatter.ofPattern("dd-MM-yyyy")) + "\n" + "Партия: " + this.party + "\n" + "Срок годности в месяцах: " + this.dateExpirationInMonths + "\n" + "Количество коробов: " + this.boxes.size() + "\n" + "Полный: " + (this.isFull ? "Да" : "Нет") + "\n" + "В заказе: " + (this.isInOrder ? "Да" : "Нет"); return result; } @Override public boolean equals(Object other) { if (other == null || other.getClass() != this.getClass()) { return false; } Pallet otherPallet = (Pallet) other; return (this.numberPalletSheet == otherPallet.numberPalletSheet && this.address.equals(otherPallet.address) && this.zone.equals(otherPallet.zone) && this.product.equals(otherPallet.product) && this.dateProduction.equals(otherPallet.dateProduction) && this.dateExpirationInMonths == otherPallet.dateExpirationInMonths && this.party == otherPallet.party && this.boxes.size() == otherPallet.boxes.size() && this.isFull == otherPallet.isFull && this.isInOrder == otherPallet.isInOrder); } }