Class Sort


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

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

      Constructors 
      Constructor Description
      Sort()  
    • Constructor Detail

      • Sort

        public Sort()
    • Method Detail

      • 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.