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.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)) {
68        return false;
69      }
70  
71      Author author = (Author) o;
72  
73      if ((id != author.id) || (bio != null ? !bio.equals(author.bio) : author.bio != null)
74          || (email != null ? !email.equals(author.email) : author.email != null)
75          || (password != null ? !password.equals(author.password) : author.password != null)) {
76        return false;
77      }
78      if (username != null ? !username.equals(author.username) : author.username != null) {
79        return false;
80      }
81      if (favouriteSection != null ? !favouriteSection.equals(author.favouriteSection)
82          : author.favouriteSection != null) {
83        return false;
84      }
85  
86      return true;
87    }
88  
89    @Override
90    public int hashCode() {
91      int result;
92      result = id;
93      result = 31 * result + (username != null ? username.hashCode() : 0);
94      result = 31 * result + (password != null ? password.hashCode() : 0);
95      result = 31 * result + (email != null ? email.hashCode() : 0);
96      result = 31 * result + (bio != null ? bio.hashCode() : 0);
97      return 31 * result + (favouriteSection != null ? favouriteSection.hashCode() : 0);
98    }
99  
100   @Override
101   public String toString() {
102     return id + " " + username + " " + password + " " + email;
103   }
104 }