Class SelectItemBuilder

java.lang.Object
io.goobi.viewer.faces.utils.SelectItemBuilder

public final class SelectItemBuilder extends Object
Tools to create SelectItem collections to use in jsf components.
Author:
Florian Alpers
  • Method Details

    • getAsAlphabeticallySortedMap

      public static <T> SortedMap<String,List<T>> getAsAlphabeticallySortedMap(List<T> items, Function<T,String> sortValueSupplier)
      Sorts the given list of items into buckets for each starting letter.
      Type Parameters:
      T -
      Parameters:
      items - List of items that should be sorted
      sortValueSupplier - Function mapping an item to the sting according to which it should be sorted
      Returns:
      Map with starting letters of sort values as keys
    • getAsSortedMap

      public static <T> SortedMap<String,List<T>> getAsSortedMap(List<T> items, Function<T,List<String>> sortValueSupplier, Function<String,String> keyGenerator)
      Sorts the given list of items into buckets for each values returned by the sortValueSupplier.
      Type Parameters:
      T -
      Parameters:
      items - List of items that should be sorted
      sortValueSupplier - Function mapping an item to the string according to which it should be sorted
      keyGenerator - Function that creates labels for the return values of the sortValueSupplier. These labels are used as the actual keys of the map
      Returns:
      Map with starting letters of sort values as keys
    • getAsGroupedSelectItems

      public static <T> List<SelectItem> getAsGroupedSelectItems(Map<String,List<T>> map, Function<T,Object> valueSupplier, Function<T,String> labelSupplier, Function<T,String> descriptionSupplier, Predicate<T> disabledPredicate)
      Creates a List of selectItems from the given map, grouped into OptGroups for each map key.
      Type Parameters:
      T -
      Parameters:
      map - Map of items to include in selectItems
      valueSupplier - function extracting the select value from an item
      labelSupplier - function extracting the display label from an item
      descriptionSupplier - function extracting the description from an item
      disabledPredicate - predicate determining whether an item is disabled
      Returns:
      List
    • createSelectItem

      public static <T> SelectItem createSelectItem(Function<T,Object> valueSupplier, Function<T,String> labelSupplier, Function<T,String> descriptionSupplier, T value, Predicate<T> disabledPredicate)
      Type Parameters:
      T -
      Parameters:
      valueSupplier - function extracting the select value from an item
      labelSupplier - function extracting the display label from an item
      descriptionSupplier - function extracting the description from an item
      value - the item to create a SelectItem for
      disabledPredicate - predicate determining whether the item is disabled
      Returns:
      SelectItem