Class EntityLists

java.lang.Object
ch.tocco.nice2.persist.core.api.entity.EntityLists

public final class EntityLists extends Object
This class consists exclusively of static methods that operate on or return entity lists (think java.util.Collections).
  • Method Details

    • filteredList

      @Deprecated public static EntityList filteredList(EntityList entityList, EntityList.Filter filter)
      Deprecated.
      use EntityList.stream() and Stream.filter(Predicate) or create new query
      Wraps 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 public static EntityList orderedList(EntityList entityList, PrimaryKey[] sortByKeys)
      Deprecated.
      order in query
      Returns 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

      public static EntityList joinedList(EntityList... entityLists)
      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

      public static EntityList joinedList(List<EntityList> entityLists)
    • joinedList

      public static EntityList joinedList(boolean allowDuplicate, EntityList... entityLists)
    • asList

      public static EntityList asList(Entity... entities)
      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

      public static EntityList emptyList(EntityManager entityManager)
      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 public static <T> List<T> transform(EntityList entityList, Function<Entity,T> function)
      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 transform
      function - 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 list
      fieldName - 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.