Please refer to the following method :
public Set getCellsInColumn(String columnIndex){
Map cellsMap = getCell
You are retrieving all the keys (accessing the whole map) and then for some keys, you access the map again to get the value.
You can iterate over the map to get map entries (Map.Entry) (couples of keys and values) and access the map only once.
Map.entrySet() delivers a set of Map.Entry
s each one with the key and corresponding value.
for ( Map.Entry< String, LIMSGridCell > entry : cellsMap.entrySet() ) {
if ( entry.getKey().startsWith( columnIndex ) ) {
cells.add( entry.getValue() );
}
}
Note: I doubt that this will be much of an improvement since if you use map entries you will instantiate an object for each entry. I don't know if this is really faster than calling get()
and retrieving the needed reference directly.