/** The packs this bot carries. */
private final Map<String, Pack> packs = Maps.newHashMap();
+ private final Map<String, Pack> packsByName = Maps.newHashMap();
/** The current name of the bot. */
private String name;
* The pack to add
*/
public void addPack(Pack pack) {
- packs.put(pack.id(), pack);
+ synchronized (this) {
+ if (packsByName.containsKey(pack.name())) {
+ Pack oldPack = packsByName.remove(pack.name());
+ packs.remove(oldPack.id());
+ }
+ packs.put(pack.id(), pack);
+ packsByName.put(pack.name(), pack);
+ }
}
//