import java.util.ArrayList; import java.util.List; public class Calculations { // TODO: What's a better name for this method (e.g. not "calculate")? Rename it to a better name. public static int calculate(int a, int b) { if(a > b) { return a; } else { return b; } } public static List selectEvenNumbers(List numbers) { List result = new ArrayList(); for (Integer number : numbers) { if (number % 2 == 0) { // TODO: extract a boolean method here to check if the number is even result.add(number); } } return result; } public static List squares(List numbers) { List result = new ArrayList(); for (Integer number : numbers) { result.add(number * number); } return result; } public static String wikiTable(List wikiLines) { // TODO: the method is a bit too long; maybe extract wiki syntax parsing (splitting of lines) into a separate method? // TODO: also, consider making separate methods for e.g. creating everything between and , and the same with the 2 lines that create the elements? // TODO: this method has nothing to do with Calculations -- move it to another class; the same for its tests String result = "\n"; for (String wikiLine : wikiLines) { result += " \n"; String[] parts = wikiLine.split("\\|"); // TODO: "parts" is ambiguous (what parts?). Maybe rename it to "cells"? for (String part : parts) { // TODO: what would be a better name for "part"? if(!part.isEmpty()) { String cellContents = part.trim(); result += " \n"; } } result += " \n"; } result += "
" + cellContents + "
"; return result; // TODO: After all these refactorings, what do you think: does the code here look more understandable now? } public static List squaresOfEvenNumbers(List numbers) { // TODO: this method duplicates some code with 2 other methods: selectEvenNumbers() and the squares() method. List result = new ArrayList(); for (Integer number : numbers) { if (number % 2 == 0) { result.add(number * number); } } return result; } }