component model
This commit is contained in:
parent
b2c36766bd
commit
230de1ccaf
94
src/main/java/ru/ulstu/is/sbapp/repair/model/Component.java
Normal file
94
src/main/java/ru/ulstu/is/sbapp/repair/model/Component.java
Normal file
@ -0,0 +1,94 @@
|
||||
package ru.ulstu.is.sbapp.repair.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@Table(name = "components")
|
||||
public class Component {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
@Column(name = "name")
|
||||
private String componentName;
|
||||
@Column(name = "amount")
|
||||
private Integer amount;
|
||||
|
||||
// @OneToMany(mappedBy = "component", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||
// @JsonIgnore
|
||||
//private List<FavorComponents> favor;
|
||||
|
||||
public Component() {
|
||||
}
|
||||
|
||||
public Component(String componentName, Integer amount) {
|
||||
this.componentName = componentName;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getComponentName() {
|
||||
return componentName;
|
||||
}
|
||||
|
||||
public void setComponentName(String componentName) {
|
||||
this.componentName = componentName;
|
||||
}
|
||||
|
||||
public Integer getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(Integer amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public List<FavorComponents> getFavors() {
|
||||
return Favors;
|
||||
}
|
||||
|
||||
public void setFavors(List<FavorComponents> favors) {
|
||||
this.favors = favors;
|
||||
}
|
||||
|
||||
public void addFavor(FavorComponents favorComponents) {
|
||||
if (favors == null) {
|
||||
favors = new ArrayList<>();
|
||||
}
|
||||
if (!favors.contains(favorComponents))
|
||||
this.favors.add(favorComponents);
|
||||
}
|
||||
|
||||
public void removeFavor(FavorComponents favorComponents) {
|
||||
if (favors.contains(favorComponents))
|
||||
this.favors.remove(favorComponents);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Component component = (Component) o;
|
||||
return Objects.equals(id, component.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Component{" +
|
||||
"id=" + id +
|
||||
", componentName='" + componentName + '\'' +
|
||||
", amount='" + amount + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user