io7m-com / jsycamore

Java embedded GUI package

Home Page:https://www.io7m.com/software/jsycamore

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Convert match methods to sealed interfaces

io7m opened this issue · comments

The component interface contains a method line this:

  /**
   * Match on the type of component.
   *
   * @param context   A context value passed through to the given functions
   * @param on_button A function evaluated if this component is a button
   * @param on_panel  A function evaluated if this component is a panel
   * @param on_label  A function evaluated if this component is a label
   * @param on_image  A function evaluated if this component is an image
   * @param on_meter  A function evaluated if this component is a meter
   * @param <A>       The type of opaque context values
   * @param <B>       The type of returned values
   *
   * @return The value returned by whichever one of the given functions is evaluated
   */

  <A, B> B matchComponent(
    A context,
    BiFunction<A, SyButtonType, B> on_button,
    BiFunction<A, SyPanelType, B> on_panel,
    BiFunction<A, SyLabelType, B> on_label,
    BiFunction<A, SyImageType, B> on_image,
    BiFunction<A, SyMeterType, B> on_meter);

This is obviously a generic visitor, and now the component type should be a sealed interface instead.