class UnitPool {

    UnitInPool createUnit(Tag tag) {
        Optional<UnitInPool> existing = getUnit(tag);
        if (existing.isPresent()) {
            UnitInPool unitInPool = existing.get();
            existingPool.put(tag, unitInPool);
            return unitInPool;
        }

        UnitInPool newUnitInPool = new UnitInPool(tag);
        pool.put(tag, newUnitInPool);
        existingPool.put(tag, newUnitInPool);
        return newUnitInPool;
    }

}