Top Description Inners Fields Constructors Methods
org.python.core

public Class PySlice

extends AbstractPyObject
Class Inheritance
Imports
java.lang.invoke.MethodHandles, org.python.core.Exposed.Member, .PyType.Flag

The Python slice object.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public class
PySlice.Indices

An object that presents the start, stop and step data members from this slice object as Java ints in an immutable data object, adjusted to a specific length of a notional source sequence (see Indices#Indices(int)).

Field Summary

Modifier and TypeField and Description
private final Object
private final Object
private final Object
pack-priv static final PyType
TYPE

The type of Python object this class implements.

Constructor Summary

AccessConstructor and Description
public
PySlice(Object
index or null (for None).
start
,
Object
index or null (for None).
stop
,
Object
or null (for None).
step
)

Create a Python slice from object arguments.

public
PySlice(Object
index or null (for None).
start
,
Object
index or null (for None).
stop
)

Create a Python slice from two object arguments.

public
PySlice(int
index of first item in slice.
start
,
int
index of first item not in slice.
stop
)

Create a Python slice from Java int arguments.

Method Summary

Modifier and TypeMethod and Description
private Object
private Object
pack-priv final Object
private Object
private Object

Returns:

result of comparison or NotImplemented
compare
(Object
must be a slice or return NotImplemented
o
,
Comparison op)

Invoke the comparison specified (supports __eq__ and __ne__).

pack-priv PySlice.Indices

Returns:

an Indices from this slice and the length
getIndices
(int
of the sequence
length
)

Calculate the actual indices of this slice in relation to a sequence of length length, reporting the effective start, stop, and step, and the number of elements in the slice.

pack-priv final Object
indices(Object length)

Inherited from org.python.core.AbstractPyObject:
getTypetoString

Field Detail

startback to summary
private final Object start
Annotations
@Member
stepback to summary
private final Object step
Annotations
@Member
stopback to summary
private final Object stop
Annotations
@Member
TYPEback to summary
pack-priv static final PyType TYPE

The type of Python object this class implements.

Constructor Detail

PySliceback to summary
public PySlice(Object start, Object stop, Object step)

Create a Python slice from object arguments.

Parameters
start:Object

index or null (for None).

stop:Object

index or null (for None).

step:Object

or null (for None).

PySliceback to summary
public PySlice(Object start, Object stop)

Create a Python slice from two object arguments. The step is implicitly None.

Parameters
start:Object

index or null (for None).

stop:Object

index or null (for None).

PySliceback to summary
public PySlice(int start, int stop)

Create a Python slice from Java int arguments.

Parameters
start:int

index of first item in slice.

stop:int

index of first item not in slice.

Method Detail

__eq__back to summary
private Object __eq__(Object o) throws Throwable
Annotations
@SuppressWarnings:unused
__ne__back to summary
private Object __ne__(Object o) throws Throwable
Annotations
@SuppressWarnings:unused
__reduce__back to summary
pack-priv final Object __reduce__()
__repr__back to summary
private Object __repr__()
Annotations
@SuppressWarnings:unused
compareback to summary
private Object compare(Object o, Comparison op) throws Throwable

Invoke the comparison specified (supports __eq__ and __ne__).

Parameters
o:Object

must be a slice or return NotImplemented

op:Comparison

Comparison#EQ or Comparison#NE

Returns:Object

result of comparison or NotImplemented

Exceptions
Throwable:
from element comparison
getIndicesback to summary
pack-priv PySlice.Indices getIndices(int length) throws TypeError, Throwable

Calculate the actual indices of this slice in relation to a sequence of length length, reporting the effective start, stop, and step, and the number of elements in the slice.

Parameters
length:int

of the sequence

Returns:PySlice.Indices

an Indices from this slice and the length

Exceptions
TypeError:
if any index has no __index__
Throwable:
from implementation of __index__
indicesback to summary
pack-priv final Object indices(Object length) throws Throwable
org.python.core back to summary

public Class PySlice.Indices

extends Object
Class Inheritance

An object that presents the start, stop and step data members from this slice object as Java ints in an immutable data object, adjusted to a specific length of a notional source sequence (see Indices#Indices(int)).

End-relative addressing (as in a[-3:-1]) and None indices (as in a[:]) have been translated in construction to absolute indices a client may use without further range checks.

Field Summary

Modifier and TypeField and Description
private static final int
private static final int
public final int
slicelength

The number of elements to select from the source sequence, and therefore the length of the slice to be generated.

public final int
start

Absolute index in the source sequence of the first element to be taken by the slice.

public final int
step

The index step to make when selecting elements from the source sequence.

public final int
stop

Absolute index relative to the source sequence that is the image of PySlice#stop.

Constructor Summary

AccessConstructor and Description
public
Indices(int
of the target sequence
length
)

Extract the start, stop and step data members from the parent slice as Java ints in an instance of Indices, then adjust start and stop assuming they apply to a sequence of the specified length.

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

MAXback to summary
private static final int MAX
MINback to summary
private static final int MIN
slicelengthback to summary
public final int slicelength

The number of elements to select from the source sequence, and therefore the length of the slice to be generated.

startback to summary
public final int start

Absolute index in the source sequence of the first element to be taken by the slice. If slicelength!= 0, this index lies within the bounds of the sequence.

stepback to summary
public final int step

The index step to make when selecting elements from the source sequence. Never zero.

stopback to summary
public final int stop

Absolute index relative to the source sequence that is the image of PySlice#stop. Dealing correctly with a step size other than one is difficult. Clients should normally choose slicelength, to decide how many elements to take from the sequence, rather than use stop to decide when to stop.

Constructor Detail

Indicesback to summary
public Indices(int length) throws TypeError, ValueError, Throwable

Extract the start, stop and step data members from the parent slice as Java ints in an instance of Indices, then adjust start and stop assuming they apply to a sequence of the specified length. Store in slicelength the number of elements the parent slice will take from that sequence.

Out of bounds indices are clipped in a manner consistent with the handling of normal slices. The idiom:

Indices x = slice.new Indices(a.length);
for (int k=0; k<x.slicelength; k++) {
    f(a[x.start + k*x.step]);
}
will access only in in-range elements.

Detail: Before adjusting to the specific sequence length, the following occurs. Extract the start, stop and step data members from the parent slice and convert them to Java ints using their __index__ methods, or mapping None to conventional values. Silently reduce values larger than Integer.MAX_VALUE to Integer.MAX_VALUE. Silently boost start and stop values less than Integer.MIN_VALUE to Integer.MIN_VALUE. And silently boost step values less than -Integer.MAX_VALUE to -Integer.MAX_VALUE.

Parameters
length:int

of the target sequence

Exceptions
TypeError:
if any index not None has no __index__
ValueError:
if step==0
Throwable:
from the implementation of __index__

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override