Package org.eclipse.emfforms.common
Class RankingHelper<T>
- java.lang.Object
-
- org.eclipse.emfforms.common.RankingHelper<T>
-
- Type Parameters:
T- the type for the rank comparison
public class RankingHelper<T> extends java.lang.ObjectRanking 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 interfaceRankingHelper.RankTester<T>Helper callback interface for rank testing.
-
Field Summary
Fields Modifier and Type Field Description static doubleDEFAULT_INITIAL_RANKValue 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.StringcreateWarning(java.util.List<T> highestRankingElements, double rank)Create warning about clashing priorities.TgetHighestRankingElement(java.util.Collection<T> elements, RankingHelper.RankTester<T> rankTester)Determine the highest ranking element by iterating over all elements and calling rankTester.getRank().protected voidreportClashingPriorities(java.lang.String warningMessage)Report clashing priorities using ReportService.
-
-
-
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 purposesinitialRank- 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 purposesinitialRank- 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 considerrankTester- 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 elementsrank- 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
-
-