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 Applications#getVersion}.
10   */
11  public final class ApplicationVersionSpecifier
12  {
13      private final Option<Either<String, Integer>> nameOrBuild;
14      
15      private ApplicationVersionSpecifier(Option<Either<String, Integer>> nameOrBuild)
16      {
17          this.nameOrBuild = nameOrBuild;
18      }
19      
20      /**
21       * Searches for an application version by build number.
22       */
23      public static ApplicationVersionSpecifier buildNumber(int buildNumber)
24      {
25          return new ApplicationVersionSpecifier(some(Either.<String, Integer>right(buildNumber)));
26      }
27      
28      /**
29       * Searches for an application version by name (version string, e.g. "1.0.0").
30       */
31      public static ApplicationVersionSpecifier versionName(String name)
32      {
33          return new ApplicationVersionSpecifier(some(Either.<String, Integer>left(name))); 
34      }
35      
36      /**
37       * Searches for the latest version.
38       */
39      public static ApplicationVersionSpecifier latest()
40      {
41          return new ApplicationVersionSpecifier(Option.<Either<String, Integer>>none());
42      }
43      
44      /**
45       * Used internally to access the previously set details of the specifier.  
46       */
47      public Option<Either<String, Integer>> getSpecifiedVersion()
48      {
49          return nameOrBuild;
50      }
51      
52      @Override
53      public String toString()
54      {
55          for (Either<String, Integer> vob: nameOrBuild)
56          {
57              for (Integer b: vob.right())
58              {
59                  return "buildNumber(" + b + ")";
60              }
61              for (String n: vob.left())
62              {
63                  return "name(" + n + ")";
64              }
65          }
66          return "latest";
67      }
68      
69      @Override
70      public boolean equals(Object other)
71      {
72          return (other instanceof ApplicationVersionSpecifier) && ((ApplicationVersionSpecifier) other).nameOrBuild.equals(this.nameOrBuild);
73      }
74      
75      @Override
76      public int hashCode()
77      {
78          return nameOrBuild.hashCode();
79      }
80  }