View Javadoc

1   package com.atlassian.marketplace.client.api;
2   
3   import com.atlassian.fugue.Either;
4   import com.atlassian.fugue.Option;
5   
6   import static com.atlassian.fugue.Option.some;
7   
8   /**
9    * Encapsulates parameters that can be passed to {@link Addons#getVersion}.
10   * @since 2.0.0
11   */
12  public final class AddonVersionSpecifier
13  {
14      private final Option<Either<String, Integer>> nameOrBuild;
15      
16      private AddonVersionSpecifier(Option<Either<String, Integer>> nameOrBuild)
17      {
18          this.nameOrBuild = nameOrBuild;
19      }
20      
21      /**
22       * Searches for an add-on version by build number.
23       */
24      public static AddonVersionSpecifier buildNumber(int buildNumber)
25      {
26          return new AddonVersionSpecifier(some(Either.<String, Integer>right(buildNumber)));
27      }
28      
29      /**
30       * Searches for an add-on version by name (version string, e.g. "1.0.0").
31       */
32      public static AddonVersionSpecifier versionName(String name)
33      {
34          return new AddonVersionSpecifier(some(Either.<String, Integer>left(name))); 
35      }
36      
37      /**
38       * Searches for the latest version (which may be constrained by criteria such as compatibility
39       * if specified with {@link AddonVersionsQuery}).
40       */
41      public static AddonVersionSpecifier latest()
42      {
43          return new AddonVersionSpecifier(Option.<Either<String, Integer>>none());
44      }
45      
46      /**
47       * Used internally to access the previously set details of the specifier.  
48       */
49      public Option<Either<String, Integer>> getSpecifiedVersion()
50      {
51          return nameOrBuild;
52      }
53      
54      @Override
55      public String toString()
56      {
57          for (Either<String, Integer> vob: nameOrBuild)
58          {
59              for (Integer b: vob.right())
60              {
61                  return "buildNumber(" + b + ")";
62              }
63              for (String n: vob.left())
64              {
65                  return "name(" + n + ")";
66              }
67          }
68          return "latest";
69      }
70      
71      @Override
72      public boolean equals(Object other)
73      {
74          return (other instanceof AddonVersionSpecifier) && ((AddonVersionSpecifier) other).nameOrBuild.equals(this.nameOrBuild);
75      }
76      
77      @Override
78      public int hashCode()
79      {
80          return nameOrBuild.hashCode();
81      }
82  }