Package org.openhab.core.items
Class ItemUtil
java.lang.Object
org.openhab.core.items.ItemUtil
The
ItemUtil class contains utility methods for Item objects.
This class cannot be instantiated, it only contains static methods.
- Author:
- Michael Grammling - Initial contribution, Simon Kaufmann - added type conversion, Martin van Wingerden - when converting types convert null to UnDefType.NULL
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidassertValidItemName(String itemName) Ensures that the specified name of the item is valid.static @Nullable StringgetItemTypeExtension(@Nullable String itemTypeName) Get the optional extension from an item type name.static StringgetMainItemType(String itemTypeName) Get the main item type from an item type name.static booleanisValidItemName(@Nullable String itemName) Returnstrueif the specified name is a valid item name, otherwisefalse.
-
Field Details
-
EXTENSION_SEPARATOR
- See Also:
-
-
Method Details
-
isValidItemName
Returnstrueif the specified name is a valid item name, otherwisefalse.A valid item name must only only consists of the following characters:
- a-z
- A-Z
- 0..9
- _ (underscore)
- Parameters:
itemName- the name of the item to be checked (could be null or empty)- Returns:
- true if the specified name is a valid item name, otherwise false
-
assertValidItemName
Ensures that the specified name of the item is valid.If the name of the item is invalid an
IllegalArgumentExceptionis thrown, otherwise this method returns silently.A valid item name must only only consists of the following characters:
- a-z
- A-Z
- 0..9
- _ (underscore)
- Parameters:
itemName- the name of the item to be checked (could be null or empty)- Throws:
IllegalArgumentException- if the name of the item is invalid
-
getMainItemType
Get the main item type from an item type name. The name may consist of an extended item type where an extension is separated by ":".- Parameters:
itemTypeName- the item type name, e.g. "Number:Temperature" or "Switch".- Returns:
- the main item type without the extension.
-
getItemTypeExtension
Get the optional extension from an item type name.- Parameters:
itemTypeName- the item type name, e.g. "Number:Temperature" or "Switch".- Returns:
- the extension from the item type name,
nullin case no extension is defined.
-