public static < S extends Solution < ? > > S getBestSolution ( S solution1 , S solution2 , Comparator < S > comparator , BinaryOperator < S > equalityPolicy ) { S result ; int flag = comparator . compare ( solution1 , solution2 ) ; if ( flag == - 1 ) { result = solution1 ; } else if ( flag == 1 ) { result = solution2 ; } else { result = equalityPolicy . apply ( solution1 , solution2 ) ; } return result ; }
Return the best solution between those passed as arguments . If they are equal or incomparable one of them is chosen based on the given policy .