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.internal.json;
18  
19  import com.google.common.base.Objects;
20  
21  import javax.annotation.Nullable;
22  
23  /**
24   * Represents schema of field in JIRA
25   *
26   * @since v1.0
27   */
28  public class FieldSchema {
29  
30  	private final String type;
31  	@Nullable
32  	private final String items;
33  	@Nullable
34  	private final String system;
35  	@Nullable
36  	private final String custom;
37  	@Nullable
38  	private final Long customId;
39  
40  	public FieldSchema(String type, String items, String system, String custom, Long customId) {
41  		this.type = type;
42  		this.items = items;
43  		this.system = system;
44  		this.custom = custom;
45  		this.customId = customId;
46  	}
47  
48  	public String getType() {
49  		return type;
50  	}
51  
52  	@Nullable
53  	public String getItems() {
54  		return items;
55  	}
56  
57  	@Nullable
58  	public String getSystem() {
59  		return system;
60  	}
61  
62  	@Nullable
63  	public String getCustom() {
64  		return custom;
65  	}
66  
67  	@Nullable
68  	public Long getCustomId() {
69  		return customId;
70  	}
71  
72  	public boolean isCustom() {
73  		return custom != null;
74  	}
75  
76  	/**
77  	 * Returns ToStringHelper with all fields inserted. Override this method to insert additional fields.
78  	 *
79  	 * @return ToStringHelper
80  	 */
81  	protected Objects.ToStringHelper getToStringHelper() {
82  		return Objects.toStringHelper(this).
83  				add("type", type).
84  				add("items", items).
85  				add("system", system).
86  				add("custom", custom).
87  				add("customId", customId);
88  	}
89  
90  	@Override
91  	public String toString() {
92  		return getToStringHelper().toString();
93  	}
94  
95  	@Override
96  	public boolean equals(Object obj) {
97  		if (obj instanceof FieldSchema) {
98  			FieldSchema that = (FieldSchema) obj;
99  			return Objects.equal(this.type, that.type)
100 					&& Objects.equal(this.items, that.items)
101 					&& Objects.equal(this.system, that.system)
102 					&& Objects.equal(this.custom, that.custom)
103 					&& Objects.equal(this.customId, that.customId);
104 		}
105 		return false;
106 	}
107 
108 	@Override
109 	public int hashCode() {
110 		return Objects.hashCode(type, items, system, custom, customId);
111 	}
112 }