java.lang.Object
de.uplanet.lucy.server.auxiliaries.collections.Sort

@VelocityCallable("singleton") public final class Sort extends Object
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Comparators for java.lang.Strings.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Create a comparator for sorting, e.g.
    Get comparators for strings.
    <T extends Object & Comparable<? super T>>
    T
    max(Collection<? extends T> p_collection)
    Returns the minimum element of the given collection, according to the natural ordering of its elements.
    <T> T
    max(Collection<? extends T> p_collection, Comparator<? super T> p_comparator)
    Returns the minimum element of the given collection, according to the order induced by the specified comparator.
    <T extends Object & Comparable<? super T>>
    T
    min(Collection<? extends T> p_collection)
    Returns the minimum element of the given collection, according to the natural ordering of its elements.
    <T> T
    min(Collection<? extends T> p_collection, Comparator<? super T> p_comparator)
    Returns the minimum element of the given collection, according to the order induced by the specified comparator.
    List<?>
    reverse(List<?> p_list)
     
    <T extends Comparable<T>>
    List<T>
    sort(List<T> p_list)
    Sorts the specified list into ascending order, according to the natural ordering of its elements.
    <T> List<T>
    sort(List<T> p_list, Comparator<? super T> p_comparator)
    Sorts the specified list according to the order induced by the specified comparator.
    <K extends Comparable<K>, V>
    Map<K,V>
    sort(Map<K,V> p_map)
    Try to sort the given map according to the natural ordering of its keys.
    <K extends Comparable<K>, V>
    Map<K,V>
    sort(Map<K,V> p_map, Comparator<? super K> p_comparator)
    Try to sort the given map according to the natural ordering of its keys.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Sort

      public Sort()
  • Method Details

    • getString

      public Sort.StringComparators getString()
      Get comparators for strings.
      Returns:
      The comparators.
    • sort

      public <T extends Comparable<T>> List<T> sort(List<T> p_list)
      Sorts the specified list into ascending order, according to the natural ordering of its elements.
      Parameters:
      p_list - List of objects that should be sorted.
      Returns:
      The sorted list (same object as p_list).
    • sort

      public <T> List<T> sort(List<T> p_list, Comparator<? super T> p_comparator)
      Sorts the specified list according to the order induced by the specified comparator.
      Parameters:
      p_list - List of objects that should be sorted.
      p_comparator - The comparator to be used.
      Returns:
      The sorted list (same object as p_list).
    • reverse

      public List<?> reverse(List<?> p_list)
      Parameters:
      p_list - List of objects that should be reverted.
      Returns:
      The reverted list (same object as p_list).
    • min

      public <T extends Object & Comparable<? super T>> T min(Collection<? extends T> p_collection)
      Returns the minimum element of the given collection, according to the natural ordering of its elements.
      Parameters:
      p_collection - The collection.
      Returns:
      The minimum element.
    • min

      public <T> T min(Collection<? extends T> p_collection, Comparator<? super T> p_comparator)
      Returns the minimum element of the given collection, according to the order induced by the specified comparator.
      Parameters:
      p_collection - The collection.
      p_comparator - The comparator.
      Returns:
      The minimum element.
    • max

      public <T extends Object & Comparable<? super T>> T max(Collection<? extends T> p_collection)
      Returns the minimum element of the given collection, according to the natural ordering of its elements.
      Parameters:
      p_collection - The collection.
      Returns:
      The minimum element.
    • max

      public <T> T max(Collection<? extends T> p_collection, Comparator<? super T> p_comparator)
      Returns the minimum element of the given collection, according to the order induced by the specified comparator.
      Parameters:
      p_collection - The collection.
      p_comparator - The comparator.
      Returns:
      The minimum element.
    • sort

      public <K extends Comparable<K>, V> Map<K,V> sort(Map<K,V> p_map)
      Try to sort the given map according to the natural ordering of its keys. If sorting fails, e.g. due to incomparable keys, the given map is returned.
      Parameters:
      p_map - The map that should be sorted.
      Returns:
      The sorted map, or the original map if sorting was not possible. If the given map is null, then null will be returned.
    • sort

      public <K extends Comparable<K>, V> Map<K,V> sort(Map<K,V> p_map, Comparator<? super K> p_comparator)
      Try to sort the given map according to the natural ordering of its keys. If sorting fails, e.g. due to incomparable keys, the given map is returned.
      Parameters:
      p_map - The map that should be sorted.
      p_comparator - The comparator to be used.
      Returns:
      The sorted map, or the original map if sorting was not possible. If the given map is null, then null will be returned.
    • createComparator

      public Comparator<?> createComparator(String p_strClass)
      Parameters:
      p_strClass - The name of the comparator class, e.g. one of
      Returns:
      The requested comparator, or null if an error occurred.