de.vc.util

## Class LazyList<E>

- java.lang.Object
- - java.util.AbstractCollection<E>
  - - java.util.AbstractList<E>
    - - de.vc.util.LazyList<E>

- All Implemented Interfaces:
    java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>
  Direct Known Subclasses:
    LazyListWithLoader

      public abstract class LazyList<E>
      extends java.util.AbstractList<E>

  A lazy list loads it's elements on demand using chunks. To use this class you must extends from LazyList and implement `calculateSize` and `fillChunk`.

- - ### Field Summary

    - ### Fields inherited from class java.util.AbstractList

      `modCount`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `LazyList()` Creates a new lazy list with chunkSize=10 and chunkOffset=0.
    `LazyList(int chunkSize)` Creates a new lazy list with a given chunkSize and chunkOffset=0.
    `LazyList(int chunkSize, int chunkOffset)` Creates a new lazy list with a given chunkSize and chunkOffset.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected abstract int` | `calculateSize()` Implement this method to calculate the total size of this list.
    `protected abstract void` | `fillChunk(int start, int length)` Implement this method to load a range of lazy loaded objects.
    `E` | `get(int index)`
    `float` | `getGrowFactor()`
    `int` | `getShrinkThreshold()`
    `E` | `set(int index, E o)` Sets a cached object.
    `void` | `setChunkParams(int size, int offset)` Sets the chunk parameters.
    `void` | `setGrowFactor(float growFactor)`
    `void` | `setShrinkThreshold(int shrinkThreshold)`
    `protected void` | `setSize(int newSize)` An implementing class can update the size of this list any time (e.g. if the size of a result set changed).
    `int` | `size()`

    - ### Methods inherited from class java.util.AbstractList

      `add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, subList`

    - ### Methods inherited from class java.util.AbstractCollection

      `addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString`

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

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

    - ### Methods inherited from interface java.util.List

      `addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray`

- - ### Constructor Detail

    - #### LazyList

          public LazyList()

      Creates a new lazy list with chunkSize=10 and chunkOffset=0.

    - #### LazyList

          public LazyList(int chunkSize)

      Creates a new lazy list with a given chunkSize and chunkOffset=0.
      Parameters:
        `chunkSize` - Size of a lazy loaded chunk.

    - #### LazyList

          public LazyList(int chunkSize,
                  int chunkOffset)

      Creates a new lazy list with a given chunkSize and chunkOffset.
      Parameters:
        `chunkSize` - Size of a lazy loaded chunk.
        `chunkOffset` - Offset of a lazy loaded chunk, must be 0 or negative.

  - ### Method Detail

    - #### get

          public final E get(int index)

      Specified by:
        `get` in interface `java.util.List<E>`
      Specified by:
        `get` in class `java.util.AbstractList<E>`

    - #### size

          public final int size()

      Specified by:
        `size` in interface `java.util.Collection<E>`
      Specified by:
        `size` in interface `java.util.List<E>`
      Specified by:
        `size` in class `java.util.AbstractCollection<E>`

    - #### setChunkParams

          public void setChunkParams(int size,
                            int offset)

      Sets the chunk parameters.
      Parameters:
        `size` - Size of a lazy loaded chunk.
        `offset` - Offset of a lazy loaded chunk, must be 0 or negative.
      Throws:
        `java.lang.IllegalArgumentException`

    - #### set

          public E set(int index,
              E o)

      Sets a cached object. This method should be invoked in `fillChunk`.
      Specified by:
        `set` in interface `java.util.List<E>`
      Overrides:
        `set` in class `java.util.AbstractList<E>`
      Parameters:
        `index` - Index
        `o` - Object

    - #### getGrowFactor

          public float getGrowFactor()

    - #### setGrowFactor

          public void setGrowFactor(float growFactor)

    - #### getShrinkThreshold

          public int getShrinkThreshold()

    - #### setShrinkThreshold

          public void setShrinkThreshold(int shrinkThreshold)

    - #### setSize

          protected void setSize(int newSize)

      An implementing class can update the size of this list any time (e.g. if the size of a result set changed).
      Parameters:
        `newSize` -

    - #### calculateSize

          protected abstract int calculateSize()

      Implement this method to calculate the total size of this list.
      Returns:
        Size of list.

    - #### fillChunk

          protected abstract void fillChunk(int start,
                       int length)

      Implement this method to load a range of lazy loaded objects. Use the `set(int i, Object o)` method to set a loaded object.
      Parameters:
        `start` - Start offset
        `length` - Chunk length

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