Java Code Examples for org.supercsv.util.CsvContext#getRowNumber()
The following examples show how to use
org.supercsv.util.CsvContext#getRowNumber() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SuperCsvCellProcessorExceptionTest.java From super-csv with Apache License 2.0 | 6 votes |
/** * Tests the integrity of the CsvContext in a <code>SuperCsvCellProcessorException</code> */ @Test public void testCsvContext() { // This is my reference context. It is the control object to use as the reference for assertions CsvContext rc = new CsvContext(1, 2, 3); // line, row, col // This is the test context object to use for the test. It must have the same // values as the reference context. CsvContext tc = new CsvContext(rc.getLineNumber(), rc.getRowNumber(), rc.getColumnNumber()); SuperCsvCellProcessorException e = new SuperCsvCellProcessorException (String.class, 123, tc, PROCESSOR); // Pre-condition check assertEquals(rc, e.getCsvContext()); // Test steps tc.setColumnNumber(2*rc.getColumnNumber() + 50); // Set a column # that is different than the reference // Check that the exception still returns the context that it was created with assertEquals(rc, e.getCsvContext()); }
Example 2
Source File: SuperCsvRowException.java From super-csv-annotation with Apache License 2.0 | 6 votes |
private CsvContext cloneCsvContext(final CsvContext context) { CsvContext cloned = new CsvContext( context.getLineNumber(), context.getRowNumber(), context.getColumnNumber()); // shallow copy List<Object> destRowSource = new ArrayList<Object>(context.getRowSource().size()); for(Object obj : context.getRowSource()) { destRowSource.add(obj); } cloned.setRowSource(destRowSource); return cloned; }
Example 3
Source File: UniqueHashCode.java From super-csv-annotation with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public Object execute(final Object value, final CsvContext context) { if(value == null) { return next.execute(value, context); } final T result = (T)value; final int hashCode = value.hashCode(); if(encounteredElements.containsKey(hashCode)) { final ValueObject duplicatedObject = encounteredElements.get(result); throw createValidationException(context) .messageFormat("duplicate hashCode '%s' encountered.", hashCode) .rejectedValue(result) .messageVariables("hashCode", hashCode) .messageVariables("duplicatedRowNumber", duplicatedObject.rowNumber) .messageVariables("duplicatedLineNumber", duplicatedObject.lineNumber) .messageVariables("printer", getPrinter()) .build(); } else { final ValueObject object = new ValueObject(hashCode, context.getRowNumber(), context.getLineNumber()); encounteredElements.put(object.hashCode, object); } return next.execute(value, context); }
Example 4
Source File: Unique.java From super-csv-annotation with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public Object execute(final Object value, final CsvContext context) { if(value == null) { return next.execute(value, context); } final T result = (T)value; if(encounteredElements.containsKey(result)) { final String formattedValue = printer.print(result); final ValueObject duplicatedObject = encounteredElements.get(result); throw createValidationException(context) .messageFormat("duplicate value '%s' encountered.", formattedValue) .rejectedValue(result) .messageVariables("duplicatedLineNumber", duplicatedObject.lineNumber) .messageVariables("duplicatedRowNumber", duplicatedObject.rowNumber) .messageVariables("printer", getPrinter()) .build(); } else { final ValueObject object = new ValueObject(result, context.getLineNumber(), context.getRowNumber()); encounteredElements.put(object.value, object); } return next.execute(value, context); }