add a new method

I add a method for manipulation individual fields.
This commit is contained in:
Christian Bender 2017-12-16 15:44:33 +01:00 committed by GitHub
parent bd45b3b891
commit 140b8e852f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 1 deletions

View File

@ -29,6 +29,9 @@
* adds a row to the inner data structure.
* without writing into the CSV-file.
*
* set (row : int, column : int, item : string) : void
* replaces the specified item with a newer.
*
* commit() : void
* writes the added data into CSV-file.
*
@ -711,4 +714,24 @@ public class CSVFile {
return table.size();
}
/**
*
* @param row
* @param column
* @param item
* @purpose replaces the specified item with a newer.
*/
public void set(int row, int column, String item) {
if (row < table.size()) {
if (column < table.get(row).size()) {
table.get(row).set(column, item);
} else {
throw new RuntimeException("set: column is too large!");
}
} else {
throw new RuntimeException("set: row is too large!");
}
}
}

View File

@ -121,5 +121,13 @@ public class TestCSVFile {
// test successful
}
@Test
public void testSet() {
// CSVFile testObj = new CSVFile("testData4.csv",',');
// testObj.set(6, 2, "80");
// testObj.updateFile();
// test succesfull
}
}

View File

@ -4,4 +4,4 @@
4,68.2166,142.3354
5,67.78781,144.2971
7,69.80204,141.4947
8,70.01472,136.4623
8,70.01472,80

1 1 65.78331 112.9925
4 4 68.2166 142.3354
5 5 67.78781 144.2971
6 7 69.80204 141.4947
7 8 70.01472 136.4623 80