View Javadoc
1   /**
2    * Copyright (c) 2012-2017, s3auth.com
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met: 1) Redistributions of source code must retain the above
8    * copyright notice, this list of conditions and the following
9    * disclaimer. 2) Redistributions in binary form must reproduce the above
10   * copyright notice, this list of conditions and the following
11   * disclaimer in the documentation and/or other materials provided
12   * with the distribution. 3) Neither the name of the s3auth.com nor
13   * the names of its contributors may be used to endorse or promote
14   * products derived from this software without specific prior written
15   * permission.
16   *
17   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
19   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21   * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28   * OF THE POSSIBILITY OF SUCH DAMAGE.
29   */
30  package com.s3auth.hosts;
31  
32  import com.jcabi.aspects.Immutable;
33  import com.jcabi.aspects.Loggable;
34  import lombok.EqualsAndHashCode;
35  import lombok.ToString;
36  
37  /**
38   * S3 Object version.
39   *
40   * @author Carlos Miranda (miranda.cma@gmail.com)
41   * @version $Id: dcaf61d94c1c870e7fb24594dd1b3b1586f1c65a $
42   */
43  @Immutable
44  @SuppressWarnings("PMD.TooManyMethods")
45  public interface Version {
46  
47      /**
48       * Specify that the latest version be fetched.
49       */
50      Version LATEST = new Version() {
51          @Override
52          public boolean latest() {
53              return true;
54          }
55          @Override
56          public boolean list() {
57              return false;
58          }
59          @Override
60          public String version() {
61              // @checkstyle MultipleStringLiterals (1 line)
62              throw new UnsupportedOperationException("Version is unspecified.");
63          }
64      };
65  
66      /**
67       * Specify that the object's versions be listed.
68       */
69      Version LIST = new Version() {
70          @Override
71          public boolean latest() {
72              return false;
73          }
74          @Override
75          public boolean list() {
76              return true;
77          }
78          @Override
79          public String version() {
80              throw new UnsupportedOperationException("Version is unspecified.");
81          }
82      };
83  
84      /**
85       * Flag specifying whether the latest version is to be fetched.
86       * @return Boolean value true, if we're fetching the latest version
87       */
88      boolean latest();
89  
90      /**
91       * Flag specifying whether versions should be listed instead of obtaining
92       * a particular version.
93       * @return Boolean value true, if we're fetching the list of versions
94       */
95      boolean list();
96  
97      /**
98       * Version ID of the S3 object.
99       * @return Version ID
100      */
101     String version();
102 
103     /**
104      * Simple implementation.
105      */
106     @Immutable
107     @Loggable(Loggable.DEBUG)
108     @ToString
109     @EqualsAndHashCode(of = "ver")
110     final class Simple implements Version {
111         /**
112          * The version ID.
113          */
114         private final String ver;
115         /**
116          * Public ctor.
117          * @param version Version ID string
118          */
119         public Simple(final String version) {
120             this.ver = version;
121         }
122         @Override
123         public boolean latest() {
124             return false;
125         }
126         @Override
127         public boolean list() {
128             return false;
129         }
130         @Override
131         public String version() {
132             return this.ver;
133         }
134     }
135 
136 }