Class ItemUtil


  • @NonNullByDefault
    public class ItemUtil
    extends Object
    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
    • Method Detail

      • isValidItemName

        public static boolean isValidItemName​(String itemName)
        Returns true if the specified name is a valid item name, otherwise false.

        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

        public static void assertValidItemName​(String itemName)
                                        throws IllegalArgumentException
        Ensures that the specified name of the item is valid.

        If the name of the item is invalid an IllegalArgumentException is 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

        public static String getMainItemType​(String itemTypeName)
        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

        public static @Nullable String getItemTypeExtension​(@Nullable String itemTypeName)
        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, null in case no extension is defined.