From 9297fb06ae577328838323be77ea2021af710a78 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Mon, 27 Mar 2023 17:51:24 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=BC=D0=B5=D0=B6=D1=83?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BD=D0=BE=D0=B5=20=D1=81=D0=BE=D1=85=D1=80?= =?UTF-8?q?=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../labWork/premium_store/model/Tank.java | 65 ++++++++++++++----- 1 file changed, 47 insertions(+), 18 deletions(-) diff --git a/spring_online_calculator/src/main/java/labWork/premium_store/model/Tank.java b/spring_online_calculator/src/main/java/labWork/premium_store/model/Tank.java index ea271e8..f3b2ae1 100644 --- a/spring_online_calculator/src/main/java/labWork/premium_store/model/Tank.java +++ b/spring_online_calculator/src/main/java/labWork/premium_store/model/Tank.java @@ -1,7 +1,9 @@ package labWork.premium_store.model; import javax.persistence.*; +import java.util.ArrayList; import java.util.List; +import java.util.Objects; @Entity public class Tank { @@ -20,18 +22,23 @@ public class Tank { @JoinColumn(name = "level_id") private Level level; + @Column(nullable = false) + private int cost; + + //реализация двунаправленной связи мнокие-ко-многим @ManyToMany @JoinTable(name = "tanks_of_clients", joinColumns = @JoinColumn(name = "tank_fk"), inverseJoinColumns = @JoinColumn(name = "client_fk")) private List clients; - @Column(nullable = false) - private int cost; - public Tank() { } + public Long getId(){ + return id; + } + public Tank(String name, int cost) { this.name = name; this.cost = cost; @@ -53,35 +60,57 @@ public class Tank { this.cost = cost; } - public List getProducts() { - return products; + public Level getLevel() { + return level; } - public void setProducts(List products) { - this.products = products; + public void setLevel(Level level) { + this.level = level; } - public void addProduct(OrderProducts orderProducts){ - if (products == null){ - this.products = new ArrayList<>(); + public Nation getNation() { + return nation; + } + + public void setNation(Nation nation) { + this.nation = nation; + } + + public List getClients() { + return clients; + } + + public void setClients(List clients) { + this.clients = clients; + } + + public void addClient(Client newClient){ + if (clients == null){ + this.clients = new ArrayList<>(); } - if (!products.contains(orderProducts)) - this.products.add(orderProducts); + + if (!clients.contains(newClient)) + this.clients.add(newClient); } - public void removeProducts(OrderProducts orderProducts){ - if (products.contains(orderProducts)) - this.products.remove(orderProducts); + + public void removeClient(Client remClient){ + if (clients.contains(remClient)) + this.clients.remove(remClient); } @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof Order order)) return false; - return Objects.equals(getId(), order.getId()) && Objects.equals(getDate(), order.getDate()) && Objects.equals(getPrice(), order.getPrice()); + + if (!(o instanceof Tank tank)) return false; + + return Objects.equals(getId(), tank.getId()) && Objects.equals(getName(), tank.getName()) + && Objects.equals(getCost(), tank.getCost()) && Objects.equals(getClients(), tank.getClients()) + && Objects.equals(getLevel(), tank.getLevel()); } @Override public int hashCode() { - return Objects.hash(getId(), getDate(), getPrice()); + return Objects.hash(getId(), getName(), getLevel(), getClients(), getCost()); } }