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.
29   * <p>
30   * The CIM prefix stands for CreateIssueMetadata as this class is used in output of {@link IssueRestClient#getCreateIssueMetadata(GetCreateIssueMetadataOptions)}
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      @Nullable
48      public CimFieldInfo getField(IssueFieldId fieldId) {
49          return fields.get(fieldId.id);
50      }
51  
52      /**
53       * Returns ToStringHelper with all fields inserted. Override this method to insert additional fields.
54       *
55       * @return ToStringHelper
56       */
57      @Override
58      protected Objects.ToStringHelper getToStringHelper() {
59          return super.getToStringHelper().add("fields", fields);
60      }
61  
62      @Override
63      public boolean equals(Object obj) {
64          if (obj instanceof CimIssueType) {
65              CimIssueType that = (CimIssueType) obj;
66              return super.equals(obj)
67                      && Objects.equal(this.fields, that.fields);
68          }
69          return false;
70      }
71  
72      @Override
73      public int hashCode() {
74          return Objects.hashCode(super.hashCode(), fields);
75      }
76  }