Class BeanComparator<T>

java.lang.Object
rs.baselib.util.BeanComparator<T>
All Implemented Interfaces:
java.util.Comparator<T>

public class BeanComparator<T>
extends java.lang.Object
implements java.util.Comparator<T>
A comparator based on a list of bean properties. The comparison will be null-safe and exception-safe.
Author:
ralph
  • Constructor Summary

    Constructors 
    Constructor Description
    BeanComparator​(java.lang.String... beanProperties)
    Constructor.
    BeanComparator​(java.util.Comparator<java.lang.Object> comparator, java.lang.String... beanProperties)
    Constructor.
    BeanComparator​(java.util.Comparator<java.lang.Object> comparator, IValueProvider... valueProviders)
    Constructor.
    BeanComparator​(IValueProvider... valueProviders)
    Constructor.
  • Method Summary

    Modifier and Type Method Description
    int compare​(T o1, T o2)
    java.util.Comparator<java.lang.Object> getComparator()
    Returns the comparator used to compare the values.
    IValueProvider[] getValueProviders()
    Returns the value providers of this comparator.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.util.Comparator

    equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
  • Constructor Details

    • BeanComparator

      public BeanComparator​(java.lang.String... beanProperties)
      Constructor.
      Parameters:
      beanProperties - the properties in order of priority.
    • BeanComparator

      public BeanComparator​(java.util.Comparator<java.lang.Object> comparator, java.lang.String... beanProperties)
      Constructor.
      Parameters:
      comparator - the comparator to be used
      beanProperties - the properties in order of priority.
    • BeanComparator

      public BeanComparator​(IValueProvider... valueProviders)
      Constructor.
      Parameters:
      valueProviders - the value providers for each of the properties to be compared
    • BeanComparator

      public BeanComparator​(java.util.Comparator<java.lang.Object> comparator, IValueProvider... valueProviders)
      Constructor.
      Parameters:
      comparator - the comparator to be used
      valueProviders - the value providers for each of the properties to be compared
  • Method Details

    • getComparator

      public java.util.Comparator<java.lang.Object> getComparator()
      Returns the comparator used to compare the values.
      Returns:
      the comparator
    • getValueProviders

      public IValueProvider[] getValueProviders()
      Returns the value providers of this comparator.
      Returns:
      providers that will be used
    • compare

      public int compare​(T o1, T o2)
      Specified by:
      compare in interface java.util.Comparator<T>