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.domain.blog;
17  
18  import java.io.Serializable;
19  
20  public class ImmutableAuthor implements Serializable {
21    private static final long serialVersionUID = 1L;
22    protected final int id;
23    protected final String username;
24    protected final String password;
25    protected final String email;
26    protected final String bio;
27    protected final Section favouriteSection;
28  
29    public ImmutableAuthor(int id, String username, String password, String email, String bio, Section section) {
30      this.id = id;
31      this.username = username;
32      this.password = password;
33      this.email = email;
34      this.bio = bio;
35      this.favouriteSection = section;
36    }
37  
38    public int getId() {
39      return id;
40    }
41  
42    public String getUsername() {
43      return username;
44    }
45  
46    public String getPassword() {
47      return password;
48    }
49  
50    public String getEmail() {
51      return email;
52    }
53  
54    public String getBio() {
55      return bio;
56    }
57  
58    public Section getFavouriteSection() {
59      return favouriteSection;
60    }
61  
62    @Override
63    public boolean equals(Object o) {
64      if (this == o) {
65        return true;
66      }
67      if (!(o instanceof Author author)) {
68        return false;
69      }
70  
71      if (id != author.id || (bio != null ? !bio.equals(author.bio) : author.bio != null)
72          || (email != null ? !email.equals(author.email) : author.email != null)
73          || (password != null ? !password.equals(author.password) : author.password != null)) {
74        return false;
75      }
76      return username != null ? username.equals(author.username) : author.username == null && favouriteSection != null
77          ? favouriteSection.equals(author.favouriteSection) : author.favouriteSection == null;
78    }
79  
80    @Override
81    public int hashCode() {
82      int result = id;
83      result = 31 * result + (username != null ? username.hashCode() : 0);
84      result = 31 * result + (password != null ? password.hashCode() : 0);
85      result = 31 * result + (email != null ? email.hashCode() : 0);
86      result = 31 * result + (bio != null ? bio.hashCode() : 0);
87      return 31 * result + (favouriteSection != null ? favouriteSection.hashCode() : 0);
88    }
89  
90    @Override
91    public String toString() {
92      return id + " " + username + " " + password + " " + email;
93    }
94  }