javagroovyobject-model

What is the Grooviest way to model this data?


I am using Groovy to read from a CSV file which has the below fields:

  Code   Name        Class
  ---    -----       ----
  1701   Enterprise  Constitution      
  1864   Reliant     Miranda 

What is the best way to represent this data in Groovy?

I was thinking a HashMap where Code is the key and the value is a POGO with two fields (Name and Class). But is there a groovier way?


Solution

  • Using a plain Map with code as a key is ok enough. It depends on what you need to do exactly. If you need to transform this data into Map that's the way to go.

    However groovy is so elastic in data processing that you can also create a POGO and transform this CSV data into a list. It can be easily grouped by code or whatever you need.

    Also, maybe creating a POGO isn't necessary? In such case use code a a key to.. Map.