com.hammurapi.store

## Class AbstractIndex<ST,T extends ST,PK,V,S extends Store<ST,PK,S>>

- java.lang.Object
- - com.hammurapi.store.AbstractIndex<ST,T,PK,V,S>

- All Implemented Interfaces:
    Index<ST,T,PK,V,S>, OrderedIndex<ST,T,PK,V,S>, Iterable<T>

      public abstract class AbstractIndex<ST,T extends ST,PK,V,S extends Store<ST,PK,S>>
      extends Object
      implements OrderedIndex<ST,T,PK,V,S>

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected class` | `AbstractIndex.UpdateEntry`

    - ### Nested classes/interfaces inherited from interface com.hammurapi.store.Index

      `Index.Type`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Runnable` | `applyUpdatesTask`
    `protected Comparator<V>` | `comparator`
    `protected AtomicBoolean` | `isCorrupt`
    `protected boolean` | `ordered`
    `protected AbstractStore<ST,PK,S>` | `store`
    `protected Index.Type` | `type`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `AbstractIndex(Predicate<ST,S> predicate, Extractor<T,V,S> extractor, Index.Type type, boolean ordered, Comparator<V> comparator, AbstractStore<ST,PK,S> store)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `applyUpdate(Store.Handle<ST,PK,S> changed, boolean isNew)` This method is invoked within write lock, no need to acquire own lock.
    `protected void` | `checkCorrupt()`
    `void` | `cleanup()` Removes invalid handles from index store.
    `Index<ST,T,PK,V,S>` | `createProxy()`
    `Iterable<T>` | `find(V from, V to, boolean fromInclusive, boolean toInclusive)` Finds objects by index range.
    `Comparator<V>` | `getComparator()`
    `protected abstract ExecutorService` | `getExecutorService()`
    `Extractor<T,V,S>` | `getExtractor()`
    `int` | `getGranularity()`
    `protected abstract Map<V,Collection<Store.Handle<ST,PK,S>>>` | `getIndexMultiStore()`
    `protected abstract Map<V,Store.Handle<ST,PK,S>>` | `getIndexUniqueStore()`
    `protected abstract Collection<AbstractIndex.UpdateEntry>` | `getPendingUpdates()`
    `Predicate<ST,S>` | `getPredicate()`
    `S` | `getStore()`
    `protected abstract void` | `handleAsynchException(Exception e)` Handles exceptions thrown in asynchronous applyUpdates().
    `boolean` | `isOrdered()`
    `boolean` | `isUnique()`
    `Iterator<T>` | `iterator()`
    `protected abstract Lock` | `readLock()`
    `String` | `toString()`
    `void` | `update(Store.Handle<ST,PK,S> changed, boolean isNew)` Updates index
    `abstract void` | `upgrade(Index.Type type, boolean ordered, Comparator<V> comparator)` Upgrades index type.
    `protected abstract Lock` | `writeLock()`

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

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

- - ### Field Detail

    - #### type

          protected Index.Type type

    - #### ordered

          protected boolean ordered

    - #### comparator

          protected Comparator<V> comparator

    - #### store

          protected AbstractStore<ST,PK,S extends Store<ST,PK,S>> store

    - #### isCorrupt

          protected AtomicBoolean isCorrupt

    - #### applyUpdatesTask

          protected Runnable applyUpdatesTask

  - ### Constructor Detail

    - #### AbstractIndex

          protected AbstractIndex(Predicate<ST,S> predicate,
                       Extractor<T,V,S> extractor,
                       Index.Type type,
                       boolean ordered,
                       Comparator<V> comparator,
                       AbstractStore<ST,PK,S> store)

  - ### Method Detail

    - #### getIndexUniqueStore

          protected abstract Map<V,Store.Handle<ST,PK,S>> getIndexUniqueStore()

      Returns:
        Index unique store. If index is ordered, the index store shall be of type SortedMap.

    - #### getIndexMultiStore

          protected abstract Map<V,Collection<Store.Handle<ST,PK,S>>> getIndexMultiStore()

      Returns:
        Index multi-store. If index is ordered, the index store shall be of type SortedMap.

    - #### readLock

          protected abstract Lock readLock()

    - #### writeLock

          protected abstract Lock writeLock()

    - #### upgrade

          public abstract void upgrade(Index.Type type,
                     boolean ordered,
                     Comparator<V> comparator)

      Upgrades index type.
      Parameters:
        `type` - Asynchronous and lazy indices can be upgraded to synchronous. All index types can be upgraded to unique if current index data does not contain duplicates.
        `ordered` - unordered index can be upgraded to ordered.

    - #### iterator

          public Iterator<T> iterator()

      Specified by:
        `iterator` in interface `Iterable<T extends ST>`

    - #### getStore

          public S getStore()

      Specified by:
        `getStore` in interface `Index<ST,T extends ST,PK,V,S extends Store<ST,PK,S>>`
      Returns:
        Back-link to the store.

    - #### getPredicate

          public Predicate<ST,S> getPredicate()

      Specified by:
        `getPredicate` in interface `Index<ST,T extends ST,PK,V,S extends Store<ST,PK,S>>`

    - #### getExtractor

          public Extractor<T,V,S> getExtractor()

      Specified by:
        `getExtractor` in interface `Index<ST,T extends ST,PK,V,S extends Store<ST,PK,S>>`

    - #### isUnique

          public boolean isUnique()

      Specified by:
        `isUnique` in interface `Index<ST,T extends ST,PK,V,S extends Store<ST,PK,S>>`

    - #### isOrdered

          public boolean isOrdered()

      Specified by:
        `isOrdered` in interface `Index<ST,T extends ST,PK,V,S extends Store<ST,PK,S>>`

    - #### getComparator

          public Comparator<V> getComparator()

      Specified by:
        `getComparator` in interface `Index<ST,T extends ST,PK,V,S extends Store<ST,PK,S>>`

    - #### getPendingUpdates

          protected abstract Collection<AbstractIndex.UpdateEntry> getPendingUpdates()

    - #### update

          public void update(Store.Handle<ST,PK,S> changed,
                    boolean isNew)

      Updates index
      Parameters:
        `changed` - Changed/added handle.
        `isNew` - If true, then handle was added, updated otherwise.

    - #### getExecutorService

          protected abstract ExecutorService getExecutorService()

    - #### checkCorrupt

          protected void checkCorrupt()

    - #### applyUpdate

          protected void applyUpdate(Store.Handle<ST,PK,S> changed,
                         boolean isNew)

      This method is invoked within write lock, no need to acquire own lock.
      Parameters:
        `changed` -

    - #### getGranularity

          public int getGranularity()

    - #### handleAsynchException

          protected abstract void handleAsynchException(Exception e)

      Handles exceptions thrown in asynchronous applyUpdates().
      Parameters:
        `e` -

    - #### cleanup

          public void cleanup()

      Removes invalid handles from index store. This method operates under store's write lock, so it is not necessary to acquire own lock.

    - #### find

          public Iterable<T> find(V from,
                         V to,
                         boolean fromInclusive,
                         boolean toInclusive)

      Description copied from interface: `OrderedIndex`
      Finds objects by index range.
      Specified by:
        `find` in interface `OrderedIndex<ST,T extends ST,PK,V,S extends Store<ST,PK,S>>`
      Parameters:
        `from` - Low index range value.
        `to` - High index range value.
        `fromInclusive` - If true, `from` is included to the range.
        `toInclusive` - If true, `to` is included to the range.
      Returns:

    - #### createProxy

          public Index<ST,T,PK,V,S> createProxy()

      Returns:
        proxy which implements interfaces appropriate for the index type.

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`