Use bitCount
@@ -307,7 +307,7 @@ public class SpareCapacityMaintainer extends NodeRepositoryMaintainer {
// find next
while (++i < 1<<nodes.size()) {
- int ones = onesIn(i);
+ int ones = Integer.bitCount(i);
if (ones > maxLength) continue;
next = new ArrayList<>(ones);
@@ -332,15 +332,6 @@ public class SpareCapacityMaintainer extends NodeRepositoryMaintainer {
return (number & (1 << position)) > 0;
}
- private int onesIn(int number) {
- int ones = 0;
- for (int position = 0; Math.pow(2, position) <= number; position++) {
- if (hasOneAtPosition(position, number))
- ones++;
- }
- return ones;
- }
-
}
}
