I scratched my head a bit on this issue. I am basically trying to create a tree hierarchy from a CSV dataset. CSV data is optionally ordered. It somehow looks like this:
Header: Record1,Record2,Value1,Value2
Row: A,XX,22,33
Row: A,XX,777,888
Row: A,YY,33,11
Row: B,XX,12,0
Row: A,YY,13,23
Row: B,YY,44,98
I am trying to make grouping as flexible as possible. The simplest one for grouping will do this for Record1 and Record2 with the values Value1 and Value2 stored in Record2, so that we get the following result:
Record1
Record2
Value1 Value2
What will happen:
A
XX
22,33
777,888
YY
33,11
13,23
B
XX
12,0
YY
44,98
I keep my group settings in the list for the time being, and I don’t know if this impedes my thoughts. This list contains a hierarchy of groups, for example:
Record1 (SchemaGroup)
.column = Record1
.columns = null
.childGroups =
Record2 (SchemaGroup)
.column = Record1
.columns = Value1 (CSVColumnInformation), Value2 (CSVColumnInformation)
.childGroups = null
The code for this is as follows:
private class SchemaGroup {
private SchemaGroupType type = SchemaGroupType.StaticText;
private String text;
private CSVColumnInformation column = null;
private List<SchemaGroup> childGroups = new ArrayList<SchemaGroup>();
private List<CSVColumnInformation> columns = new ArrayList<CSVColumnInformation>();
}
private enum SchemaGroupType {
StaticText,
ColumnGroup
}
, , . CSV , -:
CSVParser csv = new CSVParser(content);
String[] line;
while((line = csv.readLine()) != null ) {
...
}
.
?