Class PythonSlice

All Implemented Interfaces:
PythonLikeObject

public class PythonSlice extends AbstractPythonLikeObject
  • Field Details

  • Constructor Details

  • Method Details

    • asIntIndexForLength

      public static int asIntIndexForLength(PythonInteger index, int length)
      Convert index into a index for a sequence of length length. May be outside the range [0, length - 1]. Use for indexing into a sequence.
      Parameters:
      index - The given index
      length - The length
      Returns:
      index, if index in [0, length -1]; length - index, if index < 0.
    • asValidStartIntIndexForLength

      public static int asValidStartIntIndexForLength(PythonInteger index, int length)
      Convert index into a VALID start index for a sequence of length length. bounding it to the range [0, length - 1]. Use for sequence operations that need to search an portion of a sequence.
      Parameters:
      index - The given index
      length - The length
      Returns:
      index, if index in [0, length -1]; length - index, if index < 0 and -index ≤ length; otherwise 0 (if the index represent a position before 0) or length - 1 (if the index represent a position after the sequence).
    • asValidEndIntIndexForLength

      public static int asValidEndIntIndexForLength(PythonInteger index, int length)
      Convert index into a VALID end index for a sequence of length length. bounding it to the range [0, length]. Use for sequence operations that need to search an portion of a sequence.
      Parameters:
      index - The given index
      length - The length
      Returns:
      index, if index in [0, length]; length - index, if index < 0 and -index ≤ length + 1; otherwise 0 (if the index represent a position before 0) or length (if the index represent a position after the sequence).
    • indices

      public PythonLikeTuple indices(PythonInteger sequenceLength)
    • getStartIndex

      public int getStartIndex(int length)
    • getStopIndex

      public int getStopIndex(int length)
    • getStrideLength

      public int getStrideLength()
    • iterate

      public void iterate(int length, PythonSlice.SliceConsumer consumer)
    • getSliceSize

      public int getSliceSize(int length)
    • pythonEquals

      public PythonBoolean pythonEquals(PythonSlice other)
    • pythonHash

      public PythonInteger pythonHash()
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • $method$__hash__

      public PythonInteger $method$__hash__()