int prioritySum = 0;
int countOfElements = roots.size();
int countOfLockedElements = 0; // lockedGoals.size();
for (Element element : roots) {
PrioritizedElement priorizedElement = priorizedElementMap
.get(element);
String priorityString = priorizedElement.getGlobalPriority();
if (priorityString != null) {
prioritySum += Integer.parseInt(priorityString);
}
if (isLocked(element)) {
countOfLockedElements++;
}
}
int countOfNotLockedElement = countOfElements - countOfLockedElements;
int notAssignedLocalPrioritysumOfNotLocked = 100 - prioritySum;
int diffForEachNotLockedElement = countOfNotLockedElement != 0 ? notAssignedLocalPrioritysumOfNotLocked
/ countOfNotLockedElement
: 0;
int modulo = countOfNotLockedElement != 0 ? notAssignedLocalPrioritysumOfNotLocked
% countOfNotLockedElement
: 0;
int i = 0;
if (notAssignedLocalPrioritysumOfNotLocked != 0) {
for (Element element : roots) {
if (!isLocked(element)) {
i++;
PrioritizedElement priorizedElement = priorizedElementMap
.get(element);
String oldPriorityString = priorizedElement
.getGlobalPriority();
int oldPriorityInt = oldPriorityString != null ? Integer
.parseInt(oldPriorityString) : 0;
int newPriorityInt = oldPriorityInt
+ diffForEachNotLockedElement;
if (modulo >= i)
newPriorityInt++;
String newPrioritySting = String.valueOf(newPriorityInt);
priorizedElement.setGlobalPriority(newPrioritySting);
}
}
}