Debian Codegraph @

curator-examples/src/main/java/modeled/PersonModel.java

raw
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 package modeled;
21
22 import java.util.Objects;
23
24 public class PersonModel {
25 private final PersonId id;
26 private final ContainerType containerType;
27 private final String firstName;
28 private final String lastName;
29 private final int age;
30
31 public PersonModel() {
32 this(new PersonId(), new ContainerType(), null, null, 0);
33 }
34
35 public PersonModel(PersonId id, ContainerType containerType, String firstName, String lastName, int age) {
36 this.id = Objects.requireNonNull(id, "id cannot be null");
37 this.containerType = Objects.requireNonNull(containerType, "containerType cannot be null");
38 this.firstName = Objects.requireNonNull(firstName, "firstName cannot be null");
39 this.lastName = Objects.requireNonNull(lastName, "lastName cannot be null");
40 this.age = age;
41 }
42
43 public PersonId getId() {
44 return id;
45 }
46
47 public ContainerType getContainerType() {
48 return containerType;
49 }
50
51 public String getFirstName() {
52 return firstName;
53 }
54
55 public String getLastName() {
56 return lastName;
57 }
58
59 public int getAge() {
60 return age;
61 }
62
63 @Override
64 public boolean equals(Object o) {
65 if (this == o) {
66 return true;
67 }
68 if (o == null || getClass() != o.getClass()) {
69 return false;
70 }
71
72 PersonModel that = (PersonModel) o;
73
74 if (age != that.age) {
75 return false;
76 }
77 if (!id.equals(that.id)) {
78 return false;
79 }
80 if (!containerType.equals(that.containerType)) {
81 return false;
82 }
83 //noinspection SimplifiableIfStatement
84 if (!firstName.equals(that.firstName)) {
85 return false;
86 }
87 return lastName.equals(that.lastName);
88 }
89
90 @Override
91 public int hashCode() {
92 int result = id.hashCode();
93 result = 31 * result + containerType.hashCode();
94 result = 31 * result + firstName.hashCode();
95 result = 31 * result + lastName.hashCode();
96 result = 31 * result + age;
97 return result;
98 }
99
100 @Override
101 public String toString() {
102 return "PersonModel{" + "id=" + id + ", containerType=" + containerType + ", firstName='" + firstName + '\''
103 + ", lastName='" + lastName + '\'' + ", age=" + age + '}';
104 }
105 }