View Javadoc

1   /*
2    * Copyright (C) 2010 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.jira.rest.client.api.domain;
18  
19  import com.atlassian.jira.rest.client.api.AddressableEntity;
20  import com.atlassian.jira.rest.client.api.NamedEntity;
21  import com.google.common.base.Objects;
22  
23  import java.net.URI;
24  
25  /**
26   * Any resource which is addressable (has "self" URI) and has a name.
27   *
28   * @since v0.1
29   */
30  public class AddressableNamedEntity implements AddressableEntity, NamedEntity {
31  	protected final URI self;
32  	protected final String name;
33  
34  	public AddressableNamedEntity(URI self, String name) {
35  		this.name = name;
36  		this.self = self;
37  	}
38  
39  	@Override
40  	public URI getSelf() {
41  		return self;
42  	}
43  
44  	public String getName() {
45  		return name;
46  	}
47  
48  	@Override
49  	public String toString() {
50  		return getToStringHelper().toString();
51  	}
52  
53  	protected Objects.ToStringHelper getToStringHelper() {
54  		return Objects.toStringHelper(this).
55  				add("self", self).
56  				add("name", name);
57  	}
58  
59  	@Override
60  	public boolean equals(Object obj) {
61  		if (obj instanceof AddressableNamedEntity) {
62  			AddressableNamedEntity that = (AddressableNamedEntity) obj;
63  			return Objects.equal(this.self, that.self)
64  					&& Objects.equal(this.name, that.name);
65  		}
66  		return false;
67  	}
68  
69  	@Override
70  	public int hashCode() {
71  		return Objects.hashCode(self, name);
72  	}
73  }