ReadSublistOp
Date: 2016-02-29

de.zib.scalaris.operations

## Class ReadSublistOp

- java.lang.Object
- - de.zib.scalaris.operations.PartialReadOp
  - - de.zib.scalaris.operations.ReadSublistOp

- All Implemented Interfaces:
    Operation, TransactionOperation, TransactionSingleOpOperation

      public class ReadSublistOp
      extends PartialReadOp

  Operation reading a sublist from a value. Extracts a sublist of length `Length` starting at `Start`.
  - If Start is negative, we count from the end, e.g. `-1` is the last element, `-2` the second last.
  - If Length is negative, the sublist is created in reversed direction, e.g. `sublist([a,b,c], -1, -2)` gets `[c, b]`.
  - If Start is less than -ListLength and Length is non-negative, it will be set to `1`. If Length is negative in this case, an empty sublist will be returned.
  - If Start is greater than ListLength and Length is non-negative, an empty sublist will be returned. If Length is negative in this case, it will be set to `ListLength`.
  - Note: sublists never wrap between start and end, i.e. `sublist([a,b,c], 1, -2)` gets `[]`!
  - Examples:
    - first 10: `sublist(L, 1, 10)` | `sublist(L, 10, -10)` (reverse order)
    - last 10 : `sublist(L, -10, 10)` | `sublist(L, -1, -10)` (reverse order)
  Since:
    3.18
  Version:
    3.18
  Author:
    Nico Kruber, kruber@zib.de

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `ReadSublistOp.Result` Result type of sublist operations.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ReadSublistOp(OtpErlangString key, OtpErlangInt start, OtpErlangInt length)` Constructor
    `ReadSublistOp(String key, int start, int length)` Constructor

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `OtpErlangObject` | `getErlang(boolean compressed)` Gets the erlang representation of the operation.
    `ReadSublistOp.Result` | `processResult()` Processes the result set by `Operation.setResult(OtpErlangObject, boolean)`.
    `ReadSublistOp.Result` | `processResultSingle()` Processes the result set by `Operation.setResult(OtpErlangObject, boolean)` assuming that operation was committed.
    `String` | `toString()`

    - ### Methods inherited from class de.zib.scalaris.operations.PartialReadOp

      `getKey, getResult, getResultCompressed, setResult`

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

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

- - ### Constructor Detail

    - #### ReadSublistOp

          public ReadSublistOp(OtpErlangString key,
                       OtpErlangInt start,
                       OtpErlangInt length)

      Constructor
      Parameters:
        `key` - the key to read
        `start` - the start of the sublist (may be negative - see `ReadSublistOp`)
        `length` - the length of the sublist (may be negative - see `ReadSublistOp`)

    - #### ReadSublistOp

          public ReadSublistOp(String key,
                       int start,
                       int length)

      Constructor
      Parameters:
        `key` - the key to read
        `start` - the start of the sublist (may be negative - see `ReadSublistOp`)
        `length` - the length of the sublist (may be negative - see `ReadSublistOp`)

  - ### Method Detail

    - #### getErlang

          public OtpErlangObject getErlang(boolean compressed)

      Description copied from interface: `Operation`
      Gets the erlang representation of the operation.
      Parameters:
        `compressed` - whether the value part in the term should be encoded, i.e. compressed into an Erlang binary, or not
      Returns:
        erlang representation for api_tx:req_list

    - #### processResult

          public ReadSublistOp.Result processResult()
                                             throws NotFoundException,
                                                    NotAListException,
                                                    UnknownException

      Description copied from interface: `Operation`
      Processes the result set by `Operation.setResult(OtpErlangObject, boolean)`. Note: the created value is not cached!
      Returns:
        a (potentially) read value (may be `null`)
      Throws:
        `NotFoundException` - if the requested key does not exist
        `NotAListException` - if the previously stored value was no list
        `UnknownException` - if any other error occurs

    - #### processResultSingle

          public ReadSublistOp.Result processResultSingle()
                                                   throws NotFoundException,
                                                          NotAListException,
                                                          UnknownException

      Description copied from interface: `TransactionSingleOpOperation`
      Processes the result set by `Operation.setResult(OtpErlangObject, boolean)` assuming that operation was committed. In contrast to `Operation.processResult()` operations like `WriteOp` will throw a proper `AbortException` for their commit part instead of an `UnknownException`. Note: the created value is not cached!
      Returns:
        a (potentially) read value (may be `null`)
      Throws:
        `NotFoundException` - if the requested key does not exist
        `NotAListException` - if the previously stored value was no list
        `UnknownException` - if any other error occurs

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`