1 /* 2 * CSVeed (https://github.com/42BV/CSVeed) 3 * 4 * Copyright 2013-2023 CSVeed. 5 * 6 * All rights reserved. This program and the accompanying materials 7 * are made available under the terms of The Apache Software License, 8 * Version 2.0 which accompanies this distribution, and is available at 9 * https://www.apache.org/licenses/LICENSE-2.0.txt 10 */ 11 package org.csveed.api; 12 13 import org.csveed.report.RowReport; 14 15 /** 16 * A Row is a line of content read from the CSV file. Note that a Row is never a Header. Rows can be iterated which 17 * yields the individual cells as Strings. 18 */ 19 public interface Row extends Iterable<String> { 20 21 /** 22 * The number of columns in the Row. 23 * 24 * @return number of columns 25 */ 26 int size(); 27 28 /** 29 * Gets the content of the cell on the basis of its cell position within the Row. Counting is 0-based. 30 * 31 * @param columnIndex 32 * the position of the cell within the Row 33 * 34 * @return the content of the cell 35 */ 36 String get(int columnIndex); 37 38 /** 39 * Gets the content of the cell in the column named columnName. This method depends on the availability of a Header, 40 * or will otherwise throw an exception 41 * 42 * @param columnName 43 * the cell of the Row in the same column as the header with name columnName 44 * 45 * @return the content of the cell 46 */ 47 String get(String columnName); 48 49 /** 50 * Gets the column name belonging to the cell. This method depends on the availability of a Header, or will 51 * otherwise throw an exception 52 * 53 * @param columnIndex 54 * the position of the header cell within the Header line 55 * 56 * @return the name of the column 57 */ 58 String getColumnName(int columnIndex); 59 60 /** 61 * Returns true if a Header has been set for this Row. 62 * 63 * @return true if Header has been found 64 */ 65 boolean hasHeader(); 66 67 /** 68 * Returns the Headers and throws an exception if it does not exist. Use hasHeader() if you want to prevent the 69 * throwing of an exception when a Header can lack 70 * 71 * @return the Header for the Row 72 */ 73 Header getHeader(); 74 75 /** 76 * Generates a report on the Row with focus on the end of the row. This is internally used when there is a syntax 77 * error in the line. It could also be used when there is an error that can not be traced back to a single cell. 78 * 79 * @return report on the row with focus on the end of the row 80 */ 81 RowReport reportOnEndOfLine(); 82 83 /** 84 * Generates a report on the Row with focus on a particular cell. The report can return lines for web consumption 85 * (assisting highlighting) or monospaced font printing with dual lines, the first holding the value of the line, 86 * the second showing where the error occurred. 87 * 88 * @param columnIndex 89 * the index of the column to focus the report on 90 * 91 * @return report on the row with focus on a particular cell 92 */ 93 RowReport reportOnColumn(int columnIndex); 94 95 }