de.vc.util

## Class SwappingList<T>

- java.lang.Object
- - de.vc.util.SwappingList<T>

- All Implemented Interfaces:
    java.lang.Iterable<T>, java.util.Collection<T>, java.util.List<T>

      public class SwappingList<T>
      extends java.lang.Object
      implements java.util.List<T>

  The SwappingList can swap objects at begin of this list into a temporary file to reduce memory consumption.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `SwappingList()` Constructs a new swapping list.
    `SwappingList(int max, int keep)` Constructs a new swapping list.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(int index, T element)`
    `boolean` | `add(T o)`
    `boolean` | `addAll(java.util.Collection<? extends T> c)`
    `boolean` | `addAll(int index, java.util.Collection<? extends T> c)`
    `void` | `clear()`
    `boolean` | `contains(java.lang.Object o)` Returns `true` if this list contains the specified element.
    `boolean` | `containsAll(java.util.Collection<?> c)`
    `boolean` | `equals(java.lang.Object o)`
    `T` | `get(int index)` Gets an object of this list.
    `int` | `getKeepMemoryEntries()` Gets the number of (last) objects that are keeped in memory when objects are swapped to disc.
    `int` | `getMaxMemoryEntries()` Sets the maximum number of (last) objects that are hold in memory.
    `int` | `getMemoryIndex()` Gets the index of first element that is in memory.
    `java.io.File` | `getPageFile()` Gets the page-file of this swapping list.
    `int` | `hashCode()`
    `int` | `indexOf(java.lang.Object o)`
    `boolean` | `isEmpty()` Returns `true` if this list contains no elements.
    `java.util.Iterator<T>` | `iterator()`
    `int` | `lastIndexOf(java.lang.Object o)`
    `java.util.ListIterator<T>` | `listIterator()`
    `java.util.ListIterator<T>` | `listIterator(int index)`
    `T` | `remove(int index)`
    `boolean` | `remove(java.lang.Object o)`
    `boolean` | `removeAll(java.util.Collection<?> c)`
    `boolean` | `retainAll(java.util.Collection<?> c)`
    `T` | `set(int index, T element)` Sets the object at a given position.
    `void` | `setKeepMemoryEntries(int keep)` Sets the number of (last) objects that are keeped in memory when objects are swapped to disc.
    `void` | `setMaxMemoryEntries(int max)` Sets the maximum number of (last) objects that are hold in memory.
    `int` | `size()`
    `java.util.List<T>` | `subList(int fromIndex, int toIndex)`
    `void` | `swapAll()` Swaps all elements that are still in memory to disc.
    `java.lang.Object[]` | `toArray()`
    `java.lang.Object[]` | `toArray(java.lang.Object[] a)`

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

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

- - ### Constructor Detail

    - #### SwappingList

          public SwappingList()

      Constructs a new swapping list.

    - #### SwappingList

          public SwappingList(int max,
                      int keep)

      Constructs a new swapping list.
      Parameters:
        `max` - Maximum number of objects in memory.
        `keep` - Number of objects keeped in memory when swapped to disc.

  - ### Method Detail

    - #### getMemoryIndex

          public int getMemoryIndex()

      Gets the index of first element that is in memory. All elements with an lower index are stored in a temporary page file.
      Returns:
        Index of first element that is in memory.

    - #### setMaxMemoryEntries

          public void setMaxMemoryEntries(int max)

      Sets the maximum number of (last) objects that are hold in memory. If value is less then 1, all objects are hold in memory and no objects are swapped to disc.
      Parameters:
        `max` - Maximum number of objects in memory.

    - #### getMaxMemoryEntries

          public int getMaxMemoryEntries()

      Sets the maximum number of (last) objects that are hold in memory. If value is less then 1, all objects are hold in memory and no objects are swapped to disc.
      Returns:
        Maximum number of objects.

    - #### setKeepMemoryEntries

          public void setKeepMemoryEntries(int keep)

      Sets the number of (last) objects that are keeped in memory when objects are swapped to disc. Must be between 0 and (maximum number of objects - 1).
      Parameters:
        `keep` - Number of objects keeped in memory when swapped to disc.

    - #### getKeepMemoryEntries

          public int getKeepMemoryEntries()

      Gets the number of (last) objects that are keeped in memory when objects are swapped to disc.
      Returns:
        Number of objects keeped in memory after swapping.

    - #### getPageFile

          public java.io.File getPageFile()

      Gets the page-file of this swapping list. If no page file is created, NULL is returned.
      Returns:
        Page file of this list.

    - #### swapAll

          public void swapAll()

      Swaps all elements that are still in memory to disc.

    - #### size

          public int size()

      Specified by:
        `size` in interface `java.util.Collection<T>`
      Specified by:
        `size` in interface `java.util.List<T>`

    - #### isEmpty

          public boolean isEmpty()

      Returns `true` if this list contains no elements.
      Specified by:
        `isEmpty` in interface `java.util.Collection<T>`
      Specified by:
        `isEmpty` in interface `java.util.List<T>`
      Returns:
        `true` if this list contains no elements.

    - #### contains

          public boolean contains(java.lang.Object o)

      Returns `true` if this list contains the specified element. More formally, returns `true` if and only if this list contains at least one element `e` such that `(o==null ? e==null : o.equals(e))`.
      Specified by:
        `contains` in interface `java.util.Collection<T>`
      Specified by:
        `contains` in interface `java.util.List<T>`
      Parameters:
        `o` - element whose presence in this list is to be tested.
      Returns:
        `true` if this list contains the specified element.

    - #### iterator

          public java.util.Iterator<T> iterator()

      Specified by:
        `iterator` in interface `java.lang.Iterable<T>`
      Specified by:
        `iterator` in interface `java.util.Collection<T>`
      Specified by:
        `iterator` in interface `java.util.List<T>`

    - #### toArray

          public java.lang.Object[] toArray()

      Specified by:
        `toArray` in interface `java.util.Collection<T>`
      Specified by:
        `toArray` in interface `java.util.List<T>`

    - #### toArray

          public java.lang.Object[] toArray(java.lang.Object[] a)

      Specified by:
        `toArray` in interface `java.util.Collection<T>`
      Specified by:
        `toArray` in interface `java.util.List<T>`

    - #### add

          public boolean add(T o)

      Specified by:
        `add` in interface `java.util.Collection<T>`
      Specified by:
        `add` in interface `java.util.List<T>`

    - #### remove

          public boolean remove(java.lang.Object o)

      Specified by:
        `remove` in interface `java.util.Collection<T>`
      Specified by:
        `remove` in interface `java.util.List<T>`

    - #### containsAll

          public boolean containsAll(java.util.Collection<?> c)

      Specified by:
        `containsAll` in interface `java.util.Collection<T>`
      Specified by:
        `containsAll` in interface `java.util.List<T>`

    - #### addAll

          public boolean addAll(java.util.Collection<? extends T> c)

      Specified by:
        `addAll` in interface `java.util.Collection<T>`
      Specified by:
        `addAll` in interface `java.util.List<T>`

    - #### addAll

          public boolean addAll(int index,
                       java.util.Collection<? extends T> c)

      Specified by:
        `addAll` in interface `java.util.List<T>`

    - #### removeAll

          public boolean removeAll(java.util.Collection<?> c)

      Specified by:
        `removeAll` in interface `java.util.Collection<T>`
      Specified by:
        `removeAll` in interface `java.util.List<T>`

    - #### retainAll

          public boolean retainAll(java.util.Collection<?> c)

      Specified by:
        `retainAll` in interface `java.util.Collection<T>`
      Specified by:
        `retainAll` in interface `java.util.List<T>`

    - #### clear

          public void clear()

      Specified by:
        `clear` in interface `java.util.Collection<T>`
      Specified by:
        `clear` in interface `java.util.List<T>`

    - #### equals

          public boolean equals(java.lang.Object o)

      Specified by:
        `equals` in interface `java.util.Collection<T>`
      Specified by:
        `equals` in interface `java.util.List<T>`
      Overrides:
        `equals` in class `java.lang.Object`

    - #### hashCode

          public int hashCode()

      Specified by:
        `hashCode` in interface `java.util.Collection<T>`
      Specified by:
        `hashCode` in interface `java.util.List<T>`
      Overrides:
        `hashCode` in class `java.lang.Object`

    - #### get

          public T get(int index)

      Gets an object of this list. Note, if the object is already swapped to disc any modification to the object are not stored to swap-file! To check, if the object is swapped to disc you can use getMemoryIndex().
      Specified by:
        `get` in interface `java.util.List<T>`
      Parameters:
        `index` - Index of object.
      Returns:
        Object
      Throws:
        `java.lang.IndexOutOfBoundsException` - is thrown if index is invalid.

    - #### set

          public T set(int index,
              T element)

      Sets the object at a given position. Note, you can't set elements that are already swapped to disc.
      Specified by:
        `set` in interface `java.util.List<T>`
      Parameters:
        `index` - Index of element.
        `element` - Element.
      Returns:
        Old element.
      Throws:
        `java.lang.IndexOutOfBoundsException` - is thrown if index is invalid.

    - #### add

          public void add(int index,
                 T element)

      Specified by:
        `add` in interface `java.util.List<T>`

    - #### remove

          public T remove(int index)

      Specified by:
        `remove` in interface `java.util.List<T>`

    - #### indexOf

          public int indexOf(java.lang.Object o)

      Specified by:
        `indexOf` in interface `java.util.List<T>`

    - #### lastIndexOf

          public int lastIndexOf(java.lang.Object o)

      Specified by:
        `lastIndexOf` in interface `java.util.List<T>`

    - #### listIterator

          public java.util.ListIterator<T> listIterator()

      Specified by:
        `listIterator` in interface `java.util.List<T>`

    - #### listIterator

          public java.util.ListIterator<T> listIterator(int index)

      Specified by:
        `listIterator` in interface `java.util.List<T>`

    - #### subList

          public java.util.List<T> subList(int fromIndex,
                                  int toIndex)

      Specified by:
        `subList` in interface `java.util.List<T>`

© 2003-2011 by Sascha Schmidt (vision-cloud.de). All Rights Reserved.