mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-26 05:59:22 +08:00
add a new method
I add a method for manipulation individual fields.
This commit is contained in:
Binary file not shown.
Binary file not shown.
@ -29,6 +29,9 @@
|
|||||||
* adds a row to the inner data structure.
|
* adds a row to the inner data structure.
|
||||||
* without writing into the CSV-file.
|
* without writing into the CSV-file.
|
||||||
*
|
*
|
||||||
|
* set (row : int, column : int, item : string) : void
|
||||||
|
* replaces the specified item with a newer.
|
||||||
|
*
|
||||||
* commit() : void
|
* commit() : void
|
||||||
* writes the added data into CSV-file.
|
* writes the added data into CSV-file.
|
||||||
*
|
*
|
||||||
@ -711,4 +714,24 @@ public class CSVFile {
|
|||||||
return table.size();
|
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!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -121,5 +121,13 @@ public class TestCSVFile {
|
|||||||
// test successful
|
// test successful
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSet() {
|
||||||
|
// CSVFile testObj = new CSVFile("testData4.csv",',');
|
||||||
|
// testObj.set(6, 2, "80");
|
||||||
|
// testObj.updateFile();
|
||||||
|
// test succesfull
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,4 +4,4 @@
|
|||||||
4,68.2166,142.3354
|
4,68.2166,142.3354
|
||||||
5,67.78781,144.2971
|
5,67.78781,144.2971
|
||||||
7,69.80204,141.4947
|
7,69.80204,141.4947
|
||||||
8,70.01472,136.4623
|
8,70.01472,80
|
||||||
|
|
Reference in New Issue
Block a user