I ran across some code recently at work (recreated to be similar to what I am dealing with) similar to the code below
Is there a way I can rework the code below to use one data structure (with performance in mind)?
Here is some code to illustrate what I mean:
public class ObjectMapper {
private Map<UUID,Integer> uuidMap;
private Map<Integer,UUID> indexMap;
public ObjectMapper(){
uuidMap = new HashMap<UUID,Integer>();
indexMap = new HashMap<Integer,UUID>();
}
public void addMapping(int index, UUID uuid){
uuidMap.put(uuid, index);
indexMap.put(index, uuid);
}
.
.
.
public Integer getIndexByUUID(UUID uuid){
return uuidMap.get(uuid);
}
public UUID getUUIDByIndex(Integer index){
return indexMap.get(index);
}
}