Interface ComparableUsing<T>

  • All Superinterfaces:
    Comparable<T>

    public interface ComparableUsing<T>
    extends Comparable<T>
    Implement this Comparable extension to enable relational operators directly on your type. Normally you only need to implement Comparable#compareTo(T), the remaining method in this interface have default implementations suitable for most use-cases. However, if necessary you can override behavior for individual relational operators by overriding #compareToUsing(T,Operator).

    Note implementing this interface automatically overloads == and !=. The default behavior delegates to compareTo(), but you can easily change the behavior by overriding equalityMode(), see ComparableUsing.EqualityMode options.

    • Method Detail

      • compareToUsing

        default boolean compareToUsing​(T that,
                                       ComparableUsing.Operator op)
        Compare this to that using op.

        Calls to this method are generated for usage of >, >=, <, and <=. If equalityMode() returns CompareTo, calls to this method are also generated for == and !=.

        Normally you do not need to implement this method because it delegates to your type's #compareTo(T) implementation. However, you can override this default implementation to customize behavior.