class MenuBarTabHandlerImpl implements MenuBarTabHandler {

    private final Map<String, MenuItemFactory> byKey;
    private final List<MenuItemFactory> factories;
    private final Injector injector;

    MenuBarTabHandlerImpl(Injector injector) {
        this.injector  = requireNonNull(injector);
        this.byKey     = new HashMap<>();
        this.factories = new ArrayList<>();
    }

    @Override
    public MenuBarTabHandler add(MenuItemFactory factory) {
        factories.add(injector.inject(factory));
        return this;
    }

    @Override
    public MenuBarTabHandler set(String key, MenuItemFactory factory) {<FILL_FUNCTION_BODY>}

    @Override
    public MenuBarTabHandler insert(int index, MenuItemFactory factory) {
        factories.add(index, injector.inject(factory));
        return this;
    }

    @Override
    public boolean remove(String key) {
        final MenuItemFactory oldFactory = byKey.remove(key);
        if (oldFactory == null) {
            return false;
        } else {
            factories.remove(oldFactory);
            return true;
        }
    }

    @Override
    public int indexOf(String key) {
        final MenuItemFactory factory = byKey.get(key);
        if (factory == null) return -1;
        else return factories.indexOf(factory);
    }

    @Override
    public void populate(Menu menu) {
        final ObservableList<MenuItem> items = menu.getItems();
        items.clear();
        for (final MenuItemFactory factory : factories) {
            items.add(factory.createMenuItem());
        }
    }
}

        injector.inject(factory);
        final MenuItemFactory oldFactory = byKey.put(key, factory);
        if (oldFactory == null) {
            factories.add(factory);
        } else {
            factories.set(factories.indexOf(oldFactory), factory);
        }
        return this;
    
<no_super_class>