1 package com.atlassian.plugins.rest.common.expand.parameter;
2
3 import java.util.SortedSet;
4
5 /**
6 * <p>Represents indexes as used in expand parameters. The size of the whole collection is required on most of this
7 * class methods as it can handle indexes specified as: <ul> <li>[i]</li> <li>[-i]</li> <li>[i:j]</li> </ul> where
8 * {@code i} and {@code j} are positive integers.</p>
9 */
10 public interface Indexes
11 {
12 /**
13 * Tells whether {@code this} represents a contiguous range. If not a range it is a single index, and {@link
14 * #getMinIndex(int)} and {@link #getMaxIndex(int)} will return the same value.
15 *
16 * @return {@code true} if this is a range.
17 */
18 boolean isRange();
19
20 /**
21 * Gets the minimum index in the range, given the total size of the collection to consider.
22 *
23 * @param size the size of the collection to consider.
24 * @return the min index, -1 if the min index is out of bounds.
25 */
26 int getMinIndex(int size);
27
28 /**
29 * Gets the maximum index in the range, given the total size of the collection to consider.
30 *
31 * @param size the size of the collection to consider.
32 * @return the max index, -1 if the max index is out of bounds.
33 */
34 int getMaxIndex(int size);
35
36 /**
37 * Checks whether a given index is contained within this collection of indexes
38 *
39 * @param index the index to look for.
40 * @param size the size of the overall collection to consider.
41 * @return {@code true} if it does contain the given index, {@code false} otherwise.
42 */
43 boolean contains(int index, int size);
44
45 /**
46 * Gets a sorted set of all indexes, negative indexes having been translated into their positive counter part.
47 *
48 * @param size the size of the overall collection to consider.
49 * @return a set of positive indexes.
50 */
51 SortedSet<Integer> getIndexes(int size);
52 }