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.atlassian.jira.rest.client.api.GetCreateIssueMetadataOptions;
20  import com.atlassian.jira.rest.client.api.IssueRestClient;
21  import com.google.common.base.Objects;
22  
23  import javax.annotation.Nullable;
24  import java.net.URI;
25  import java.util.Map;
26  
27  /**
28   * Describes issue type with fields info map.<br/>
29   * The CIM prefix stands for CreateIssueMetadata as this class is used in output of {@link IssueRestClient#getCreateIssueMetadata(GetCreateIssueMetadataOptions)}
30   *
31   * @since v1.0
32   */
33  public class CimIssueType extends IssueType {
34  
35  	private final Map<String, CimFieldInfo> fields;
36  
37  	public CimIssueType(URI self, @Nullable Long id, String name, boolean isSubtask, String description, URI iconUri, Map<String, CimFieldInfo> fields) {
38  		super(self, id, name, isSubtask, description, iconUri);
39  		this.fields = fields;
40  	}
41  
42  	public Map<String, CimFieldInfo> getFields() {
43  		return fields;
44  	}
45  
46  	@Nullable
47  	public CimFieldInfo getField(IssueFieldId fieldId) {
48  		return fields.get(fieldId.id);
49  	}
50  
51  	/**
52  	 * Returns ToStringHelper with all fields inserted. Override this method to insert additional fields.
53  	 *
54  	 * @return ToStringHelper
55  	 */
56  	@Override
57  	protected Objects.ToStringHelper getToStringHelper() {
58  		return super.getToStringHelper().add("fields", fields);
59  	}
60  
61  	@Override
62  	public boolean equals(Object obj) {
63  		if (obj instanceof CimIssueType) {
64  			CimIssueType that = (CimIssueType) obj;
65  			return super.equals(obj)
66  					&& Objects.equal(this.fields, that.fields);
67  		}
68  		return false;
69  	}
70  
71  	@Override
72  	public int hashCode() {
73  		return Objects.hashCode(super.hashCode(), fields);
74  	}
75  }