mai*_*rgs 4 java oop uuid java-ee
我最近在工作中遇到了一些代码(重新创建类似于我正在处理的代码),类似于下面的代码
有没有办法可以重新编写下面的代码来使用一个数据结构(考虑到性能)?
这里有一些代码来说明我的意思:
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);
}
}
Run Code Online (Sandbox Code Playgroud)