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.api.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  	 *
70  	 * @return ToStringHelper
71  	 */
72  	protected Objects.ToStringHelper getToStringHelper() {
73  		return Objects.toStringHelper(this)
74  				.add("self", self)
75  				.add("id", id)
76  				.add("value", value)
77  				.add("children", children)
78  				.add("child", child);
79  	}
80  
81  	@Override
82  	public String toString() {
83  		return getToStringHelper().toString();
84  	}
85  
86  	@Override
87  	public int hashCode() {
88  		return Objects.hashCode(self, id, value, children, child);
89  	}
90  
91  	@Override
92  	public boolean equals(Object obj) {
93  		if (obj == null) {
94  			return false;
95  		}
96  		if (getClass() != obj.getClass()) {
97  			return false;
98  		}
99  		final CustomFieldOption other = (CustomFieldOption) obj;
100 		return Objects.equal(this.self, other.self)
101 				&& Objects.equal(this.id, other.id)
102 				&& Objects.equal(this.value, other.value)
103 				&& Objects.equal(this.children, other.children)
104 				&& Objects.equal(this.child, other.child);
105 	}
106 }