Class MenuItemHelper
- java.lang.Object
-
- com.thecoderscorner.menu.domain.util.MenuItemHelper
-
public class MenuItemHelper extends java.lang.ObjectA 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 Summary
Constructors Constructor Description MenuItemHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static SubMenuItemasSubMenu(MenuItem item)Returns the menu item as a sub menu or nullstatic MenuItemcreateFromExistingWithId(MenuItem selected, int newId)creates a copy of the menu item chosen, with the ID changed to newIdstatic inteepromSizeForItem(MenuItem item)Gets the size of the eeprom storage for a given element typestatic booleanisRuntimeStructureNeeded(MenuItem item)Check if the item is based on a runtime itemstatic java.lang.StringmakeNameToVar(java.lang.String name)static <T> java.util.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.
-
-
-
Method Detail
-
visitWithResult
public static <T> java.util.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 visitedvisitor- 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 copynewId- 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.
-
makeNameToVar
public static java.lang.String makeNameToVar(java.lang.String name)
-
-