Java – Parsing and validation of a csv file

Architecturecouplingengineeringjavasingle-responsibility

I am trying to create a library where I need to validate and parse a file in a CSV-like format and then use this data to generate a Tree data structure.

At the moment I split the process into two steps:

  1. Validate the file and store its lines in a list (in the parsing package)
  2. Read the list plus a string array containing a subset of columns to generate the tree (in the hierarchy package)

I was thinking if the steps can be simplified as a single one, since I would only need to store data just once (and there would be better performance) and I would store less data because of the columns subset. But I am concerned that the single step would result in a merged package that has too many responsibilities: validation and tree preparation.

What would be the best option in terms of best practice of software architecture?

Best Answer

Do nothing, if you see no performance problems.

Otherwise make parser return Iterator instead of List, that way, you will only need enough memory to store a single line at cost of complicating parser's lifetime management.

Related Topic