public final class Pythonesque
extends java.lang.Object
1
will refer to the last element,
2
to the one before it and so on.
Note taht UNMAPPABLE
(same value as Integer.MIN_VALUE
is handled special.
All methods here will throw an IndexOutOfBoundsException
if the index to map
has has is UNMAPPABLE
. This allows to use this value as a special invalid index indicator even
when Pythonesque indexing is used.
Modifier and Type  Field and Description 

static java.lang.String 
ERROR_INDEX_OUT_OF_BOUNDS_FORMAT
Format used for index out of bounds exception.

static int 
UNMAPPABLE
Unmappable index, same as
Integer.MAX_VALUE . 
Modifier and Type  Method and Description 

static int 
map(int index,
int size)
Map a possibly negative index from an indexable of a given size to
the standard Java index.

static int 
map(int index,
Sizeable indexable)
Map a possibly negative index from an indexable of a given size to
the standard Java index.

static int 
mapLB(int index,
int size)
Map a possibly negative index from an indexable of a given size to
the standard Java index, but keep a lower bound.

static int 
mapLB(int index,
Sizeable indexable)
Map a possibly negative index from an indexable of a given size to
the standard Java index, but keep a lower bound.

static int 
mapUB(int index,
int size)
Map a possibly negative index from an indexable of a given size to
the standard Java index, and keep an upper bound.

static int 
mapUB(int index,
Sizeable indexable)
Map a possibly negative index from an indexable of a given size to
the standard Java index, but keep a lower bound.

static int 
mapX(int index,
int size)
Map a possibly negative index from an indexable of a given size to
the standard Java index.

static int 
mapX(int index,
Sizeable indexable)
Map a possibly negative index from an indexable of a given size to
the standard Java index.

public static final int UNMAPPABLE
Integer.MAX_VALUE
.
This index can be used as an impossible result even if
Pythonesque indexing is used, as it is not mappable.
The mapping methods here will all throw an IndexOutOfBoundsException
if called with
an index of UNMAPPABLE
.public static final java.lang.String ERROR_INDEX_OUT_OF_BOUNDS_FORMAT
public static int map(int index, int size)
index
 index to be mapped, must not be UNMAPPABLE
size
 size of the indexable element for which the index is meantindex
is outside the
range [size, size[
java.lang.IndexOutOfBoundsException
 if index is UNMAPPABLE
public static int map(int index, @NotNull Sizeable indexable)
index
 index to be mapped, must not be UNMAPPABLE
indexable
 indexable which is indeindex
is outside the
range [size, size[
java.lang.IndexOutOfBoundsException
 if index is UNMAPPABLE
public static int mapLB(int index, int size)
0
is returned if a negative
index has a magnitude larger than the size.index
 index to be mapped, must not be UNMAPPABLE
size
 size of the indexable element for which the index is meantindex
is too largejava.lang.IndexOutOfBoundsException
 if index is UNMAPPABLE
public static int mapLB(int index, @NotNull Sizeable indexable)
0
is returned if a negative
index has a magnitude larger than the size.index
 index to be mapped, must not be UNMAPPABLE
indexable
 indexable which is indeindex
is too largejava.lang.IndexOutOfBoundsException
 if index is UNMAPPABLE
public static int mapUB(int index, int size)
size  1
is returned if a positive
index is larger or queal to sizeindex
 index to be mappedsize
 size of the indexable element for which the index is meantindex
is too largejava.lang.IndexOutOfBoundsException
 if index is UNMAPPABLE
public static int mapUB(int index, @NotNull Sizeable indexable)
0
is returned if a negative
index has a magnitude larger than the size.index
 index to be mapped, must not be UNMAPPABLE
indexable
 indexable which is indeindex
is too largejava.lang.IndexOutOfBoundsException
 if index is UNMAPPABLE
public static int mapX(int index, int size)
IndexOutOfBoundsException
if index
is negative
and out of range. It will not check positive indices, as it is expected that the returned
index is used in a way that it is checked anywayindex
 index to be mappedsize
 size of the indexable element for which the index is meant[0, size[
java.lang.IndexOutOfBoundsException
 if index is outside the range [size, size[
.
Note that this is always true for UNMAPPABLE
public static int mapX(int index, @NotNull Sizeable indexable)
IndexOutOfBoundsException
if index
is negative
and out of range. It will not check positive indices, as it is expected that the returned
index is used in a way that it is checked anywayindex
 index to be mappedindexable
 indexable which is inde[0, size[
java.lang.IndexOutOfBoundsException
 if index is negative and smaller than size
.
Note that this is always true for UNMAPPABLE