Enum GenericTextParser

    • Method Detail

      • values

        public static GenericTextParser[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (GenericTextParser c : GenericTextParser.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static GenericTextParser valueOf​(String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        IllegalArgumentException - if this enum type has no constant with the specified name
        NullPointerException - if the argument is null
      • format

        public Optional<String> format​(Object _object)
        Convert the given object to string with default format
        Parameters:
        _object - object to format
        Returns:
        an optional of the object converted to string (if the given object can not be converted, its not the correct type, throws an exception)
      • format

        public Optional<String> format​(Object _object,
                                       String _format)
        Convert the given object to string with the given format if not null, otherwise uses default format
        Parameters:
        _object - object to format
        _format - format to use to convert object to string (can be null)
        Returns:
        an optional of the object converted to string (if the given object can not be converted, its not the correct type, throws an exception)
      • parse

        public <T> Optional<T> parse​(Class<T> _class,
                                     String _string)
        Convert the given string to the intended _class usign default format
        Type Parameters:
        T - type of the class
        Parameters:
        _class - Class which we want once converted
        _string - String to convert
        Returns:
        an optional of the string converted to object (if the given string can not be converted or enum target or its not castable to _class, throws an exception)
        Throws:
        ClassCastException - if the enum target its not castable to the given _class
        DateTimeParseException - if is parsing a date/time or datetime
        NumberFormatException - if is parsing a non parseable numeric
      • parse

        public Optional<Object> parse​(String _string)
        Convert the given string to enum target usign default format
        Parameters:
        _string - String to convert
        Returns:
        an optional of the string converted to enum target (if the given string can not be converted, throws an exception)
        Throws:
        DateTimeParseException - if is parsing a date/time or datetime
        NumberFormatException - if is parsing a non parseable numeric
      • parse

        public <T> Optional<T> parse​(Class<T> _class,
                                     String _string,
                                     String _format)
        Convert the given string to the intended _class usign the given format if not null, otherwise uses default format
        Type Parameters:
        T - type of the class
        Parameters:
        _class - Class which we want once converted
        _string - String to convert
        _format - format to use to convert object to string (can be null)
        Returns:
        an optional of the string converted to _class (if the given string can not be converted or enum target its not castable to _class, throws an exception)
        Throws:
        ClassCastException - if the enum target its not castable to the given _class
        DateTimeParseException - if is parsing a date/time or datetime
        NumberFormatException - if is parsing a non parseable numeric
      • parse

        public Optional<Object> parse​(String _string,
                                      String _format)
        Convert the given string to enum target usign the given format if not null, otherwise uses default format
        Parameters:
        _string - String to convert
        _format - format to use to convert object to string (can be null)
        Returns:
        an optional of the string converted to enum target (if the given string can not be converted, throws an exception)
        Throws:
        DateTimeParseException - if is parsing a date/time or datetime
        NumberFormatException - if is parsing a non parseable numeric
      • find

        public static Optional<GenericTextParser> find​(Object _object)
        Try to convert the given object to string usign default format
        Parameters:
        _object - object to format
        Returns:
        an optional of the object converted to string (if the given object can not be converted, its not the correct type, throws an exception)
        Since:
        1.2.0
      • find

        public static Optional<GenericTextParser> find​(Class _class)
        Try to return an available parser for the given class
        Parameters:
        _class - class to parse
        Returns:
        an optional of the appropiate converter or an empty optional
        Since:
        1.2.0
      • toFormattedString

        public static final Optional<String> toFormattedString​(Object _object)
        Try to convert the given object to string usign default format
        Parameters:
        _object - object to format
        Returns:
        an optional of the object converted to string (if the given object can not be converted, its not the correct type, throws an exception)
      • toFormattedString

        public static final Optional<String> toFormattedString​(Object _object,
                                                               String _format)
        Try to convert the given object to string usign the given format if not null, otherwise uses default format
        Parameters:
        _object - object to format
        _format - format to use to convert object to string (can be null)
        Returns:
        an optional of the object converted to string (if the given object can not be converted, its not the correct type, throws an exception)
      • toValue

        public static final <T> Optional<T> toValue​(Class<T> _class,
                                                    String _string)
        Try to convert the given string to the intended _class usign default format
        Type Parameters:
        T - type of the class
        Parameters:
        _class - Class which we want once converted
        _string - String to convert
        Returns:
        an optional of the string converted to _class if any suitable converter found for the given _class
        Throws:
        DateTimeParseException - if is parsing a date/time or datetime
        NumberFormatException - if is parsing a non parseable numeric
      • toValue

        public static final <T> Optional<T> toValue​(Class<T> _class,
                                                    String _string,
                                                    String _format)
        Try to convert the given string to the intended _class usign the given format if not null, otherwise uses default format
        Type Parameters:
        T - type of the class
        Parameters:
        _class - Class which we want once converted
        _string - String to convert
        _format - format to use to convert object to string (can be null)
        Returns:
        an optional of the string converted to _class if any suitable converter found for the given _class
        Throws:
        DateTimeParseException - if is parsing a date/time or datetime
        NumberFormatException - if is parsing a non parseable numeric