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  package com.atlassian.jira.rest.client.api.domain;
17  
18  import com.atlassian.jira.rest.client.api.IdentifiableEntity;
19  import com.atlassian.jira.rest.client.api.NamedEntity;
20  import com.google.common.base.Objects;
21  
22  import javax.annotation.Nullable;
23  
24  /**
25   * Representation of JIRA field, either system or custom.
26   */
27  public class Field implements NamedEntity, IdentifiableEntity<String> {
28  
29      private final String id;
30      private final String name;
31      private final FieldType fieldType;
32      private final boolean orderable;
33      private final boolean navigable;
34      private final boolean searchable;
35      @Nullable
36      private final FieldSchema schema;
37  
38      public Field(String id, String name, FieldType fieldType, boolean orderable, boolean navigable, boolean searchable,
39                   @Nullable FieldSchema schema) {
40          this.id = id;
41          this.name = name;
42          this.fieldType = fieldType;
43          this.orderable = orderable;
44          this.navigable = navigable;
45          this.searchable = searchable;
46          this.schema = schema;
47      }
48  
49      public String getId() {
50          return id;
51      }
52  
53      public String getName() {
54          return name;
55      }
56  
57      @SuppressWarnings("unused")
58      public FieldType getFieldType() {
59          return fieldType;
60      }
61  
62      @SuppressWarnings("unused")
63      public boolean isOrderable() {
64          return orderable;
65      }
66  
67      @SuppressWarnings("unused")
68      public boolean isNavigable() {
69          return navigable;
70      }
71  
72      @SuppressWarnings("unused")
73      public boolean isSearchable() {
74          return searchable;
75      }
76  
77      @Nullable
78      @SuppressWarnings("unused")
79      public FieldSchema getSchema() {
80          return schema;
81      }
82  
83      @Override
84      public int hashCode() {
85          return Objects.hashCode(id, name, fieldType, orderable, navigable, searchable, schema);
86      }
87  
88      @Override
89      public boolean equals(Object obj) {
90          if (obj instanceof Field) {
91              final Field that = (Field) obj;
92              return Objects.equal(this.id, that.id)
93                      && Objects.equal(this.name, that.name)
94                      && Objects.equal(this.fieldType, that.fieldType)
95                      && Objects.equal(this.orderable, that.orderable)
96                      && Objects.equal(this.navigable, that.navigable)
97                      && Objects.equal(this.searchable, that.searchable)
98                      && Objects.equal(this.schema, that.schema);
99          }
100         return false;
101     }
102 
103     protected Objects.ToStringHelper getToStringHelper() {
104         return Objects.toStringHelper(this)
105                 .add("id", id)
106                 .add("name", name)
107                 .add("fieldType", fieldType)
108                 .add("orderable", orderable)
109                 .add("navigable", navigable)
110                 .add("searchable", searchable)
111                 .add("schema", schema);
112     }
113 
114     @Override
115     public String toString() {
116         return getToStringHelper().toString();
117     }
118 }