View Javadoc

1   /*
2    * Copyright (C) 2012 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.domain;
18  
19  import com.google.common.base.Objects;
20  
21  import javax.annotation.Nullable;
22  import java.net.URI;
23  
24  /**
25   * Represents Custom Field Option
26   *
27   * @since v1.0
28   */
29  public class CustomFieldOption {
30  
31  	private final URI self;
32  	private final Long id;
33  	private final String value;
34  	private final Iterable<CustomFieldOption> children;
35  	@Nullable
36  	private final CustomFieldOption child;
37  
38  	public CustomFieldOption(Long id, URI self, String value, Iterable<CustomFieldOption> children, @Nullable CustomFieldOption child) {
39  		this.value = value;
40  		this.id = id;
41  		this.self = self;
42  		this.children = children;
43  		this.child = child;
44  	}
45  
46  	public URI getSelf() {
47  		return self;
48  	}
49  
50  	public Long getId() {
51  		return id;
52  	}
53  
54  	public String getValue() {
55  		return value;
56  	}
57  
58  	public Iterable<CustomFieldOption> getChildren() {
59  		return children;
60  	}
61  
62  	@Nullable
63  	public CustomFieldOption getChild() {
64  		return child;
65  	}
66  
67  	/**
68  	 * Returns ToStringHelper with all fields inserted. Override this method to insert additional fields.
69  	 * @return ToStringHelper
70  	 */
71  	protected Objects.ToStringHelper getToStringHelper() {
72  		return Objects.toStringHelper(this)
73  				.add("self", self)
74  				.add("id", id)
75  				.add("value", value)
76  				.add("children", children)
77  				.add("child", child);
78  	}
79  
80  	@Override
81  	public String toString() {
82  		return getToStringHelper().toString();
83  	}
84  
85  	@Override
86  	public int hashCode() {
87  		return Objects.hashCode(self, id, value, children, child);
88  	}
89  
90  	@Override
91  	public boolean equals(Object obj) {
92  		if (obj == null) {
93  			return false;
94  		}
95  		if (getClass() != obj.getClass()) {
96  			return false;
97  		}
98  		final CustomFieldOption other = (CustomFieldOption) obj;
99  		return Objects.equal(this.self, other.self)
100 				&& Objects.equal(this.id, other.id)
101 				&& Objects.equal(this.value, other.value)
102 				&& Objects.equal(this.children, other.children)
103 				&& Objects.equal(this.child, other.child);
104 	}
105 }