Class ViewElement.Wither<T extends ViewElement>

java.lang.Object
com.foreach.across.modules.web.ui.ViewElement.Wither<T>
Type Parameters:
T - type of the view element
Enclosing interface:
ViewElement

public static class ViewElement.Wither<T extends ViewElement> extends Object
A wrapper for any type of ViewElement which allows the use of separate functions to perform the actions. Uses 3 separate functional interfaces to perform typical actions and convey meaning (get, set, remove).

The main purpose of the wither approach is to allow a library of functions to be defined that allow a more descriptive and fluent approach of configuration elements. Using separate functions increases testability and removes the need for a complex class hierarchy.

Default functions are available for typical html node actions.

Because of limitations with generics, the wither does not define a type on its parameter interfaces. This means that the function implementations should do type checking at runtime where appropriate, or runtime class cast exceptions will be thrown.

See Also:
  • Constructor Details

    • Wither

      public Wither(T element)
  • Method Details

    • set

      public ViewElement.Wither<T> set(ViewElement.WitherSetter... setters)
      Execute one or more setter functions.
      Parameters:
      setters - to execute
      Returns:
      self
    • apply

      public ViewElement.Wither<T> apply(Consumer<? super T> consumer)
      Allows for a specifically typed generic consumer to be passed or defined.
      Parameters:
      consumer - to execute
      Returns:
      self
    • remove

      public ViewElement.Wither<T> remove(ViewElement.WitherRemover... functions)
      Execute one or more remover functions. A remover is defined as a separate interface so implementations can both implement setter and remover at the same time.
      Parameters:
      functions - to execute
      Returns:
      self
    • get

      public <U> U get(ViewElement.WitherGetter<?,U> function)
      Get a value from the element. Use ViewElement.WitherGetter.as(Class) for compile time typing. Note that runtime type casting execptions will occur when using the wrong type.
      Type Parameters:
      U - type of the expected return value
      Parameters:
      function - that returns the value
      Returns:
      value
    • get

      public T get()