private boolean tryConsumeToken(char token) { if (content.hasNext() && content.peek() == token) { // consume the comma content.next(); return true; } return false; }
private boolean entryComplete() { if (!content.hasNext()) { return true; } char c = content.peek(); return (c == ';' || c == ','); }
void build() { int[] temp = new int[MAX_ENTRY_VALUES]; ArrayList<Entry> entries = new ArrayList<Entry>(); while (content.hasNext()) { // ';' denotes a new line. if (tryConsumeToken(';')) { // The line is complete, store the result for the line, // null if the line is empty. ArrayList<Entry> result; if (entries.size() > 0) { result = entries; // A new array list for the next line. entries = new ArrayList<Entry>(); } else { result = null; } lines.add(result); entries.clear(); line++; previousCol = 0; } else { // grab the next entry for the current line. int entryValues = 0; while (!entryComplete()) { temp[entryValues] = nextValue(); entryValues++; } Entry entry = decodeEntry(temp, entryValues); validateEntry(entry); entries.add(entry); // Consume the separating token, if there is one. tryConsumeToken(','); } } }