io7m-com / jsycamore

Java embedded GUI package
https://www.io7m.com/software/jsycamore
ISC License
3 stars 0 forks source link

Convert match methods to sealed interfaces #41

Closed io7m closed 12 months ago

io7m commented 2 years ago

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.

io7m commented 12 months ago

Done.