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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
ListCache.ListCacheConfig<M extends Serializable,
K extends Serializable, T extends Serializable> Configuration set by concrete class to control template behaviour for lists.static enum
static enum
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds new item to end of list and sets it as selected item.void
addListCacheListener
(ListCacheListener<T> listener) void
Reloads list using currently set list finder, id list finder, or list size finder.ListFinder
<M, T> Returns Strategy object used to retrieve list.boolean
Returns whether records must lazy load additional data for detail pages.Returns Strategy used to retrieve list.Returns Strategy used to retrieve single item of list, including any extensions, or null if not set.Returns Strategy used to sort list, or null for no sorting.Returns Strategy that extracts the primary key from a record.getList()
Returns entire record list, loading it if needed.Returns all listeners of any change to this.ListFinder
<M, T> Returns Strategy object used to retrieve list.int
Returns list size.Returns Strategy object used to retrieve list size.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()
getPage()
Returns current page containing selected record, loading records if needed.Returns Strategy object used to retrieve page by their record primary keys.Returns Strategy object used to retrieve page by their indices.Returns Transfer Object Assembler for adding record extensions needed for requested page that is not loaded by a base record list finder.int
Returns number of current page, starting at 1, containing selected record.int
Returns how pages are retrieved.getRange
(int startIndex, int endIndex) Returns range of records from cached list, loading them if needed.boolean
Indicates if record list must be reloaded.boolean
Indicates if record list must be sorted.Returns selected item from list.int
Returns index of currently selected item, starting at 0, in list.int
protected void
void
Marks record list as requiring a reload.void
Marks record list as requiring a re-sort.protected void
Notification of change.remove
(int index) Removes item from list at index position and returns it.void
removeListCacheListener
(ListCacheListener<T> listener) Removes currently, selected item from list and returns it.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.void
setBaseRecordListFinder
(ListFinder<M, T> baseRecordListFinder) Sets base record list finder, marks list for reload, and sets base record list pagination mode..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.void
setIdListFinder
(IdListFinder<M, K> idListFinder) Sets Strategy used to retrieve ids, sets page by ids pagination mode and marks list for reload.void
setItemFinder
(SingleItemFinder<K, T> value) Sets Strategy for retrieving single item of list, including details.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.void
setKeyExtractor
(KeyExtractor<K, T> keyExtractor) Sets Strategy that extracts the primary key from a record.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.void
setListFinder
(ListFinder<M, T> listFinder) Sets full list Strategy to retrieve list when needed and sets full list pagination mode.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.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.void
setPageByIdsFinder
(PageByIdsFinder<K, T> value) Sets Strategy used to retrieve page by their record ids.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.void
setPageNo
(int pageNo) Sets index of currently selected item to be first item of page where pageNo starts at one.void
setPageSize
(int pageSize) void
setSelected
(T value) Replaces selected item in list.void
setSelectedIndex
(int index) Sets currently selected item in list by index.
-
Constructor Details
-
ListCache
Copy constructor.- Throws:
Exception
-
ListCache
- Parameters:
listCacheConfig
- Configuration supplied by template functions.
-
-
Method Details
-
markChanged
protected void markChanged() -
notifyChanged
protected void notifyChanged()Notification of change. This typically notifies the parent container. -
addListCacheListener
-
addItem
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
Reloads list using currently set list finder, id list finder, or list size finder.- Throws:
Exception
-
getBaseRecordListFinder
Returns Strategy object used to retrieve list. -
getHasDetails
public boolean getHasDetails()Returns whether records must lazy load additional data for detail pages. -
getIdListFinder
Returns Strategy used to retrieve list. -
getItemFinder
Returns Strategy used to retrieve single item of list, including any extensions, or null if not set. -
getItemSorter
Returns Strategy used to sort list, or null for no sorting. -
getKeyExtractor
Returns Strategy that extracts the primary key from a record. -
getList
Returns entire record list, loading it if needed.- Throws:
Exception
-
getListeners
Returns all listeners of any change to this. -
getListFinder
Returns Strategy object used to retrieve list. -
getListSize
Returns list size.- Throws:
Exception
-
getListSizeFinder
Returns Strategy object used to retrieve list size. -
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
-
getPage
Returns current page containing selected record, loading records if needed.- Throws:
Exception
-
getPageByIdsFinder
Returns Strategy object used to retrieve page by their record primary keys. -
getPageByIndexRangeFinder
Returns Strategy object used to retrieve page by their indices. -
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
Returns number of current page, starting at 1, containing selected record.- Throws:
Exception
-
getPageSize
- Throws:
Exception
-
getPaginationMode
Returns how pages are retrieved. -
getRange
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
Returns selected item from list.- Throws:
Exception
-
getSelectedIndex
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
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
-
removeSelected
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
Caches list already loaded, sets base record list finder Strategy used to load it, and sets base record list pagination mode. -
setBaseRecordListFinder
Sets base record list finder, marks list for reload, and sets base record list pagination mode.. -
setIdListAndFinder
Caches id list already loaded, sets id list finder Strategy used to load it, and sets page by ids pagination mode. -
setIdListFinder
Sets Strategy used to retrieve ids, sets page by ids pagination mode and marks list for reload. -
setItemFinder
Sets Strategy for retrieving single item of list, including details. -
setItemSorter
Sets Strategy for sorting list data, overriding the list order of a list finder, or null to preserve list order. -
setKeyExtractor
Sets Strategy that extracts the primary key from a record. -
setListAndFinder
Caches list already loaded, sets full list Strategy used to load it, and sets full list pagination mode. -
setListFinder
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
Sets Strategy used to retrieve page by their record ids. -
setPageExtensionAssembler
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
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.
-