org.eclipse.january.dataset

## Class Slice

- java.lang.Object
- - org.eclipse.january.dataset.Slice

- All Implemented Interfaces:
    Serializable, Cloneable

      public class Slice
      extends Object
      implements Cloneable, Serializable

  Class to represent a slice through a single dimension of a multi-dimensional dataset. A slice comprises a starting position, a stopping position (not included) and a stepping size.
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Slice()`
    `Slice(Integer stop)` Default to starting at 0 with steps of 1
    `Slice(Integer start, Integer stop)` Default to steps of 1
    `Slice(Integer start, Integer stop, Integer step)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `appendSliceToString(StringBuilder s, int len, int beg, int end, int del)` Append string representation of slice
    `Slice` | `clone()`
    `static void` | `convertFromSlice(Slice[] slice, int[] shape, int[] start, int[] stop, int[] step)` Populate given start, stop, step arrays from given slice array
    `static Slice[]` | `convertFromString(String sliceString)` Convert a string to a slice array
    `static Slice[]` | `convertToSlice(int[] start, int[] stop, int[] step)` Convert from a set of integer arrays to a slice array
    `static String` | `createString(int[] shape, int[] start, int[] stop, int[] step)` Create a string representing the slice taken from given shape
    `static String` | `createString(Slice... slices)`
    `Slice` | `flip()` Flip slice direction so slice begins at previous end point, steps in the opposite direction, and finishes at the previous start point .
    `int` | `getEnd()`
    `int` | `getLength()`
    `int` | `getNumSteps()`
    `int` | `getNumSteps(int beg, int end)`
    `int` | `getPosition(int n)` Get position of n-th step in slice
    `Integer` | `getStart()`
    `int` | `getStep()`
    `Integer` | `getStop()`
    `boolean` | `isSliceComplete()`
    `Slice` | `setLength(int length)` Set maximum value of slice
    `boolean` | `setPosition(int beg)` Set start and end from implied number of steps.
    `void` | `setStart(Integer start)` Set starting position of slice
    `void` | `setStep(int step)` Set step size of slice
    `void` | `setStop(Integer stop)` Set stopping position of slice
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### Slice

          public Slice()

    - #### Slice

          public Slice(Integer stop)

      Default to starting at 0 with steps of 1
      Parameters:
        `stop` - if null, then default to whatever shape is when converted

    - #### Slice

          public Slice(Integer start,
               Integer stop)

      Default to steps of 1
      Parameters:
        `start` - if null, then default to 0
        `stop` - if null, then default to whatever shape is when converted

    - #### Slice

          public Slice(Integer start,
               Integer stop,
               Integer step)

      Parameters:
        `start` - if null, then default to bound
        `stop` - if null, then default to bound
        `step` - if null, then default to 1

  - ### Method Detail

    - #### clone

          public Slice clone()

      Overrides:
        `clone` in class `Object`

    - #### setLength

          public Slice setLength(int length)

      Set maximum value of slice
      Parameters:
        `length` -
      Returns:
        this slice

    - #### isSliceComplete

          public boolean isSliceComplete()

      Returns:
        true if slice represents complete dimension

    - #### getLength

          public int getLength()

      Returns:
        maximum value of slice

    - #### getStart

          public Integer getStart()

      Returns:
        starting position of slice

    - #### getStop

          public Integer getStop()

      Returns:
        stopping position of slice

    - #### getStep

          public int getStep()

      Returns:
        step size of slice

    - #### setStart

          public void setStart(Integer start)

      Set starting position of slice
      Parameters:
        `start` - (can be null)

    - #### setStop

          public void setStop(Integer stop)

      Set stopping position of slice
      Parameters:
        `stop` - (can be null)

    - #### setPosition

          public boolean setPosition(int beg)

      Set start and end from implied number of steps. I.e. shift start to position given by parameter whilst keeping size of slice fixed
      Parameters:
        `beg` -
      Returns:
        true if end reached

    - #### getPosition

          public int getPosition(int n)

      Get position of n-th step in slice
      Parameters:
        `n` -
      Returns:
        position

    - #### setStep

          public void setStep(int step)

      Set step size of slice
      Parameters:
        `step` -

    - #### appendSliceToString

          public static void appendSliceToString(StringBuilder s,
                                 int len,
                                 int beg,
                                 int end,
                                 int del)

      Append string representation of slice
      Parameters:
        `s` -
        `len` -
        `beg` -
        `end` -
        `del` -

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### getNumSteps

          public int getNumSteps()

      Returns:
        number of steps in slice

    - #### getNumSteps

          public int getNumSteps(int beg,
                        int end)

      Parameters:
        `beg` -
        `end` - (exclusive)
      Returns:
        number of steps between limits

    - #### getEnd

          public int getEnd()

      Returns:
        last value in slice (< stop if step > 0, > stop if step < 0)

    - #### flip

          public Slice flip()

      Flip slice direction so slice begins at previous end point, steps in the opposite direction, and finishes at the previous start point .

      Note the stop value may not be preserved across two flips

    - #### convertFromSlice

          public static void convertFromSlice(Slice[] slice,
                              int[] shape,
                              int[] start,
                              int[] stop,
                              int[] step)

      Populate given start, stop, step arrays from given slice array
      Parameters:
        `shape` -
        `start` -
        `stop` -
        `step` -
        `slice` -

    - #### convertToSlice

          public static Slice[] convertToSlice(int[] start,
                               int[] stop,
                               int[] step)

      Convert from a set of integer arrays to a slice array
      Parameters:
        `start` -
        `stop` -
        `step` -
      Returns:
        a slice array

    - #### convertFromString

          public static Slice[] convertFromString(String sliceString)

      Convert a string to a slice array
      Parameters:
        `sliceString` -
      Returns:
        a slice array

    - #### createString

          public static String createString(int[] shape,
                            int[] start,
                            int[] stop,
                            int[] step)

      Create a string representing the slice taken from given shape
      Parameters:
        `shape` -
        `start` -
        `stop` -
        `step` -
      Returns:
        string representation

    - #### createString

          public static String createString(Slice... slices)

      Parameters:
        `slices` -
      Returns:
        string specifying slices

Copyright © 2017. All rights reserved.