Source:
<code>private Optional<AssignableNode> getNodeWithHighestPoints(AssignableReplica replica, List<AssignableNode> assignableNodes, ClusterContext clusterContext, Set<String> busyInstances, OptimalAssignment optimalAssignment) { Map<AssignableNode, List<HardConstraint>> hardConstraintFailures = new ConcurrentHashMap<>(); List<AssignableNode> candidateNodes = assignableNodes.parallelStream().filter(candidateNode -> { boolean isValid = true; for (HardConstraint hardConstraint : _hardConstraints) { if (!hardConstraint.isAssignmentValid(candidateNode, replica, clusterContext)) { hardConstraintFailures.computeIfAbsent(candidateNode, node -> new ArrayList<>()) .add(hardConstraint); isValid = false; } } return isValid; }).collect(Collectors.toList()); if (candidateNodes.isEmpty()) { optimalAssignment.recordAssignmentFailure(replica, Maps.transformValues(hardConstraintFailures, this::convertFailureReasons)); return Optional.empty(); } return candidateNodes.parallelStream().map(node -> new HashMap.SimpleEntry<>(node, getAssignmentNormalizedScore(node, replica, clusterContext))) .max((nodeEntry1, nodeEntry2) -> { int scoreCompareResult = nodeEntry1.getValue().compareTo(nodeEntry2.getValue()); if (scoreCompareResult == 0) { String instanceName1 = nodeEntry1.getKey().getInstanceName(); String instanceName2 = nodeEntry2.getKey().getInstanceName(); int idleScore1 = busyInstances.contains(instanceName1) ? 0 : 1; int idleScore2 = busyInstances.contains(instanceName2) ? 0 : 1; <START> return idleScore1 != idleScore2 ? idleScore1 - idleScore2 <END> : - instanceName1.compareTo(instanceName2); } else { return scoreCompareResult; } }).map(Map.Entry::getKey); }</code><technical_language>nit, adding parenthesis calculation is cleaner safer</technical_language>

Target:
private Optional<AssignableNode> getNodeWithHighestPoints(AssignableReplica replica, List<AssignableNode> assignableNodes, ClusterContext clusterContext, Set<String> busyInstances, OptimalAssignment optimalAssignment) { Map<AssignableNode, List<HardConstraint>> hardConstraintFailures = new ConcurrentHashMap<>(); List<AssignableNode> candidateNodes = assignableNodes.parallelStream().filter(candidateNode -> { boolean isValid = true; for (HardConstraint hardConstraint : _hardConstraints) { if (!hardConstraint.isAssignmentValid(candidateNode, replica, clusterContext)) { hardConstraintFailures.computeIfAbsent(candidateNode, node -> new ArrayList<>()) .add(hardConstraint); isValid = false; } } return isValid; }).collect(Collectors.toList()); if (candidateNodes.isEmpty()) { optimalAssignment.recordAssignmentFailure(replica, Maps.transformValues(hardConstraintFailures, this::convertFailureReasons)); return Optional.empty(); } return candidateNodes.parallelStream().map(node -> new HashMap.SimpleEntry<>(node, getAssignmentNormalizedScore(node, replica, clusterContext))) .max((nodeEntry1, nodeEntry2) -> { int scoreCompareResult = nodeEntry1.getValue().compareTo(nodeEntry2.getValue()); if (scoreCompareResult == 0) { String instanceName1 = nodeEntry1.getKey().getInstanceName(); String instanceName2 = nodeEntry2.getKey().getInstanceName(); int idleScore1 = busyInstances.contains(instanceName1) ? 0 : 1; int idleScore2 = busyInstances.contains(instanceName2) ? 0 : 1; return idleScore1 != idleScore2 ? (idleScore1 - idleScore2) : - instanceName1.compareTo(instanceName2); } else { return scoreCompareResult; } }).map(Map.Entry::getKey); }