View Javadoc

1   /*
2    * Copyright (C) 2010 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.google.common.base.Objects;
20  
21  import java.util.Collection;
22  
23  /**
24   * Information about selected transition including fields which can or must be set while performing the transition.
25   *
26   * @since v0.1
27   */
28  public class Transition {
29      private final String name;
30      private final int id;
31      private final Collection<Field> fields;
32  
33      public Transition(String name, int id, Collection<Field> fields) {
34          this.name = name;
35          this.id = id;
36          this.fields = fields;
37      }
38  
39      public String getName() {
40          return name;
41      }
42  
43      public int getId() {
44          return id;
45      }
46  
47      public Iterable<Field> getFields() {
48          return fields;
49      }
50  
51      @Override
52      public boolean equals(Object obj) {
53          if (obj instanceof Transition) {
54              Transition that = (Transition) obj;
55              return Objects.equal(this.name, that.name)
56                      && Objects.equal(this.id, that.id)
57                      && Objects.equal(this.fields, that.fields);
58          }
59          return false;
60      }
61  
62      @Override
63      public int hashCode() {
64          return Objects.hashCode(id, name, fields);
65      }
66  
67  
68      @Override
69      public String toString() {
70          return Objects.toStringHelper(this).
71                  add("id", id).
72                  add("name", name).
73                  add("fields", fields).
74                  toString();
75      }
76  
77  
78      public static class Field {
79          private final String id;
80          private final boolean isRequired;
81          private final String type;
82  
83          public Field(String id, boolean isRequired, String type) {
84              this.id = id;
85              this.isRequired = isRequired;
86              this.type = type;
87          }
88  
89          public String getId() {
90              return id;
91          }
92  
93          public boolean isRequired() {
94              return isRequired;
95          }
96  
97          public String getType() {
98              return type;
99          }
100 
101         @Override
102         public int hashCode() {
103             return Objects.hashCode(id, isRequired, type);
104         }
105 
106         @Override
107         public boolean equals(Object obj) {
108             if (obj instanceof Field) {
109                 Field that = (Field) obj;
110                 return Objects.equal(this.id, that.id)
111                         && Objects.equal(this.isRequired, that.isRequired)
112                         && Objects.equal(this.type, that.type);
113             }
114             return false;
115         }
116 
117         @Override
118         public String toString() {
119             return Objects.toStringHelper(this).
120                     add("id", id).
121                     add("isRequired", isRequired).
122                     add("type", type).
123                     toString();
124         }
125 
126     }
127 }