Class EntityLists
entity lists
(think java.util.Collections).-
Method Summary
Modifier and TypeMethodDescriptionstatic EntityList
Creates an EntityList of persistent entities of the same EntityModel.static EntityList
emptyList
(EntityManager entityManager) Returns an unmodifiable empty EntityList.static EntityList
filteredList
(EntityList entityList, EntityList.Filter filter) Deprecated.static <T> List
<T> getFieldValues
(EntityList entityList, String fieldName, Class<T> targetClass) Returns a list of field values from the underlying EntityList, order is preserved.static EntityList
joinedList
(boolean allowDuplicate, EntityList... entityLists) static EntityList
joinedList
(EntityList... entityLists) Merges the results of two or more entity lists into a new one.static EntityList
joinedList
(List<EntityList> entityLists) static EntityList
orderedList
(EntityList entityList, PrimaryKey[] sortByKeys) Deprecated.order in querystatic <T> List
<T> transform
(EntityList entityList, Function<Entity, T> function) Deprecated.
-
Method Details
-
filteredList
Deprecated.useEntityList.stream()
andStream.filter(Predicate)
or create new queryWraps the EntityList in a filtered list to possibly ignore elements.Example:
myEntityList = EntityLists.filteredList(myEntityList, new EntityList.Filter() { public boolean include(EntityList list, int index) { return list.get(index).getInt("someField") > 5; } });
- Parameters:
entityList
- The list to be wrapped.filter
- The filter to apply.- Returns:
- The wrapped list
-
orderedList
Deprecated.order in queryReturns a new EntityList where the entries are sorted by the given pk sequence.This is meant to be used after running a pk-based query. It may be that the actual EntityList result of a query contains fewer entries (in the case that a record does not exist or the user lacks permission). In that case that particular sort key is ignored. If on the other hand the EntityList contains entries with keys not present in the sort keys, they are moved to the end (in existing order).
- Parameters:
entityList
- The input list.sortByKeys
- The primary keys in the desired element order.- Returns:
- A new sorted list.
-
joinedList
Merges the results of two or more entity lists into a new one.The entries are appended in the order that their lists are passed. Duplicate keys are ignored, the first appearance counts.
- Parameters:
entityLists
- Must be of same entity type and from same Context, and contain at least one list.- Returns:
- The merged list.
- Throws:
IllegalArgumentException
- If one list comes from another EntityManager to avoid mixing pks of different origin. Also if the passed entityLists is empty.
-
joinedList
-
joinedList
-
asList
Creates an EntityList of persistent entities of the same EntityModel.- Parameters:
entities
- Must be of same EntityModel, and persistent (not conception).- Returns:
- new EntityList of given persistent entities.
- Throws:
IllegalArgumentException
- if one entity is of another EntityModel than the first, or if not at least one entity is passed, or if one is not persistent (has no key).
-
emptyList
Returns an unmodifiable empty EntityList.Impl notes: the EntityModel and EntityManager are required because the API offers them, and null is not permitted as return value. If you highly disagree and/or this renders the empty list unusable then refactor.
-
transform
Deprecated.Returns a list of results obtained by applying the function to each entity of entity list. The transformation is applied eagerly.- Type Parameters:
T
- generic type of the returned list- Parameters:
entityList
- an entity list to transformfunction
- a function to be applied to each entity of the list- Returns:
- a list containing the results of applying the function to the entity list
-
getFieldValues
public static <T> List<T> getFieldValues(EntityList entityList, String fieldName, Class<T> targetClass) Returns a list of field values from the underlying EntityList, order is preserved.- Type Parameters:
T
- generic type of the returned list- Parameters:
entityList
- an entity listfieldName
- the field to access (needs to be on the EntityModel of the underlying EntityList)targetClass
- the target class of the field values- Returns:
- a list containing the field values of all entities in the list.
-
EntityList.stream()
andStream.filter(Predicate)
or create new query