Class SingletonEntityList
java.lang.Object
ch.tocco.nice2.persist.core.api.util.SingletonEntityList
- All Implemented Interfaces:
EntityList
,Iterable<Entity>
-
Nested Class Summary
Nested classes/interfaces inherited from interface ch.tocco.nice2.persist.core.api.entity.EntityList
EntityList.Filter
-
Constructor Summary
ConstructorDescriptionSingletonEntityList
(Entity entity) SingletonEntityList
(Entity entity, EntityManager manager) -
Method Summary
Modifier and TypeMethodDescriptionboolean
contains
(PrimaryKey key) Determine, whether the list contains an entity with the specified key.expect
(int amount) Throws if the list does not contain exactly that amount.expectAtLeast
(int min) Throws if the list contains fewer than min items.expectAtMost
(int max) Throws if the list contains more than max items.get
(int index) Get the entity at the specified index with eager loading.get
(int index, boolean eager) Get the entity at the specified index.get
(PrimaryKey key) Get the entity with the specified key in that list with eager loading.get
(PrimaryKey key, boolean eager) Get the entity with the specified key in that list.getKey
(int index) Returns the PrimaryKey at the specified position.getKeys()
Read in subclasses if this array can contain null values or not.Get the entity manager.getModel()
Get the model of the entity type contained in this list.int
Get the number of pages in this list.int
Get the current page size.int
indexOf
(PrimaryKey key) Get the index within the list of the entity with the specified key.boolean
isEmpty()
Same as size() == 0iterator()
void
setPageSize
(int pageSize) Set the page size.int
size()
Get the number of entities this list contains.toList()
Returns the Entities of this list in a List using eager loading.Returns the Entities of this list in a List using eager loading.unwrap()
Unwrap to the underlying entity list.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface ch.tocco.nice2.persist.core.api.entity.EntityList
doWithSingleResult, doWithSingleResultOr, expectAtMostOrThrow, expectOr, expectOrThrow, getFirstEntity, getOnlyResult, getOptionalOnlyResult, getOptionalOnlyResult, requireFirstEntity, spliterator, stream
-
Constructor Details
-
SingletonEntityList
-
SingletonEntityList
-
-
Method Details
-
size
public int size()Description copied from interface:EntityList
Get the number of entities this list contains.- Specified by:
size
in interfaceEntityList
- Returns:
- The number of entities.
-
isEmpty
public boolean isEmpty()Description copied from interface:EntityList
Same as size() == 0- Specified by:
isEmpty
in interfaceEntityList
- Returns:
- If the list is empty.
-
getKeys
Description copied from interface:EntityList
Read in subclasses if this array can contain null values or not.- Specified by:
getKeys
in interfaceEntityList
- Returns:
- A defensive copy of the array. The size matches the
EntityList.size()
method.
-
get
Description copied from interface:EntityList
Get the entity at the specified index with eager loading.This method will load a full page if the entity is currently
hollow
.- Specified by:
get
in interfaceEntityList
- Parameters:
index
- The index.- Returns:
- The entity at the specified index potentially in
unusable state
, ornull
. - Throws:
PersistException
-
get
Description copied from interface:EntityList
Get the entity with the specified key in that list with eager loading.- Specified by:
get
in interfaceEntityList
- Returns:
- The entity potentially in
unusable state
, ornull
. - Throws:
PersistException
- See Also:
-
get
Description copied from interface:EntityList
Get the entity at the specified index.- Specified by:
get
in interfaceEntityList
- Parameters:
index
- The index.eager
-true
, if a page should be eagerly loaded, if the entity's state ishollow
, false otherwise.- Returns:
- The entity at the specified index potentially in
unusable state
, ornull
. - Throws:
PersistException
-
get
Description copied from interface:EntityList
Get the entity with the specified key in that list.- Specified by:
get
in interfaceEntityList
- Parameters:
key
- The key of the entity.eager
-true
, if a page should be eagerly loaded, if the entity's state ishollow
, false otherwise.- Returns:
- The entity with the specified key potentially in
unusable state
, ornull
. - Throws:
PersistException
-
toList
Description copied from interface:EntityList
Returns the Entities of this list in a List using eager loading.- Specified by:
toList
in interfaceEntityList
- Throws:
PersistException
-
toList
Description copied from interface:EntityList
Returns the Entities of this list in a List using eager loading.- Specified by:
toList
in interfaceEntityList
- Throws:
PersistException
-
getKey
Description copied from interface:EntityList
Returns the PrimaryKey at the specified position.- Specified by:
getKey
in interfaceEntityList
-
indexOf
Description copied from interface:EntityList
Get the index within the list of the entity with the specified key.- Specified by:
indexOf
in interfaceEntityList
- Parameters:
key
- The primary key.- Returns:
- The index or -1, if there's no such entity in the list.
-
contains
Description copied from interface:EntityList
Determine, whether the list contains an entity with the specified key.- Specified by:
contains
in interfaceEntityList
- Parameters:
key
- The primary key.- Returns:
true
, if there's an entity with the specified key,false
otherwise.
-
expect
Description copied from interface:EntityList
Throws if the list does not contain exactly that amount.Example:
EntityList entityList = myQuery.execute(1).expect(1);
- Specified by:
expect
in interfaceEntityList
- Parameters:
amount
- The expected amount.- Returns:
- The list itself.
- Throws:
PermanentPersistException
- See Also:
-
expectAtLeast
Description copied from interface:EntityList
Throws if the list contains fewer than min items.Example:
EntityList entityList = myQuery.execute().expectAtLeast(3);
- Specified by:
expectAtLeast
in interfaceEntityList
- Parameters:
min
- The expected minimal amount, including.- Returns:
- The list itself.
- Throws:
PermanentPersistException
- See Also:
-
expectAtMost
Description copied from interface:EntityList
Throws if the list contains more than max items.Example:
EntityList entityList = myQuery.execute(3).expectAtMost(3);
- Specified by:
expectAtMost
in interfaceEntityList
- Parameters:
max
- The expected maximal amount, including.- Returns:
- The list itself.
- Throws:
PermanentPersistException
- See Also:
-
getModel
Description copied from interface:EntityList
Get the model of the entity type contained in this list.- Specified by:
getModel
in interfaceEntityList
- Returns:
- The model of the entity type contained in this list.
-
getManager
Description copied from interface:EntityList
Get the entity manager.- Specified by:
getManager
in interfaceEntityList
- Returns:
- The entity manager.
-
unwrap
Description copied from interface:EntityList
Unwrap to the underlying entity list. Wrappers of entity lists should delegate this to the list they're wrapping, implementations returnthis
. It may be that they cannot, and then return themselves (MultiEntityList).- Specified by:
unwrap
in interfaceEntityList
- Returns:
- The underlying entity list implementation.
-
setPageSize
public void setPageSize(int pageSize) Description copied from interface:EntityList
Set the page size. The page size determines how many objects will be loaded, once ahollow
entity has been accessed.- Specified by:
setPageSize
in interfaceEntityList
- Parameters:
pageSize
- The new page size.
-
getPageSize
public int getPageSize()Description copied from interface:EntityList
Get the current page size.- Specified by:
getPageSize
in interfaceEntityList
- Returns:
- The current page size.
-
getPageCount
public int getPageCount()Description copied from interface:EntityList
Get the number of pages in this list.- Specified by:
getPageCount
in interfaceEntityList
- Returns:
- The number of pages in this list
(
size/pageSize + (size%pageSize>0 ? 1 : 0)
).
-
iterator
-