Class SpellLevelComparator

  • All Implemented Interfaces:
    java.util.Comparator<Spell>

    public class SpellLevelComparator
    extends java.lang.Object
    implements java.util.Comparator<Spell>
    A comparator imposing an ordering on Spell objects by comparing their levels.

    Note: this comparator imposes orderings that are inconsistent with equals.

    In order to overcome the inconsistency with equals this comparator allows the introduction of a sub-comparator which is applied in cases of equality. I.e. if the two compared spells have the same level and they would be regarded as equal by this comparator, instead of 0 the result of the sub-comparator's comparison is returned.

    • Constructor Summary

      Constructors 
      Constructor Description
      SpellLevelComparator​(java.util.Comparator<? super Spell> sameLevelSubComparator)
      Creates a new SpellLevelComparator object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compare​(Spell o1, Spell o2)
      Compares its two arguments for order according to their levels
      • 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 Detail

      • SpellLevelComparator

        public SpellLevelComparator​(java.util.Comparator<? super Spell> sameLevelSubComparator)
        Creates a new SpellLevelComparator object.
        Parameters:
        sameLevelSubComparator - if two spells with the same level are compared, this sub-comparator is applied if it is not null.
    • Method Detail

      • compare

        public int compare​(Spell o1,
                           Spell o2)
        Compares its two arguments for order according to their levels
        Specified by:
        compare in interface java.util.Comparator<Spell>
        Returns:
        the difference of o1's and o2's numerical level value. If they are equal and a sub-comparator was specified, the result that sub-comparator's comparison is returned.