Class ListCache<M extends Serializable,K extends Serializable,T extends Serializable>

java.lang.Object
name.matthewgreet.strutscommons.util.ListCache<M,K,T>
All Implemented Interfaces:
Serializable

public class ListCache<M extends Serializable,K extends Serializable,T extends Serializable> extends Object implements Serializable
See Also:
  • Constructor Details

  • Method Details

    • markChanged

      protected void markChanged()
    • notifyChanged

      protected void notifyChanged()
      Notification of change. This typically notifies the parent container.
    • addListCacheListener

      public void addListCacheListener(ListCacheListener<T> listener)
    • addItem

      public void addItem(T item) throws IllegalStateException, Exception
      Adds new item to end of list and sets it as selected item.
      Parameters:
      item - New item to add to end of list.
      Throws:
      IllegalStateException - List must be reloaded but list finder is missing.
      Exception - Failed to retrieve extensions.
    • forceReload

      public void forceReload() throws Exception
      Reloads list using currently set list finder, id list finder, or list size finder.
      Throws:
      Exception
    • getBaseRecordListFinder

      public ListFinder<M,T> getBaseRecordListFinder()
      Returns Strategy object used to retrieve list.
    • getHasDetails

      public boolean getHasDetails()
      Returns whether records must lazy load additional data for detail pages.
    • getIdListFinder

      public IdListFinder<M,K> getIdListFinder()
      Returns Strategy used to retrieve list.
    • getItemFinder

      public SingleItemFinder<K,T> getItemFinder()
      Returns Strategy used to retrieve single item of list, including any extensions, or null if not set.
    • getItemSorter

      public ListCacheRecordComparator<T> getItemSorter()
      Returns Strategy used to sort list, or null for no sorting.
    • getKeyExtractor

      public KeyExtractor<K,T> getKeyExtractor()
      Returns Strategy that extracts the primary key from a record.
    • getList

      public List<T> getList() throws Exception
      Returns entire record list, loading it if needed.
      Throws:
      Exception
    • getListeners

      public Collection<ListCacheListener<T>> getListeners()
      Returns all listeners of any change to this.
    • getListFinder

      public ListFinder<M,T> getListFinder()
      Returns Strategy object used to retrieve list.
    • getListSize

      public int getListSize() throws Exception
      Returns list size.
      Throws:
      Exception
    • getListSizeFinder

      public ListSizeFinder<M> getListSizeFinder()
      Returns Strategy object used to retrieve list size.
    • getMasterList

      public ListCache<?,?,M> getMasterList()
      Returns master list cache, where records of this slave list cache are related to selected record of master list cache, or null if this is not a slave list.
    • getName

      public String getName()
    • getPage

      public List<T> getPage() throws Exception
      Returns current page containing selected record, loading records if needed.
      Throws:
      Exception
    • getPageByIdsFinder

      public PageByIdsFinder<K,T> getPageByIdsFinder()
      Returns Strategy object used to retrieve page by their record primary keys.
    • getPageByIndexRangeFinder

      public PageByIndexRangeFinder<M,T> getPageByIndexRangeFinder()
      Returns Strategy object used to retrieve page by their indices.
    • getPageExtensionAssembler

      public PageExtensionAssembler<T> getPageExtensionAssembler()
      Returns Transfer Object Assembler for adding record extensions needed for requested page that is not loaded by a base record list finder. Only applies for base record list pagination mode.
    • getPageNo

      public int getPageNo() throws Exception
      Returns number of current page, starting at 1, containing selected record.
      Throws:
      Exception
    • getPageSize

      public int getPageSize() throws Exception
      Throws:
      Exception
    • getPaginationMode

      public ListCache.PaginationMode getPaginationMode()
      Returns how pages are retrieved.
    • getRange

      public List<T> getRange(int startIndex, int endIndex) throws Exception
      Returns range of records from cached list, loading them if needed. If the start or end are out of range, they are treated as the index of the nearest item. Thus, at least one item is always returned unless no items exist at all.
      Throws:
      Exception
    • getReload

      public boolean getReload()
      Indicates if record list must be reloaded.
    • getReSort

      public boolean getReSort()
      Indicates if record list must be sorted.
    • getSelected

      public T getSelected() throws Exception
      Returns selected item from list.
      Throws:
      Exception
    • getSelectedIndex

      public int getSelectedIndex() throws Exception
      Returns index of currently selected item, starting at 0, in list.
      Throws:
      Exception
    • getTotalPages

      public int getTotalPages()
    • markReload

      public void markReload()
      Marks record list as requiring a reload.
    • markReSort

      public void markReSort()
      Marks record list as requiring a re-sort.
    • remove

      public T remove(int index) throws IllegalStateException, Exception
      Removes item from list at index position and returns it. Returns null if no item exists at index.
      Throws:
      IllegalStateException - List must be reloaded but list finder is missing.
      Exception - Failed to retrieve extensions.
    • removeListCacheListener

      public void removeListCacheListener(ListCacheListener<T> listener)
    • removeSelected

      public T removeSelected() throws IllegalStateException, Exception
      Removes currently, selected item from list and returns it.

      Returns null if the list is empty and there is no selected item.

      Throws:
      IllegalStateException - List must be reloaded but list finder is missing.
      Exception - Failed to retrieve extensions.
    • setBaseRecordListAndFinder

      public void setBaseRecordListAndFinder(List<T> list, ListFinder<M,T> baseRecordListFinder)
      Caches list already loaded, sets base record list finder Strategy used to load it, and sets base record list pagination mode.
    • setBaseRecordListFinder

      public void setBaseRecordListFinder(ListFinder<M,T> baseRecordListFinder)
      Sets base record list finder, marks list for reload, and sets base record list pagination mode..
    • setIdListAndFinder

      public void setIdListAndFinder(List<K> idList, IdListFinder<M,K> idListFinder)
      Caches id list already loaded, sets id list finder Strategy used to load it, and sets page by ids pagination mode.
    • setIdListFinder

      public void setIdListFinder(IdListFinder<M,K> idListFinder)
      Sets Strategy used to retrieve ids, sets page by ids pagination mode and marks list for reload.
    • setItemFinder

      public void setItemFinder(SingleItemFinder<K,T> value)
      Sets Strategy for retrieving single item of list, including details.
    • setItemSorter

      public void setItemSorter(ListCacheRecordComparator<T> itemSorter)
      Sets Strategy for sorting list data, overriding the list order of a list finder, or null to preserve list order.
    • setKeyExtractor

      public void setKeyExtractor(KeyExtractor<K,T> keyExtractor)
      Sets Strategy that extracts the primary key from a record.
    • setListAndFinder

      public void setListAndFinder(List<T> list, ListFinder<M,T> listFinder)
      Caches list already loaded, sets full list Strategy used to load it, and sets full list pagination mode.
    • setListFinder

      public void setListFinder(ListFinder<M,T> listFinder)
      Sets full list Strategy to retrieve list when needed and sets full list pagination mode.
    • setListSizeAndFinder

      public void setListSizeAndFinder(int listSize, ListSizeFinder<M> listSizeFinder, PageByIndexRangeFinder<M,T> pageByIndexRangeFinder)
      Sets list size, the list size finder used to find that, page by index range finder that will be used to find pages from list, and sets page by index pagination mode.
      Parameters:
      listSize - Size of list to cache.
      listSizeFinder - Command that found list size.
      pageByIndexRangeFinder - Command that will load pages of list.
    • setListSizeFinder

      public void setListSizeFinder(ListSizeFinder<M> listSizeFinder, PageByIndexRangeFinder<M,T> pageByIndexRangeFinder)
      Sets the list size finder, sets accompanying page by index range finder that will be used to find pages from list, sets page by index pagination mode, and marks list for reload.
      Parameters:
      listSizeFinder - Command that found list size.
      pageByIndexRangeFinder - Command that will load pages of list..
    • setPageByIdsFinder

      public void setPageByIdsFinder(PageByIdsFinder<K,T> value)
      Sets Strategy used to retrieve page by their record ids.
    • setPageExtensionAssembler

      public void setPageExtensionAssembler(PageExtensionAssembler<T> pageExtensionAssembler)
      Sets Transfer Object Assembler for adding record extensions needed for requested page that is not loaded by a base record list finder. Only applies for base record list pagination mode.
    • setPageNo

      public void setPageNo(int pageNo)
      Sets index of currently selected item to be first item of page where pageNo starts at one.
    • setPageSize

      public void setPageSize(int pageSize)
    • setSelected

      public void setSelected(T value)
      Replaces selected item in list.
    • setSelectedIndex

      public void setSelectedIndex(int index)
      Sets currently selected item in list by index. Sets to last item if index exceeds last item. Sets no currently selected item if index is -1.