View Javadoc

1   package com.atlassian.marketplace.client.api;
2   
3   import com.atlassian.fugue.Option;
4   
5   import static com.atlassian.fugue.Option.none;
6   import static com.atlassian.marketplace.client.api.QueryProperties.describeParams;
7   import static com.atlassian.marketplace.client.api.QueryProperties.describeValues;
8   import static com.google.common.base.Preconditions.checkNotNull;
9   
10  /**
11   * Encapsulates parameters that can be passed to {@link Applications#getVersion}.
12   * @since 2.0.0
13   */
14  public final class ApplicationVersionsQuery implements QueryProperties.Bounds
15  {
16      private static final ApplicationVersionsQuery DEFAULT_QUERY = builder().build();
17      
18      private final Option<Integer> afterBuildNumber;
19      private final QueryBounds bounds;
20  
21      /**
22       * Returns a new {@link Builder} for constructing an ApplicationVersionsQuery.
23       */
24      public static Builder builder()
25      {
26          return new Builder();
27      }
28  
29      /**
30       * Returns an ApplicationsQuery with no criteria, which will query the most recent application versions.
31       */
32      public static ApplicationVersionsQuery any()
33      {
34          return DEFAULT_QUERY;
35      }
36      
37      /**
38       * Returns a new {@link Builder} for constructing an ApplicationVersionsQuery based on an existing ApplicationVersionsQuery.
39       */
40      public static Builder builder(ApplicationVersionsQuery query)
41      {
42          Builder builder = builder()
43              .afterBuildNumber(query.getAfterBuildNumber())
44              .bounds(query.getBounds());
45  
46          return builder;
47      }
48      
49      private ApplicationVersionsQuery(Builder builder)
50      {
51          afterBuildNumber = builder.afterBuildNumber;
52          bounds = builder.bounds;
53      }
54  
55      /**
56       * The version build number, if any, that the client has specified in order to search for
57       * later versions.
58       * @see Builder#afterBuildNumber(Option)
59       */
60      public Option<Integer> getAfterBuildNumber()
61      {
62          return afterBuildNumber;
63      }
64  
65      @Override
66      public QueryBounds getBounds()
67      {
68          return bounds;
69      }
70  
71      @SuppressWarnings("unchecked")
72      @Override
73      public String toString()
74      {
75          return describeParams("ApplicationVersionsQuery",
76              describeValues("afterBuildNumber", afterBuildNumber),
77              bounds.describe()
78          );
79      }
80      
81      @Override
82      public boolean equals(Object other)
83      {
84          return (other instanceof ApplicationVersionsQuery) ? toString().equals(other.toString()) : false;
85      }
86      
87      @Override
88      public int hashCode()
89      {
90          return toString().hashCode();
91      }
92      
93      /**
94       * Builder class for {@link ApplicationVersionsQuery}.  Use {@link ApplicationVersionsQuery#builder()} to create an instance. 
95       */
96      public static class Builder implements QueryBuilderProperties.Bounds<Builder>
97      {
98          private Option<Integer> afterBuildNumber = none();
99          private QueryBounds bounds = QueryBounds.defaultBounds();
100 
101         /**
102          * Returns an immutable {@link ApplicationVersionsQuery} based on the current builder properties.
103          */
104         public ApplicationVersionsQuery build()
105         {
106             return new ApplicationVersionsQuery(this);
107         }
108 
109         /**
110          * Specifies an existing version if you want to query versions that are later than that
111          * version.
112          * @param afterBuildNumber  the build number of an existing application version
113          *   to restrict the query to versions later than this version, or {@link Option#none()} to
114          *   remove any such restriction 
115          * @return  the same query builder
116          * @see ApplicationVersionsQuery#getAfterVersionName()
117          */
118         public Builder afterBuildNumber(Option<Integer> afterBuildNumber)
119         {
120             this.afterBuildNumber = checkNotNull(afterBuildNumber);
121             return this;
122         }
123 
124         @Override
125         public Builder bounds(QueryBounds bounds)
126         {
127             this.bounds = checkNotNull(bounds);
128             return this;
129         }
130     }
131 }