FIlling a Java Bean tree structure from a csv flat file

Posted by Clem on Stack Overflow See other posts from Stack Overflow or by Clem
Published on 2010-03-17T00:57:27Z Indexed on 2010/03/17 1:01 UTC
Read the original article Hit count: 406

Filed under:
|
|
|
|

Hi,

I'm currently trying to construct a list of bean classes in Java from a flat description file formatted in csv. Concretely :

Here is the structure of the csv file :

MES_ID;GRP_PARENT_ID;GRP_ID;ATTR_ID
M1    ;             ;G1    ;A1
M1    ;             ;G1    ;A2
M1    ;G1           ;G2    ;A3
M1    ;G1           ;G2    ;A4
M1    ;G2           ;G3    ;A5
M1    ;             ;G4    ;A6
M1    ;             ;G4    ;A7
M1    ;             ;G4    ;A8
M2    ;             ;G1    ;A1
M2    ;             ;G1    ;A2
M2    ;             ;G2    ;A3
M2    ;             ;G2    ;A4

It corresponds to the hierarchical data structure :

M1
---G1
------A1
------A2
------G2
---------A3
---------A4
---------G3
------------A5
------G4
---------A7
---------A8
M2
---G1
------A1
------A2
---G2
------A3
------A4

Remarks :

  • A message M can have an infinite number of groups G and attributes A

  • A group G can have an infinite number of attributes and an infinite number of under-groups each of them having under-groups too

That beeing said, I'm trying to read this flat csv decription to store it in this structure of beans :

Map<String, MBean> messages = new HashMap<String, Mbean>();

==

public class MBean {
   private String mes_id;
   private Map<String, GBean> groups;
}

public class GBean {
   private String grp_id;
   private Map<String, ABean> attributes;
   private Map<String, GBean> underGroups;
}

public class ABean {
   private String attr_id;
}

Reading the csv file sequentially is ok and I've been investigating how to use recursion to store the description data, but couldn't find a way.

Thanks in advance for any of your algorithmic ideas.

I hope it will put you in the mood of thinking about this ... I've to admit that I'm out of ideas :s

© Stack Overflow or respective owner

Related posts about java

Related posts about csv