View Javadoc
1   /*
2    *    Copyright 2009-2024 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package org.apache.ibatis.submitted.cglib_lazy_error;
17  
18  public class Person {
19  
20    private Long id;
21    private String firstName;
22    private String lastName;
23    private Person parent;
24  
25    public Person getAncestor() {
26      if (getParent() == null) {
27        return this;
28      }
29      return getParent().getAncestor();
30    }
31  
32    @Override
33    public boolean equals(Object o) {
34      if (this == o) {
35        return true;
36      }
37      if (!(o instanceof Person person)) {
38        return false;
39      }
40  
41      return id != null ? id.equals(person.id) : person.id == null;
42    }
43  
44    @Override
45    public int hashCode() {
46      return id != null ? id.hashCode() : 0;
47    }
48  
49    @Override
50    public String toString() {
51      return id + ": " + firstName + " " + lastName + " (" + parent + ")";
52    }
53  
54    public String getFirstName() {
55      return firstName;
56    }
57  
58    public void setFirstName(String firstName) {
59      this.firstName = firstName;
60    }
61  
62    public String getLastName() {
63      return lastName;
64    }
65  
66    public void setLastName(String lastName) {
67      this.lastName = lastName;
68    }
69  
70    public Long getId() {
71      return id;
72    }
73  
74    public void setId(Long id) {
75      this.id = id;
76    }
77  
78    public Person getParent() {
79      return parent;
80    }
81  
82    public void setParent(Person parent) {
83      this.parent = parent;
84    }
85  }