/** * Returns the character with the highest associated number. * * @param map the map of characters and their numbers * @param defaultChar the default character to return in case the map is empty * * @return the character with the highest number associated. */ private char max(Map<Character, Integer> map, Map<Character, Integer> totals, char defaultChar) { return getChar(map, totals, defaultChar, false); }
/** * Increments the number associated with a character in a map by 1 * * @param map the map of characters and their numbers * @param symbol the character whose number should be increment */ private static void increment(Map<Character, Integer> map, char symbol) { increment(map, symbol, 1); }
increment(escape, prev); if (isSymbol(ch)) { //counts all symbols. Skips letters, digits and white spaces (except the tab character) allSymbols.add(ch); increment(symbols, ch); } else if ((ch == '\r' || ch == '\n' || ch == normalizedNewLine) && symbols.size() > 0) { //got a newline and collected some symbols? Good! afterNewLine = true; Map<Character, Integer> totals = calculateTotals(symbolsPerRow); increment(sums, symbol, Math.abs(previousCount - currentCount)); // we expect to always get 0 or close to 0 here, so the symbol occurs in all rows char delimiterMax = max(sums, totals, suggestedDelimiter); char delimiterMin = min(sums, totals, suggestedDelimiter); char quoteEscape = max(escape, totals, quote); apply(delimiter, quote, quoteEscape);
defaultChar = newChar; } else if (isSymbol(newChar)) { defaultChar = newChar;
/** * Returns the character with the lowest associated number. * * @param map the map of characters and their numbers * @param defaultChar the default character to return in case the map is empty * * @return the character with the lowest number associated. */ private char min(Map<Character, Integer> map, Map<Character, Integer> totals, char defaultChar) { return getChar(map, totals, defaultChar, true); }