I have the following map:
Map<Double, List<SoundEvent>> soundEventCells = new HashMap<Double, List<SoundEvent>>();
This HashMap
maps double
values (which are points in time) to the corresponding SoundEvent
'cell': each 'cell' can contain a number of SoundEvent
s. That's why it's implemented as a List<SoundEvent>
, because that's exactly what it is.
For the sake of better readability of the code, I thought about implementing a very simple static inner class like so:
private static class SoundEventCell {
private List<SoundEvent> soundEvents = new ArrayList<SoundEvent>();
public void addEvent(SoundEvent event){
soundEvents.add(event);
}
public int getSize(){
return soundEvents.size();
}
public SoundEvent getEvent(int index){
return soundEvents.get(index);
}
// .. remove() method unneeded
}
And than the map declaration (and a lot of other code) would look better, for example:
Map<Double, SoundEventCell> soundEventCells = new HashMap<Double, SoundEventCell>();
Is this overkill? Would you do this in your projects?
private static
because it's only going to be used by the outer class, but it isn't related to any specific instance of the outer class. Isn't that exactly the proper usage ofprivate static
? – Aviv Cohn Sep 17 '14 at 20:12