protected Processor switchRowProcessor()

in src/main/java/com/univocity/parsers/common/processor/core/AbstractInputValueSwitch.java [229:263]


	protected Processor<T> switchRowProcessor(String[] row, T context) {
		if (columnIndex == -1) {
			String[] headers = context.headers();
			if (headers == null) {
				throw new DataProcessingException("Unable to determine position of column named '" + columnName + "' as no headers have been defined nor extracted from the input");
			}
			columnIndex = ArgumentUtils.indexOf(headers, columnName);
			if (columnIndex == -1) {
				throw new DataProcessingException("Unable to determine position of column named '" + columnName + "' as it does not exist in the headers. Available headers are " + Arrays.toString(headers));
			}
		}

		if (columnIndex < row.length) {
			String valueToMatch = row[columnIndex];

			for (int i = 0; i < switches.length; i++) {
				Switch s = switches[i];
				if (s.matcher != null && s.matcher.matches(valueToMatch)) {
					return s.processor;
				} else if (comparator.compare(valueToMatch, s.value) == 0) {
					headers = s.headers;
					indexes = s.indexes;
					return s.processor;
				}
			}
		}
		if (defaultSwitch != null) {
			headers = defaultSwitch.headers;
			indexes = defaultSwitch.indexes;
			return defaultSwitch.processor;
		}
		headers = null;
		indexes = null;
		throw new DataProcessingException("Unable to process input row. No switches activated and no default switch defined.", columnIndex, row, null);
	}