|
1 | | -package ru.romanow.jpa.domain; |
| 1 | +package ru.romanow.jpa.domain |
2 | 2 |
|
3 | | -import lombok.Data; |
4 | | -import lombok.experimental.Accessors; |
5 | | -import org.apache.commons.lang3.builder.ToStringBuilder; |
| 3 | +import jakarta.persistence.* |
6 | 4 |
|
7 | | -import jakarta.persistence.*; |
8 | | -import java.util.List; |
9 | | -import java.util.Objects; |
10 | | -import java.util.StringJoiner; |
11 | | - |
12 | | -@Data |
13 | | -@Accessors(chain = true) |
14 | 5 | @Entity |
15 | 6 | @Table(name = "address") |
16 | | -public class Address { |
17 | | - |
| 7 | +data class Address( |
18 | 8 | @Id |
19 | 9 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
20 | | - private Integer id; |
| 10 | + val id: Int? = null, |
21 | 11 |
|
22 | 12 | @Column(name = "city", nullable = false) |
23 | | - private String city; |
| 13 | + var city: String? = null, |
24 | 14 |
|
25 | 15 | @Column(name = "country", nullable = false) |
26 | | - private String country; |
| 16 | + var country: String? = null, |
27 | 17 |
|
28 | 18 | @Column(name = "street") |
29 | | - private String street; |
| 19 | + var street: String? = null, |
30 | 20 |
|
31 | 21 | @Column(name = "address", nullable = false) |
32 | | - private String address; |
33 | | - |
34 | | - @Override |
35 | | - public boolean equals(Object o) { |
36 | | - if (this == o) return true; |
37 | | - if (o == null || getClass() != o.getClass()) return false; |
38 | | - Address other = (Address) o; |
39 | | - return Objects.equals(city, other.city) && Objects.equals(country, other.country) && Objects.equals(street, other.street) && Objects.equals(address, other.address); |
| 22 | + var address: String? = null, |
| 23 | +) { |
| 24 | + override fun equals(other: Any?): Boolean { |
| 25 | + if (this === other) return true |
| 26 | + if (other !is Address) return false |
| 27 | + |
| 28 | + if (id != other.id) return false |
| 29 | + if (city != other.city) return false |
| 30 | + if (country != other.country) return false |
| 31 | + if (street != other.street) return false |
| 32 | + if (address != other.address) return false |
| 33 | + |
| 34 | + return true |
40 | 35 | } |
41 | 36 |
|
42 | | - @Override |
43 | | - public int hashCode() { |
44 | | - return Objects.hash(city, country, street, address); |
| 37 | + override fun hashCode(): Int { |
| 38 | + var result = id ?: 0 |
| 39 | + result = 31 * result + (city?.hashCode() ?: 0) |
| 40 | + result = 31 * result + (country?.hashCode() ?: 0) |
| 41 | + result = 31 * result + (street?.hashCode() ?: 0) |
| 42 | + result = 31 * result + (address?.hashCode() ?: 0) |
| 43 | + return result |
45 | 44 | } |
46 | 45 |
|
47 | | - @Override |
48 | | - public String toString() { |
49 | | - return new ToStringBuilder(this) |
50 | | - .append("id", id) |
51 | | - .append("city", city) |
52 | | - .append("country", country) |
53 | | - .append("street", street) |
54 | | - .append("address", address) |
55 | | - .toString(); |
| 46 | + override fun toString(): String { |
| 47 | + return "Address(id=$id, city=$city, country=$country, street=$street, address=$address)" |
56 | 48 | } |
57 | 49 | } |
0 commit comments