View Javadoc

1   /*
2    * Copyright (C) 2014 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.IssueRestClient;
20  import com.google.common.base.Objects;
21  import com.google.common.base.Optional;
22  import com.google.common.collect.Iterables;
23  
24  /**
25   * Represents operations returned for expand {@link IssueRestClient.Expandos#OPERATIONS}
26   *
27   * @since 2.0
28   */
29  public class Operations {
30      private final Iterable<OperationGroup> linkGroups;
31  
32      public Operations(final Iterable<OperationGroup> linkGroups) {
33          this.linkGroups = linkGroups;
34      }
35  
36      public Iterable<OperationGroup> getLinkGroups() {
37          return linkGroups;
38      }
39  
40      public <T> Optional<T> accept(OperationVisitor<T> visitor) {
41          return OperationGroup.accept(getLinkGroups(), visitor);
42      }
43  
44      public Operation getOperationById(final String operationId) {
45          return accept(new OperationVisitor<Operation>() {
46              @Override
47              public Optional<Operation> visit(Operation operation) {
48                  return operationId.equals(operation.getId()) ? Optional.of(operation) : Optional.<Operation>absent();
49              }
50          }).orNull();
51      }
52  
53      @Override
54      public int hashCode() {
55          return Objects.hashCode(linkGroups);
56      }
57  
58      @Override
59      public boolean equals(Object obj) {
60          if (this == obj) {
61              return true;
62          }
63          if (obj == null || getClass() != obj.getClass()) {
64              return false;
65          }
66          final Operations other = (Operations) obj;
67          return Iterables.elementsEqual(this.linkGroups, other.linkGroups);
68      }
69  
70      @Override
71      public String toString() {
72          return Objects.toStringHelper(this)
73                  .add("linkGroups", linkGroups)
74                  .toString();
75      }
76  }