Class RankingHelper<T>

  • Type Parameters:
    T - the type for the rank comparison

    public class RankingHelper<T>
    extends java.lang.Object
    Ranking helper class to generically handle prioritization use cases. This class assumes that priorities are in ascending order (higher rank means higher priority).
    Since:
    1.14
    Author:
    Mat Hansen
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  RankingHelper.RankTester<T>
      Helper callback interface for rank testing.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static double DEFAULT_INITIAL_RANK
      Value used to initialize the rank comparison in case no initialRank value is passed.
    • Constructor Summary

      Constructors 
      Constructor Description
      RankingHelper​(java.lang.Class<?> elementClass, double initialRank)
      Constructor which disables ignore rank feature.
      RankingHelper​(java.lang.Class<?> elementClass, double initialRank, java.lang.Double ignoreRankValue)
      The main constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.lang.String createWarning​(java.util.List<T> highestRankingElements, double rank)
      Create warning about clashing priorities.
      T getHighestRankingElement​(java.util.Collection<T> elements, RankingHelper.RankTester<T> rankTester)
      Determine the highest ranking element by iterating over all elements and calling rankTester.getRank().
      protected void reportClashingPriorities​(java.lang.String warningMessage)
      Report clashing priorities using ReportService.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_INITIAL_RANK

        public static final double DEFAULT_INITIAL_RANK
        Value used to initialize the rank comparison in case no initialRank value is passed.
        See Also:
        Constant Field Values
    • Constructor Detail

      • RankingHelper

        public RankingHelper​(java.lang.Class<?> elementClass,
                             double initialRank)
        Constructor which disables ignore rank feature.
        Parameters:
        elementClass - the class the prioritization is based on, required for logging purposes
        initialRank - the initialization value for the rank comparison (see INITIAL_RANK)
      • RankingHelper

        public RankingHelper​(java.lang.Class<?> elementClass,
                             double initialRank,
                             java.lang.Double ignoreRankValue)
        The main constructor.
        Parameters:
        elementClass - the class the prioritization is based on, required for logging purposes
        initialRank - the initialization value for the rank comparison (see INITIAL_RANK)
        ignoreRankValue - a specific value which will result in the given element being omitted. Must be non-null otherwise this feature is not enabled.
    • Method Detail

      • getHighestRankingElement

        public T getHighestRankingElement​(java.util.Collection<T> elements,
                                          RankingHelper.RankTester<T> rankTester)
        Determine the highest ranking element by iterating over all elements and calling rankTester.getRank().
        Parameters:
        elements - the elements to consider
        rankTester - the tester instance to fetch a rank/priority for a given element
        Returns:
        the highest ranking element found (may be null)
      • createWarning

        protected java.lang.String createWarning​(java.util.List<T> highestRankingElements,
                                                 double rank)
        Create warning about clashing priorities.
        Parameters:
        highestRankingElements - list of clashing elements
        rank - the rank of the elements
        Returns:
        the warning message
      • reportClashingPriorities

        protected void reportClashingPriorities​(java.lang.String warningMessage)
        Report clashing priorities using ReportService.
        Parameters:
        warningMessage - the warning message