tcMenuJavaAPI
Static Public Member Functions | List of all members
com.thecoderscorner.menu.domain.util.MenuItemHelper Class Reference

Static Public Member Functions

static< T > Optional< T > visitWithResult (MenuItem item, AbstractMenuItemVisitor< T > visitor)
 
static SubMenuItem asSubMenu (MenuItem item)
 
static boolean isRuntimeStructureNeeded (MenuItem item)
 
static MenuItemBuilder builderWithExisting (MenuItem item)
 
static MenuItem createFromExistingWithId (MenuItem selected, int newId)
 
static int eepromSizeForItem (MenuItem item)
 
static AnyMenuState stateForMenuItem (AnyMenuState existingState, MenuItem item, Object val)
 
static AnyMenuState stateForMenuItem (AnyMenuState existingState, MenuItem item, Object val, boolean changed)
 
static Optional< AnyMenuStateapplyIncrementalValueChange (MenuItem item, int delta, MenuTree tree)
 
static AnyMenuState stateForMenuItem (MenuItem item, Object v, boolean changed, boolean active)
 
static void setMenuState (MenuItem item, Object value, MenuTree tree)
 
static< T > T getValueFor (MenuItem item, MenuTree tree, T def)
 
static Optional< BootItemMenuCommand<?, ?> > getBootMsgForItem (MenuItem item, SubMenuItem parent, MenuTree tree)
 
static Object getValueFor (MenuItem item, MenuTree tree)
 
static Object getDefaultFor (MenuItem item)
 

Detailed Description

A helper class for dealing with MenuItem objects. This class provides helpers for visiting menu items and returning a result. It also provides other helpers for dealing with items.

Member Function Documentation

◆ applyIncrementalValueChange()

static Optional<AnyMenuState> com.thecoderscorner.menu.domain.util.MenuItemHelper.applyIncrementalValueChange ( MenuItem  item,
int  delta,
MenuTree  tree 
)
static

Try and apply an incremental delta value update to a menu tree. This works for integer, enum and scroll items, it loads the existing value and tries to apply the delta offset, if the min/max would not be exceeded.

Parameters
itemthe item to change
deltathe delta amount
treethe tree the item belongs to
Returns
a new item if the operation was possible, otherwise empty

◆ asSubMenu()

static SubMenuItem com.thecoderscorner.menu.domain.util.MenuItemHelper.asSubMenu ( MenuItem  item)
static

Returns the menu item as a sub menu or null

Parameters
itemthe possible sub menu
Returns
the sub menu, or null.

◆ createFromExistingWithId()

static MenuItem com.thecoderscorner.menu.domain.util.MenuItemHelper.createFromExistingWithId ( MenuItem  selected,
int  newId 
)
static

creates a copy of the menu item chosen, with the ID changed to newId

Parameters
selectedthe item to copy
newIdthe ID for the copy
Returns
the newly created item

◆ eepromSizeForItem()

static int com.thecoderscorner.menu.domain.util.MenuItemHelper.eepromSizeForItem ( MenuItem  item)
static

Gets the size of the eeprom storage for a given element type

Parameters
itemthe item to determine eeprom size for
Returns
the eeprom storage needed.

◆ getBootMsgForItem()

static Optional<BootItemMenuCommand<?, ?> > com.thecoderscorner.menu.domain.util.MenuItemHelper.getBootMsgForItem ( MenuItem  item,
SubMenuItem  parent,
MenuTree  tree 
)
static

Can be used during boot sequences to get a suitable boot item for a menu item

Parameters
itemthe item
parentthe parent
treethe tree it belongs to
Returns
either a boot item or empty

◆ getDefaultFor()

static Object com.thecoderscorner.menu.domain.util.MenuItemHelper.getDefaultFor ( MenuItem  item)
static

Gets the default item value for a menu item, such that the value could be used in call to set state.

Parameters
itemthe item
Returns
the default value

◆ getValueFor() [1/2]

static Object com.thecoderscorner.menu.domain.util.MenuItemHelper.getValueFor ( MenuItem  item,
MenuTree  tree 
)
static

This gets the value from the tree state, if it is not available calls getDefaultValue Same as getValueFor(item, tree, defVal) but this just calls getDefaultFor(..) to get the default.

Parameters
itemthe item to get the state of
treethe tree holding the state
Returns
the items current value, or the default.

◆ getValueFor() [2/2]

static <T> T com.thecoderscorner.menu.domain.util.MenuItemHelper.getValueFor ( MenuItem  item,
MenuTree  tree,
def 
)
static

Gets the value from the tree or the default provided

Parameters
itemthe item
treethe tree to lookup in
defthe default item (getDefaultFor can get the default automatically)
<T>the type is inferred from the default parameter
Returns
the item looked up, or the default.

◆ isRuntimeStructureNeeded()

static boolean com.thecoderscorner.menu.domain.util.MenuItemHelper.isRuntimeStructureNeeded ( MenuItem  item)
static

Check if the item is based on a runtime item

Parameters
itemthe item to check
Returns
true if runtime based, otherwise false.

◆ setMenuState()

static void com.thecoderscorner.menu.domain.util.MenuItemHelper.setMenuState ( MenuItem  item,
Object  value,
MenuTree  tree 
)
static

Set the state in the tree for an item with a new value, setting it changed if it genuinely has.

Parameters
itemthe item
valuethe replacement value
treethe tree to change

◆ stateForMenuItem() [1/3]

static AnyMenuState com.thecoderscorner.menu.domain.util.MenuItemHelper.stateForMenuItem ( AnyMenuState  existingState,
MenuItem  item,
Object  val 
)
static

Get a new state object based on an existing state with a new value keeping all exising other values

Parameters
existingStatethe existing state object
itemthe item
valthe value
Returns
a new menu state object based on the parameters

◆ stateForMenuItem() [2/3]

static AnyMenuState com.thecoderscorner.menu.domain.util.MenuItemHelper.stateForMenuItem ( AnyMenuState  existingState,
MenuItem  item,
Object  val,
boolean  changed 
)
static

Get the state for an existing state with a new value, changing the changed state

Parameters
existingStatethe existing state object
itemthe item
valthe changed value
changedthe new change status
Returns
a new state object based on the parameters

◆ stateForMenuItem() [3/3]

static AnyMenuState com.thecoderscorner.menu.domain.util.MenuItemHelper.stateForMenuItem ( MenuItem  item,
Object  v,
boolean  changed,
boolean  active 
)
static

Create a menu state for a given item with a value update. We try pretty hard to convert whatever comes in for the value into a new state.

Parameters
itemthe item to create the state for
vthe value
changedthe changed status
activethe active status
Returns
the new menu state

◆ visitWithResult()

static <T> Optional<T> com.thecoderscorner.menu.domain.util.MenuItemHelper.visitWithResult ( MenuItem  item,
AbstractMenuItemVisitor< T >  visitor 
)
static

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.

Parameters
itemthe item to be visited
visitorthe visitor that will be used
<T>the return type
Returns
an optional of the return type, set to empty unless setResult was called.

The documentation for this class was generated from the following file: