java.lang.Object
com.thecoderscorner.menu.domain.util.MenuItemHelper

public class MenuItemHelper extends Object
A helper class for dealing with MenuItem objects. This class provides the helper for visiting menu items and returning a result. It also provides other helpers for dealing with items.
  • Constructor Details

    • MenuItemHelper

      public MenuItemHelper()
  • Method Details

    • visitWithResult

      public static <T> Optional<T> visitWithResult(MenuItem item, AbstractMenuItemVisitor<T> visitor)
      Visits a menu item calling the appropriate function for the type and collects the result that is set by calling your visitor's `setResult` method.
      Type Parameters:
      T - the return type
      Parameters:
      item - the item to be visited
      visitor - the visitor that will be used
      Returns:
      an optional of the return type, set to empty unless setResult was called.
    • asSubMenu

      public static SubMenuItem asSubMenu(MenuItem item)
      Returns the menu item as a sub menu or null
      Parameters:
      item - the possible sub menu
      Returns:
      the sub menu, or null.
    • isRuntimeStructureNeeded

      public static boolean isRuntimeStructureNeeded(MenuItem item)
      Check if the item is based on a runtime item
      Parameters:
      item - the item to check
      Returns:
      true if runtime based, otherwise false.
    • createFromExistingWithId

      public static MenuItem createFromExistingWithId(MenuItem selected, int newId)
      creates a copy of the menu item chosen, with the ID changed to newId
      Parameters:
      selected - the item to copy
      newId - the ID for the copy
      Returns:
      the newly created item
    • eepromSizeForItem

      public static int eepromSizeForItem(MenuItem item)
      Gets the size of the eeprom storage for a given element type
      Parameters:
      item - the item to determine eeprom size for
      Returns:
      the eeprom storage needed.
    • stateForMenuItem

      public static AnyMenuState stateForMenuItem(AnyMenuState existingState, MenuItem item, Object val)
    • stateForMenuItem

      public static AnyMenuState stateForMenuItem(AnyMenuState existingState, MenuItem item, Object val, boolean changed)
    • stateForMenuItem

      public static AnyMenuState stateForMenuItem(MenuItem item, Object val, boolean changed, boolean active)
    • setMenuState

      public static void setMenuState(MenuItem item, Object value, MenuTree tree)
    • getValueFor

      public static <T> T getValueFor(MenuItem item, MenuTree tree, T def)
    • getBootMsgForItem

      public static Optional<BootItemMenuCommand<?,?>> getBootMsgForItem(MenuItem item, SubMenuItem parent, MenuTree tree)