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.api;
18  
19  import com.google.common.base.Objects;
20  
21  import javax.annotation.Nullable;
22  import java.util.Collection;
23  
24  /**
25   * Represents a resource which can be expandable - that is REST API is capable of sending just the number
26   * of child resources or when the entity is expanded, also the child resources themselves
27   *
28   * @since v0.1
29   */
30  public class ExpandableProperty<T> {
31      private final int size;
32  
33      public ExpandableProperty(int size) {
34          this.size = size;
35          items = null;
36      }
37  
38      public ExpandableProperty(int size, @Nullable Collection<T> items) {
39          this.size = size;
40          this.items = items;
41      }
42  
43      public ExpandableProperty(Collection<T> items) {
44          this.size = items.size();
45          this.items = items;
46      }
47  
48      public int getSize() {
49          return size;
50      }
51  
52      @Nullable
53      final private Collection<T> items;
54  
55      @Nullable
56      public Iterable<T> getItems() {
57          return items;
58      }
59  
60      @Override
61      public String toString() {
62          return Objects.toStringHelper(this).
63                  add("size", size).
64                  add("items", items).
65                  toString();
66      }
67  
68  
69      @Override
70      public boolean equals(Object obj) {
71          if (obj instanceof ExpandableProperty) {
72              ExpandableProperty that = (ExpandableProperty) obj;
73              return Objects.equal(this.size, that.size)
74                      && Objects.equal(this.items, that.items);
75          }
76          return false;
77      }
78  
79      @Override
80      public int hashCode() {
81          return Objects.hashCode(size, items);
82      }
83  }