View Javadoc
1   /*
2    *    Copyright 2009-2023 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)) {
38        return false;
39      }
40  
41      Person person = (Person) o;
42  
43      if (id != null ? !id.equals(person.id) : person.id != null) {
44        return false;
45      }
46  
47      return true;
48    }
49  
50    @Override
51    public int hashCode() {
52      return id != null ? id.hashCode() : 0;
53    }
54  
55    @Override
56    public String toString() {
57      return id + ": " + firstName + " " + lastName + " (" + parent + ")";
58    }
59  
60    public String getFirstName() {
61      return firstName;
62    }
63  
64    public void setFirstName(String firstName) {
65      this.firstName = firstName;
66    }
67  
68    public String getLastName() {
69      return lastName;
70    }
71  
72    public void setLastName(String lastName) {
73      this.lastName = lastName;
74    }
75  
76    public Long getId() {
77      return id;
78    }
79  
80    public void setId(Long id) {
81      this.id = id;
82    }
83  
84    public Person getParent() {
85      return parent;
86    }
87  
88    public void setParent(Person parent) {
89      this.parent = parent;
90    }
91  }