Package helper

Class Helper

java.lang.Object
helper.Helper

public class Helper extends Object
Contains general helper methods useful in some parts of the code.
  • Constructor Details

    • Helper

      public Helper()
  • Method Details

    • toJSStringList

      public static String toJSStringList(Collection<String> collection)
      Converts a collection of Strings to a JS/HTML-valid list of strings.
      Parameters:
      collection - A collection of strings.
      Returns:
      A string, compatible with HTML/JS, representing the original collection.
    • map

      public static <T, R> Set<R> map(Collection<T> collection, Function<? super T,? extends R> mapper)
      Maps a collection to a set using a specified mapping function.
      Type Parameters:
      T - The type of the original elements in the collection.
      R - The target type of the elements to include in the set.
      Parameters:
      collection - Any set of elements of type T.
      mapper - a non-interfering, stateless function to apply to each element.
      Returns:
      A new set given by applying the specified mapper function to the elements of the set.
    • mapSorted

      public static <T, R> SortedSet<R> mapSorted(Collection<T> collection, Function<? super T,? extends R> mapper, Comparator<R> comparator)
      Maps a collection to a sorted set using a specified mapping function.
      Type Parameters:
      T - The type of the original elements in the collection.
      R - The target type of the elements to include in the sorted set.
      Parameters:
      collection - Any set of elements of type T.
      mapper - a non-interfering, stateless function to apply to each element.
      comparator - A comparator of elements of type R.
      Returns:
      A sorted set containing the sorted, unique elements of the original collection.
    • collectionToSortedSet

      public static <T> SortedSet<T> collectionToSortedSet(Collection<T> collection, Comparator<T> comparator)
      Converts a collection of elements to a sorted set.
      Type Parameters:
      T - The type of the parameters in the collection.
      Parameters:
      collection - The original, not necessarily sorted, collection.
      comparator - The comparator used to sort the elements in the collection.
      Returns:
      A SortedSet containing the sorted, unique elements in the original collection.
    • getFieldValue

      public static <T> T getFieldValue(Field field, Object obj, Class<T> type)
      Gets the value of a given field on an instance of the defining objects, and casts it to a specified type.
      Type Parameters:
      T - A generic type.
      Parameters:
      field - The field
      obj - The object defining the field. Null, for static fields.
      type - The class to cast the value of the field to.
      Returns:
      The value of the given field, on the defining object, cast to type T.