boolean (StringBuilder sb, List<SortableEntry> entries) { int entryIndex = 0; int lines = myEntryCountOnLines.size(); int currentEntryIndex = 0; int entryCount = entries.size(); boolean eolRequired = false; for (int rowIndex = 0; rowIndex < lines; rowIndex++) { int entryCountOnRow = myEntryCountOnLines.getInt(rowIndex); if (entryCountOnRow == 0) { sb.append("\n"); eolRequired = false; continue; } for (int rowPosition = 0; rowPosition < entryCountOnRow; rowPosition++) { currentEntryIndex++; boolean isLastInRow = rowPosition + 1 == entryCountOnRow && rowIndex + 1 != lines; boolean isLastInList = currentEntryIndex == entryCount; eolRequired = entries.get(entryIndex).generate(sb, isLastInList); if (!isLastInList && (isLastInRow || eolRequired)) { sb.append("\n"); eolRequired = false; } entryIndex++; } } return eolRequired; }