de.caff.generics

## Class BasicLoop.Item<V extends BasicLoop.Item<V>>

- java.lang.Object
- - de.caff.generics.BasicLoop.Item<V>

- Type Parameters:
    `V` - item type
  Direct Known Subclasses:
    Loop.Item
  Enclosing class:
    BasicLoop<T extends BasicLoop.Item<T>>

      public abstract static class BasicLoop.Item<V extends BasicLoop.Item<V>>
      extends java.lang.Object

  Base implementation of a double linked loop item.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `(package private) BasicLoop<V>` | `loop` Loop containing this item.
    `(package private) V` | `next` Next item in the loop (possibly `this`).
    `(package private) V` | `previous` Previous item in the loop (possibly `this`).

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `Item(BasicLoop<V> loop)` Constructor for first item.
    `protected` | `Item(BasicLoop<V> loop, V previous, V next)` Standard constructor..

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `V` | `advanced(int steps)` Advance to the item `steps` steps away.
    `V` | `exchangeWith(Function3<? extends V,BasicLoop<V>,V,V> creator)` Exchange this item with a new item.
    `V` | `findNext(java.util.function.Predicate<? super V> condition)` Find the next item for which its value fulfills the given condition, starting with this item.
    `V` | `findPrevious(java.util.function.Predicate<? super V> condition)` Find the previous item for which its value fulfills the given condition, starting with this item.
    `BasicLoop<V>` | `getLoop()` Get the loop to which this item belongs.
    `V` | `getNext()` Get the next item.
    `V` | `getPrevious()` Get the previous item.
    `V` | `insertAfter(Function3<? extends V,BasicLoop<V>,V,V> creator)` Insert an item after this one.
    `V` | `insertBefore(Function3<? extends V,BasicLoop<V>,V,V> creator)` Insert an item before this one.
    `boolean` | `isValid()` Does this item still belong to a loop.
    `(package private) java.util.Iterator<V>` | `iteratorTo(V otherItem)`
    `int` | `minStepsTo(V otherItem)` Get the number of steps from this item to another item.
    `void` | `remove()` Remove this item from the loop.
    `int` | `stepsTo(V otherItem)` Get the number of steps from this item to another item.
    `void` | `swapPlaces(V item)` Exchange the loop position of this item with the one of the given item and vice versa.

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

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

- - ### Field Detail

    - #### loop

          @Nullable
          BasicLoop<V extends BasicLoop.Item<V>> loop

      Loop containing this item. May be `null` if this item is removed.

    - #### previous

          @NotNull
          V extends BasicLoop.Item<V> previous

      Previous item in the loop (possibly `this`).

    - #### next

          @NotNull
          V extends BasicLoop.Item<V> next

      Next item in the loop (possibly `this`).

  - ### Constructor Detail

    - #### Item

          protected Item(@NotNull
                         BasicLoop<V> loop,
                         @Nullable
                         V previous,
                         @Nullable
                         V next)

      Standard constructor..
      Parameters:
        `loop` - loop to which this item belongs
        `previous` - previous item
        `next` - next item

    - #### Item

          protected Item(@NotNull
                         BasicLoop<V> loop)

      Constructor for first item.
      Parameters:
        `loop` - loop to which this item belongs

  - ### Method Detail

    - #### getPrevious

          @NotNull
          public V getPrevious()

      Get the previous item.
      Returns:
        previous item

    - #### getNext

          @NotNull
          public V getNext()

      Get the next item.
      Returns:
        next item

    - #### advanced

          public V advanced(int steps)

      Advance to the item `steps` steps away.
      Parameters:
        `steps` - steps to advance, forward if positive, backward if negative
      Returns:
        item which is the given number of steps away

    - #### stepsTo

          public int stepsTo(@NotNull
                             V otherItem)

      Get the number of steps from this item to another item.
      Parameters:
        `otherItem` - another item which has to be in the same loop as this item
      Returns:
        number of forward steps to the given item, `0` or positive
      See Also:
        `minStepsTo(BasicLoop.Item)`

    - #### minStepsTo

          public int minStepsTo(@NotNull
                                V otherItem)

      Get the number of steps from this item to another item.
      Parameters:
        `otherItem` - other item which has to be in the same loop as this item
      Returns:
        minimal number of steps to get from this to the given item, positive for forward iteration, negative for backward iteration

    - #### getLoop

          @Nullable
          public BasicLoop<V> getLoop()

      Get the loop to which this item belongs.
      Returns:
        loop of this item, `null` if this item is removed from its loop

    - #### isValid

          public boolean isValid()

      Does this item still belong to a loop.
      Returns:
        `true` if it belongs to a loop
        `false` if it is already removed

    - #### insertBefore

          @NotNull
          public V insertBefore(Function3<? extends V,BasicLoop<V>,V,V> creator)

      Insert an item before this one.
      Parameters:
        `creator` - item creator
      Returns:
        inserted item

    - #### insertAfter

          @NotNull
          public V insertAfter(Function3<? extends V,BasicLoop<V>,V,V> creator)

      Insert an item after this one.
      Parameters:
        `creator` - item creator
      Returns:
        inserted item

    - #### swapPlaces

          public void swapPlaces(@NotNull
                                 V item)

      Exchange the loop position of this item with the one of the given item and vice versa.

      Note that this method also allows to exchange items between different loops and even removed items.

      Parameters:
        `item` - item which will exchange its chaining properties with this one

    - #### exchangeWith

          public V exchangeWith(@NotNull
                                Function3<? extends V,BasicLoop<V>,V,V> creator)

      Exchange this item with a new item.

      Note that this item is removed and `invalid` after the call.

      Parameters:
        `creator` - creator for new item
      Returns:
        newly created item

    - #### remove

          public void remove()

      Remove this item from the loop.

    - #### findNext

          @Nullable
          public V findNext(@NotNull
                                      java.util.function.Predicate<? super V> condition)

      Find the next item for which its value fulfills the given condition, starting with this item. This searches forward through the loop until the condition is met, or the loop is finished.
      Parameters:
        `condition` - condition to be checked
      Returns:
        item found or `null` if no item matches the condition

    - #### findPrevious

          @Nullable
          public V findPrevious(@NotNull
                                          java.util.function.Predicate<? super V> condition)

      Find the previous item for which its value fulfills the given condition, starting with this item. This searches backward through the loop until the condition is met, or the loop is finished.
      Parameters:
        `condition` - condition to be checked
      Returns:
        item found or `null` if no item matches the condition

    - #### iteratorTo

          @NotNull
          java.util.Iterator<V> iteratorTo(@NotNull
                                                    V otherItem)