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