Botre Posted April 20, 2015 Posted April 20, 2015 Beginners swag. public static int getMyTotalLevel(Script script) { int total = 0; for (Skill skill : Skill.values()) total += script.getSkills().getStatic(skill); return total; }
lare96 Posted April 27, 2015 Posted April 27, 2015 Could always use Streams introduced in Java 8 to make this a one liner. public static int getMyTotalLevel(Script script) { return Arrays.stream(Skill.values()).mapToInt(script.getSkills()::getStatic).sum(); }
Botre Posted April 27, 2015 Author Posted April 27, 2015 Could always use Streams introduced in Java 8 to make this a one liner. public static int getMyTotalLevel(Script script) { return Arrays.stream(Skill.values()).mapToInt(script.getSkills()::getStatic).sum(); } Not sure if it's worth it but sure.