Class TypeParser


  • @NonNullByDefault
    public final class TypeParser
    extends Object
    This is a helper class that helps parsing a string into an openHAB type (state or command).
    Author:
    Kai Kreuzer - Initial contribution
    • Method Detail

      • parseType

        public static @Nullable Type parseType​(String typeName,
                                               String input)
        Parses a string into a type.
        Parameters:
        typeName - name of the type, for example StringType.
        input - input string to parse.
        Returns:
        Parsed type or null, if the type couldn't be parsed.
      • parseState

        public static @Nullable State parseState​(List<Class<? extends State>> types,
                                                 String s)

        Determines a state from a string. Possible state types are passed as a parameter. Note that the order matters here; the first type that accepts the string as a valid value, will be used for the state.

        Example: The type list is OnOffType.class,StringType.class. The string "ON" is now accepted by the OnOffType and thus OnOffType.ON will be returned (and not a StringType with value "ON").

        Parameters:
        types - possible types of the state to consider
        s - the string to parse
        Returns:
        the corresponding State instance or null
      • parseCommand

        public static @Nullable Command parseCommand​(List<Class<? extends Command>> types,
                                                     String s)

        Determines a command from a string. Possible command types are passed as a parameter. Note that the order matters here; the first type that accepts the string as a valid value, will be used for the command.

        Example: The type list is OnOffType.class,StringType.class. The string "ON" is now accepted by the OnOffType and thus OnOffType.ON will be returned (and not a StringType with value "ON").

        Parameters:
        types - possible types of the command to consider
        s - the string to parse
        Returns:
        the corresponding Command instance or null