Simplify equals() methods
[aaa.git] / aaa-authn-api / src / main / java / org / opendaylight / aaa / api / model / User.java
1 /*
2  * Copyright (c) 2014, 2017 Hewlett-Packard Development Company, L.P. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.aaa.api.model;
9
10 import java.util.Objects;
11 import javax.xml.bind.annotation.XmlRootElement;
12
13 @XmlRootElement(name = "user")
14 public class User {
15     private static final int USER_ACCOUNT_ENABLED = 1;
16     private static final int USER_ACCOUNT_DISABLED = 0;
17     private static final int USER_ACCOUNT_DEFAULT_ENABLED = USER_ACCOUNT_ENABLED;
18
19     private String userid;
20     private String name;
21     private String description;
22     private int enabled = USER_ACCOUNT_DEFAULT_ENABLED;
23     private String email;
24     private String password;
25     private String salt;
26     private String domainid;
27
28     public String getUserid() {
29         return userid;
30     }
31
32     public void setUserid(final String id) {
33         userid = id;
34     }
35
36     public String getName() {
37         return name;
38     }
39
40     public void setName(final String name) {
41         this.name = name;
42     }
43
44     public String getDescription() {
45         return description;
46     }
47
48     public void setDescription(final String description) {
49         this.description = description;
50     }
51
52     public Boolean isEnabled() {
53         return enabled == USER_ACCOUNT_ENABLED;
54     }
55
56     public void setEnabled(final boolean enabled) {
57         if (enabled) {
58             setEnabled(USER_ACCOUNT_ENABLED);
59         } else {
60             setEnabled(USER_ACCOUNT_DISABLED);
61         }
62     }
63
64     public void setEnabled(final int enabled) {
65         this.enabled = enabled;
66     }
67
68     public void setEmail(final String email) {
69         this.email = email;
70     }
71
72     public String getEmail() {
73         return email;
74     }
75
76     public void setPassword(final String password) {
77         this.password = password;
78     }
79
80     public String getPassword() {
81         return password;
82     }
83
84     public void setSalt(final String salt) {
85         this.salt = salt;
86     }
87
88     public String getSalt() {
89         return salt;
90     }
91
92     public String getDomainid() {
93         return domainid;
94     }
95
96     public void setDomainid(final String domainid) {
97         this.domainid = domainid;
98     }
99
100     @Override
101     public int hashCode() {
102         return name != null ? name.hashCode() : 0;
103     }
104
105     @Override
106     public boolean equals(final Object obj) {
107         if (this == obj) {
108             return true;
109         }
110         if (obj == null || getClass() != obj.getClass()) {
111             return false;
112         }
113         final User other = (User) obj;
114         return Objects.equals(getName(), other.getName()) && Objects.equals(getEmail(), other.getEmail())
115             && isEnabled().equals(other.isEnabled()) && Objects.equals(getPassword(), other.getPassword())
116             && Objects.equals(getSalt(), other.getSalt()) && Objects.equals(getUserid(), other.getUserid())
117             && Objects.equals(getDescription(), other.getDescription());
118     }
119
120     @Override
121     public String toString() {
122         return name;
123     }
124 }