java.lang.Object
org.jhotdraw8.base.converter.DefaultConverter
Converts an
Object to a String but can not a String
back to an Object.
This converter is not bijective, and thus only useful for one-way conversions to a String. For example for generating a message text.
- The conversion to string is performed by invoking the
toStringmethod on the value object. - The
fromStringmethod always returns a String object regardless of the type that was convertedtoString. - If a null value is converted to string, the string contains the text
"null". On the conversion from string, a String object with the value"null"is returned.
- Author:
- Werner Randelshofer
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfromString(@NonNull CharBuffer buf, @Nullable IdResolver idResolver) Constructs a value from a string.Provides a default value for APIs which always require a value even if conversion from String failed.voidtoString(@NonNull Appendable out, @Nullable IdSupplier idSupplier, @Nullable Object value) Converts a value to a string and appends it to the providedAppendable.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jhotdraw8.base.converter.Converter
fromString, fromString, fromString, getHelpText, needsIdResolver, toString, toString, toString
-
Constructor Details
-
DefaultConverter
public DefaultConverter()
-
-
Method Details
-
fromString
Description copied from interface:ConverterConstructs a value from a string.The converter should try to create the value greedily, by consuming as many characters as possible for the value.
This method does not change the state of the converter.
- Specified by:
fromStringin interfaceConverter<Object>- Parameters:
buf- A char buffer which holds the string. The char buffer must be treated as read only! The position of the char buffer denotes the beginning of the string when this method is invoked. After completion of this method, the position is set after the last consumed character.idResolver- The factory for looking up object ids. Nullable for non-resolving converters.- Returns:
- The value. Nullable.
-
toString
public void toString(@NonNull Appendable out, @Nullable IdSupplier idSupplier, @Nullable Object value) throws IOException Description copied from interface:ConverterConverts a value to a string and appends it to the providedAppendable.This method does not change the state of the converter.
- Specified by:
toStringin interfaceConverter<Object>- Parameters:
out- The appendableidSupplier- The factory for creating object ids. Nullable for non-resolving converters.value- The value. Nullable.- Throws:
IOException- thrown by Appendable
-
getDefaultValue
Description copied from interface:ConverterProvides a default value for APIs which always require a value even if conversion from String failed.- Specified by:
getDefaultValuein interfaceConverter<Object>- Returns:
- The default value to use when conversion from String failed.
-