类 Comparators

java.lang.Object
net.apexes.commons.lang.Comparators

public class Comparators extends Object
作者:
HeDYn
  • 构造器详细资料

    • Comparators

      public Comparators()
  • 方法详细资料

    • versionCompare

      public static int versionCompare(String version1, String version2)
      比较 version1 和 version2,如果 version1 小于、等于、大于 version2 分别返回 -1、0、1
      参数:
      version1 - 版本号1
      version2 - 版本号2
      返回:
      如果 version1 小于、等于、大于 version2 分别返回 -1、0、1
    • orderBy

      public static <E, R> Comparators.ComparatorHelper<E> orderBy(Comparators.ObjectGetter<E,R> getter, Comparator<R> comparator)
      添加参与对比的属性
      参数:
      getter - 获取属性值的方法
      comparator - 用于给属性做对比
      返回:
      返回 Comparators.ComparatorHelper 对象
    • orderBy

      public static <E> Comparators.ComparatorHelper<E> orderBy(Comparators.Getter<E> getter)
      参与对比的属性
      参数:
      getter - 获取要排序的属性值的方法
      返回:
      返回 Comparators.ComparatorHelper 对象
    • orderBy

      public static <E> Comparators.ComparatorHelper<E> orderBy(Comparators.Getter<E> getter, boolean asc)
      参与对比的属性
      参数:
      getter - 获取要排序的属性值的方法
      asc - 为true使用升序,为false使用降序
      返回:
      返回 Comparators.ComparatorHelper 对象
    • ascBy

      public static <E> Comparators.ComparatorHelper<E> ascBy(Comparators.Getter<E> getter)
      参与对比的属性
      参数:
      getter - 获取要排序的属性值的方法
      返回:
      返回 Comparators.ComparatorHelper 对象
    • descBy

      public static <E> Comparators.ComparatorHelper<E> descBy(Comparators.Getter<E> getter)
      参与对比的属性
      参数:
      getter - 获取要排序的属性值的方法
      返回:
      返回 Comparators.ComparatorHelper 对象
    • sort

      public static <E> void sort(List<E> list, Comparators.Getter<E> getter)
      对列表进行升序排序,为null的排在前面
      参数:
      list - 要排序的列表
      getter - 获取要排序的值的方法
    • sort

      public static <E> void sort(List<E> list, Comparators.Getter<E> getter, boolean asc)
      对列表进行排序,为null的排在前面
      参数:
      list - 要排序的列表
      getter - 获取要排序的值的方法
      asc - 为true使用升序,为false使用降序
    • sortNullLast

      public static <E> void sortNullLast(List<E> list, Comparators.Getter<E> getter)
      对列表进行排序,为null排在后面
      参数:
      list - 要排序的列表
      getter - 获取要排序的值的方法
    • sortNullLast

      public static <E> void sortNullLast(List<E> list, Comparators.Getter<E> getter, boolean asc)
      对列表进行排序,为null排在后面
      参数:
      list - 要排序的列表
      getter - 获取要排序的值的方法
      asc - 为true使用升序,为false使用降序
    • ascSort

      public static <E> void ascSort(List<E> list, Comparators.Getter<E> getter)
      对列表进行升序排序,为null排在前面
      参数:
      list - 要排序的列表
      getter - 获取要排序的值的方法
    • descSort

      public static <E> void descSort(List<E> list, Comparators.Getter<E> getter)
      对列表进行降序排序,为null排在前面
      参数:
      list - 要排序的列表
      getter - 获取要排序的值的方法
    • ascSortNullLast

      public static <E> void ascSortNullLast(List<E> list, Comparators.Getter<E> getter)
      对列表进行升序排序,为null排在后面
      参数:
      list - 要排序的列表
      getter - 获取要排序的值的方法
    • descSortNullLast

      public static <E> void descSortNullLast(List<E> list, Comparators.Getter<E> getter)
      对列表进行降序排序,为null排在后面
      参数:
      list - 要排序的列表
      getter - 获取要排序的值的方法
    • compare

      public static <E extends Comparable<E>> int compare(E o1, E o2)
      对比两个值,空值排在前面
      参数:
      o1 - 值1
      o2 - 值2
      返回:
      非空的值1 小于、等于、大于 非空的值2 时分别返回 -1、0、1
    • nullFirstCompare

      public static <E extends Comparable<E>> int nullFirstCompare(E o1, E o2)
      对比两个值,空值排在前面
      参数:
      o1 - 值1
      o2 - 值2
      返回:
      非空的值1 小于、等于、大于 非空的值2 时分别返回 -1、0、1
    • nullLastCompare

      public static <E extends Comparable<E>> int nullLastCompare(E o1, E o2)
      对比两个值,空值排在后面
      参数:
      o1 - 值1
      o2 - 值2
      返回:
      非空的值1 小于、等于、大于 非空的值2 时分别返回 -1、0、1
    • nullFirstComparator

      public static <E> Comparator<E> nullFirstComparator(Comparator<E> comparator)
      包装一个 null 值排在前面的 Comparator 对象
      参数:
      comparator - 原 Comparator 对象
      返回:
      返回一个 null 值排在前面的 Comparator 对象
    • nullLastComparator

      public static <E> Comparator<E> nullLastComparator(Comparator<E> comparator)
      包装一个 null 值排在后面的 Comparator 对象
      参数:
      comparator - 原 Comparator 对象
      返回:
      返回一个 null 值排在后面的 Comparator 对象
    • nullableComparator

      public static <E> Comparator<E> nullableComparator(Comparator<E> comparator, boolean nullLast)
      包装一个支持 null 的 Comparator 对象
      参数:
      comparator - 原 Comparator 对象
      nullLast - 为 true 时 null 排在后面,否则 null 排在前面
      返回:
      返回一个 null 值排在后面的 Comparator 对象