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   * Range of data.
39   *
40   * @author Yegor Bugayenko (yegor@tpc2.com)
41   * @version $Id: e33296d0a8b50c3bb0dba986ae870588a3b7ff09 $
42   * @since 0.0.1
43   */
44  @Immutable
45  public interface Range {
46  
47      /**
48       * All inclusive range.
49       */
50      Range ENTIRE = new Range() {
51          @Override
52          public String toString() {
53              return "ENTIRE";
54          }
55          @Override
56          public long first() {
57              return 0;
58          }
59          @Override
60          public long last() {
61              return Long.MAX_VALUE;
62          }
63      };
64  
65      /**
66       * First byte to fetch, inclusively.
67       * @return Number of byte
68       */
69      long first();
70  
71      /**
72       * Last byte to fetch, inclusively.
73       * @return Number of byte
74       */
75      long last();
76  
77      /**
78       * Simple implementation.
79       */
80      @Loggable(Loggable.DEBUG)
81      @ToString
82      @EqualsAndHashCode(of = { "frst", "lst" })
83      final class Simple implements Range {
84          /**
85           * First byte.
86           */
87          private final transient long frst;
88          /**
89           * Last byte.
90           */
91          private final transient long lst;
92          /**
93           * Public ctor.
94           * @param first First byte
95           * @param last Last byte
96           */
97          public Simple(final long first, final long last) {
98              this.frst = first;
99              this.lst = last;
100         }
101         @Override
102         public long first() {
103             return this.frst;
104         }
105         @Override
106         public long last() {
107             return this.lst;
108         }
109     }
110 
111 }