I want to collect data which is classified in many groups. When I receive the first item of a group, I want to put a boolean as TRUE, to indicate there is some info into that group or not.
My first approach was writing a method to return that boolean for each group I want to check. But since I have 8 groups, I though about giving a different scope: I defined an ENUM, and created a Map having that ENUM as key and the boolean as the Value:
enum dataNames{TITLE, AUTHOR, SOURCE, ELEVATION, SPEED, SATELLITES, LATITUDE, LONGITUDE}; //etc
private Map<dataNames, Boolean> availableData;
And then I check the state of each boolean calling this method:
public boolean isDataAvailable (dataNames name){
return availableData.containsKey(name);
}
For example:
public void addElevationValue(double elevationValue){
if(!isDataAvailable(dataNames.ELEVATION)) availableData.put(dataNames.ELEVATION, true);
elevacion.add(elevationValue);
}
My question is: is this a good aproach, or should I stay with a method for each boolean I want to check? And… why? (I just want to learn)
Why do you need a map to tell you if data is available or not?
It looks like you are storing your data in a collection, so if this collection is empty, there is no data available.
For example: