mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
CE-1955 - Add rowNo to BulkLoadFileRow, set by FileToRowsInterface objects
This commit is contained in:
@ -36,6 +36,7 @@ public abstract class AbstractIteratorBasedFileToRows<E> implements FileToRowsIn
|
|||||||
private boolean useLast = false;
|
private boolean useLast = false;
|
||||||
private BulkLoadFileRow last;
|
private BulkLoadFileRow last;
|
||||||
|
|
||||||
|
int rowNo = 0;
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
@ -65,6 +66,7 @@ public abstract class AbstractIteratorBasedFileToRows<E> implements FileToRowsIn
|
|||||||
@Override
|
@Override
|
||||||
public BulkLoadFileRow next()
|
public BulkLoadFileRow next()
|
||||||
{
|
{
|
||||||
|
rowNo++;
|
||||||
if(iterator == null)
|
if(iterator == null)
|
||||||
{
|
{
|
||||||
throw new IllegalStateException("Object was not init'ed");
|
throw new IllegalStateException("Object was not init'ed");
|
||||||
@ -99,6 +101,7 @@ public abstract class AbstractIteratorBasedFileToRows<E> implements FileToRowsIn
|
|||||||
@Override
|
@Override
|
||||||
public void unNext()
|
public void unNext()
|
||||||
{
|
{
|
||||||
|
rowNo--;
|
||||||
useLast = true;
|
useLast = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,4 +125,15 @@ public abstract class AbstractIteratorBasedFileToRows<E> implements FileToRowsIn
|
|||||||
this.iterator = iterator;
|
this.iterator = iterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Getter for rowNo
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
@Override
|
||||||
|
public int getRowNo()
|
||||||
|
{
|
||||||
|
return rowNo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ public class CsvFileToRows extends AbstractIteratorBasedFileToRows<CSVRecord> im
|
|||||||
values[i++] = s;
|
values[i++] = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (new BulkLoadFileRow(values));
|
return (new BulkLoadFileRow(values, getRowNo()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,6 +66,12 @@ public interface FileToRowsInterface extends AutoCloseable, Iterator<BulkLoadFil
|
|||||||
void init(InputStream inputStream) throws QException;
|
void init(InputStream inputStream) throws QException;
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
**
|
||||||
|
***************************************************************************/
|
||||||
|
int getRowNo();
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
**
|
**
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
@ -116,7 +116,7 @@ public class XlsxFileToRows extends AbstractIteratorBasedFileToRows<org.dhatim.f
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new BulkLoadFileRow(values);
|
return new BulkLoadFileRow(values, getRowNo());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ import java.util.stream.Collectors;
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
public class BulkLoadFileRow implements Serializable
|
public class BulkLoadFileRow implements Serializable
|
||||||
{
|
{
|
||||||
|
private int rowNo;
|
||||||
private Serializable[] values;
|
private Serializable[] values;
|
||||||
|
|
||||||
|
|
||||||
@ -41,9 +42,10 @@ public class BulkLoadFileRow implements Serializable
|
|||||||
** Constructor
|
** Constructor
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
public BulkLoadFileRow(Serializable[] values)
|
public BulkLoadFileRow(Serializable[] values, int rowNo)
|
||||||
{
|
{
|
||||||
this.values = values;
|
this.values = values;
|
||||||
|
this.rowNo = rowNo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -150,8 +152,8 @@ public class BulkLoadFileRow implements Serializable
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
BulkLoadFileRow row = (BulkLoadFileRow) o;
|
BulkLoadFileRow that = (BulkLoadFileRow) o;
|
||||||
return Objects.deepEquals(values, row.values);
|
return rowNo == that.rowNo && Objects.deepEquals(values, that.values);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -162,6 +164,38 @@ public class BulkLoadFileRow implements Serializable
|
|||||||
@Override
|
@Override
|
||||||
public int hashCode()
|
public int hashCode()
|
||||||
{
|
{
|
||||||
return Arrays.hashCode(values);
|
return Objects.hash(rowNo, Arrays.hashCode(values));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Getter for rowNo
|
||||||
|
*******************************************************************************/
|
||||||
|
public int getRowNo()
|
||||||
|
{
|
||||||
|
return (this.rowNo);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Setter for rowNo
|
||||||
|
*******************************************************************************/
|
||||||
|
public void setRowNo(int rowNo)
|
||||||
|
{
|
||||||
|
this.rowNo = rowNo;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Fluent setter for rowNo
|
||||||
|
*******************************************************************************/
|
||||||
|
public BulkLoadFileRow withRowNo(int rowNo)
|
||||||
|
{
|
||||||
|
this.rowNo = rowNo;
|
||||||
|
return (this);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -52,8 +52,8 @@ class CsvFileToRowsTest extends BaseTest
|
|||||||
BulkLoadFileRow headerRow = fileToRowsInterface.next();
|
BulkLoadFileRow headerRow = fileToRowsInterface.next();
|
||||||
BulkLoadFileRow bodyRow = fileToRowsInterface.next();
|
BulkLoadFileRow bodyRow = fileToRowsInterface.next();
|
||||||
|
|
||||||
assertEquals(new BulkLoadFileRow(new String[] { "one", "two", "three" }), headerRow);
|
assertEquals(new BulkLoadFileRow(new String[] { "one", "two", "three" }, 1), headerRow);
|
||||||
assertEquals(new BulkLoadFileRow(new String[] { "1", "2", "3", "4" }), bodyRow);
|
assertEquals(new BulkLoadFileRow(new String[] { "1", "2", "3", "4" }, 2), bodyRow);
|
||||||
assertFalse(fileToRowsInterface.hasNext());
|
assertFalse(fileToRowsInterface.hasNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +81,6 @@ public class TestFileToRows extends AbstractIteratorBasedFileToRows<Serializable
|
|||||||
@Override
|
@Override
|
||||||
public BulkLoadFileRow makeRow(Serializable[] values)
|
public BulkLoadFileRow makeRow(Serializable[] values)
|
||||||
{
|
{
|
||||||
return (new BulkLoadFileRow(values));
|
return (new BulkLoadFileRow(values, getRowNo()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,8 +66,8 @@ class XlsxFileToRowsTest extends BaseTest
|
|||||||
BulkLoadFileRow headerRow = fileToRowsInterface.next();
|
BulkLoadFileRow headerRow = fileToRowsInterface.next();
|
||||||
BulkLoadFileRow bodyRow = fileToRowsInterface.next();
|
BulkLoadFileRow bodyRow = fileToRowsInterface.next();
|
||||||
|
|
||||||
assertEquals(new BulkLoadFileRow(new String[] {"Id", "First Name", "Last Name", "Birth Date"}), headerRow);
|
assertEquals(new BulkLoadFileRow(new String[] {"Id", "First Name", "Last Name", "Birth Date"}, 1), headerRow);
|
||||||
assertEquals(new BulkLoadFileRow(new Serializable[] {1, "Darin", "Jonson", LocalDateTime.of(1980, Month.JANUARY, 31, 0, 0)}), bodyRow);
|
assertEquals(new BulkLoadFileRow(new Serializable[] {1, "Darin", "Jonson", LocalDateTime.of(1980, Month.JANUARY, 31, 0, 0)}, 2), bodyRow);
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////
|
||||||
// make sure there's at least a limit (less than 20) to how many more rows there are //
|
// make sure there's at least a limit (less than 20) to how many more rows there are //
|
||||||
|
Reference in New Issue
Block a user