If I have a class Project:
public class Project {
enum Status {
NEW, OPENED, STOPPED, PERPETUAL, CLOSED, CANCELLED
}
enum Priority {
CRITICAL, HIGH, MEDIUM, LOW, SOMEDAY
}
private String id;
private String title;
private Status status;
private Priority priority;
}
I want to implement several sorts on this. For example, String []keysById(), String []keysByStatus(), String[] keysByPriority(). ArrayList, or something else is fine, too.
Currently I have a HashMap:
public class ProjectHash extends HashMap<String, Project> {
public ProjectHash() {
super();
}
// I use add() (instead of put()) because the key is in the value.
public Project add(Project p) {
Project retVal = null;
if(this.containsKey(p.getId())) {
// We've got a problem. I don't know what to do yet: overwrite, or vomit.
// Overwrite for now.
}
retVal = super.put(p.getId(),p);
return(retVal);
}
}
I've cut out a lot of the error checking and fields, but hopefully I've left enough to make the point. This HashMap won't see many adds or sorts per day (12?).
I've been reading about Collections, Collectable, HashMap, TreeMap, Lists, ArrayLists, etc. until my brain melted. I can see about a dozen ways to implement this. Which could be right for me? It's Java 8 with no concern about going backwards.