Friday, 15 May 2015

java - Convert a text file tree-structured content into a relationship flat dataset -



java - Convert a text file tree-structured content into a relationship flat dataset -

given text file contents following:

a. product type [a0001] mutual funds [a0002] open funded closed funds [a1313] money funds [a1317] index tracking [a1318] equity tracking[a1319] sector tracking [a1320] region-specific funds [a1325] country-specific funds [a1314] republic of austria [a1315] commonwealth of australia [a1323] xxxxx xxxxx] cxxxxxx [a1321] xxxxxxxx [a1324] xxxxxxxxx [a1306] xxxxx [a1308] xxxxx [a1307] xxxxxxx [a1309] xxxxxx [a1311] xxxxxx [a1310] xxxxxxx [a1312] xxxxxxxxxxx [a1299] xxxxxxxx [a1300] xxxxxxx [a1301] xxxxxxxxxx [a1329] xxxxxxxxxx [a1326] xxxxxxx [a1327] xxxxxxxxxx [a1328] xxxxxxxxxxxxx [a1302] xxxxxxxxxxx [a1303] xxxxxxxxxx [a1304] xxxxxxx [a0323] xxxxxxxxxx [a0351] xxxxxxx [a0362] xxxxxxx [a0363] xxxxxxxx [a0364] xxxxxxx [a0365]

what recommended method convert each line of text like:

product type [a0001] > mutual funds [a0002] > closed funds [a1313] > money funds [a1317] > index tracking [a1318] product type [a0001] > mutual funds [a0002] > closed funds [a1313] > money funds [a1317] > equity tracking[a1319] product type [a0001] > mutual funds [a0002] > closed funds [a1313] > money funds [a1317] > sector tracking [a1320]

create pojo represent each entity in file. create class producttype, class fund , maybe class tracking (i not know domain, not know entities or mean).

then build parser parse text file pojos. validate unit tests (some string in, object construction out). in case, parse file line line , take file determine tabs/blanks @ origin of line.

when have object structure, traverse , generate ever like. e.g. utilize visitor pattern encapsulate generation of final text.

java parsing

No comments:

Post a Comment