View Javadoc

1   /**
2    * Copyright (C) 2008 Atlassian
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    *    http://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  
17  package com.atlassian.theplugin.commons.crucible.api.model;
18  
19  public class UserBean implements User {
20      protected String userName;
21  	protected String displayName;
22      private static final int HASH_MAGIC = 31;
23  
24      public UserBean() {
25      }
26  
27      public UserBean(String userName) {
28          this.userName = userName;
29      }
30  
31      public UserBean(String userName, String displayName) {
32          this.userName = userName;
33          this.displayName = displayName;
34      }
35  
36      public String getUserName() {
37          return userName;
38      }
39  
40      public void setUserName(String userName) {
41          this.userName = userName;
42      }
43  
44      public String getDisplayName() {
45  		if (displayName == null) {
46  			return userName;
47  		}
48  		return displayName;
49      }
50  
51      public void setDisplayName(String displayName) {
52          this.displayName = displayName;
53      }
54  
55      @Override
56  	public boolean equals(Object o) {
57          if (this == o) {
58              return true;
59          }
60          if (o == null || getClass() != o.getClass()) {
61              return false;
62          }
63  
64          UserBean userBean = (UserBean) o;
65  
66          if (displayName != null ? !displayName.equals(userBean.displayName) : userBean.displayName != null) {
67              return false;
68          }
69  
70          if (userName != null ? !userName.equals(userBean.userName) : userBean.userName != null) {
71              return false;
72          }
73  
74          return true;
75      }
76  
77      @Override
78  	public int hashCode() {
79          int result;
80          result = (userName != null ? userName.hashCode() : 0);
81          result = HASH_MAGIC * result + (displayName != null ? displayName.hashCode() : 0);
82          return result;
83      }
84  
85      public int compareTo(User that) {
86          return this.userName.compareTo(that.getUserName());
87      }
88  }