Package org.tquadrat.foundation.util.stringconverter
This package provides classes that allow to convert certain
object instances into String and vice versa. These are inspired by the
abstract class javafx.util.StringConverter<T> from JavaFX, and
originally, I intended to use that class as the base for my implementation.
But as JavaFX is no longer part of the Java distribution, I have to provide
my own implementation:
StringConverter.
An additional implementations can be retrieved by
StringConverter.forClass(java.lang.Class)
when it was published as a
service.
In that case it must be taken care that the subject class of the new
implementation does not collide with that of an already existing
implementation. But it is still possible to provide an alternative
conversion – in that case, the implementation needs to be retrieved
explicitly.
There is no implementation of a StringConverter for
java.util.Date that works with human readable formats for the a
date/time value, because the class does not provide a proper parser
for dates, and because the method java.util.Date#toString() does
not emit the milliseconds so that the condition
StringConverter<java.util.Date> c = …
java.util.Date v = …
true == ( v.equals( c.fromString( c.toString( v ) );
cannot be easily satisfied for all possible values of v (and not
to mention that the class java.util.Date is seen as obsolete).
But I provide the class
DateLongStringConverter
that converts an instance of java.util.Date to a String holding the
number of milliseconds since the begin of the epoch and vice versa. But
this cannot be retrieved through
StringConverter.forClass( java.util.Date.class ).
This package hold implementations of
StringConverter
for a few enum types, like
DayOfWeek
and
Month,
additional String converters can be implemented easily by using
EnumStringConverter
as base class (like it was done for the already existing ones), or by using
that class directly, like here:
…
StringConverter<java.nio.file.attribute.PosixFilePermission> pfpStringConverter = new EnumStringConverter<>( java.nio.file.attribute.PosixFilePermission.class );
…
Alternatively, the method
StringConverter.forEnum()
can be used; basically, it does the same as the code snippet above.
-
ClassesClassDescriptionThe implementation of
StringConverterforStringvalues in BASE64 format.The implementation ofNumberStringConverterBigDecimal.The implementation ofNumberStringConverterBigInteger.An implementation ofStringConverterforbooleanandBooleanvalues.
The methodBooleanStringConverter.fromString(CharSequence)will accept the String "true", irrespective of case, for the valuetrue, and any other String forfalse(including the empty String!)The implementation ofStringConverterforbytearrays.The implementation ofNumberStringConverterByte.An implementation ofStringConverterforCharactervalues.
CallingCharacterStringConverter.fromString(CharSequence)with an empty String will cause anIllegalArgumentException.The implementation ofStringConverterforCharSequencevalues.An implementation ofStringConverterforCharsetvalues.
The methodCharsetStringConverter.fromString(CharSequence)will useCharset.forName(String)to obtain an instance ofCharsetbased on the given value.An implementation ofStringConverterforClassvalues.
The methodClassStringConverter.fromString(CharSequence)will useClass.forName(String, boolean, ClassLoader)to load the class with the given name.An implementation ofStringConverterforCurrencyvalues.An implementation for the interfaceStringConverterforDate.An implementation ofEnumStringConverterforMonthvalues.The implementation ofNumberStringConverterDouble.
Thedoubleliterals are expected in the format as they are emitted byDouble.toString(double); in particular, it expects decimal points instead of decimal commas for each locale.An implementation ofStringConverterforDurationvalues.
While the methodtoString(Duration)simply usesDuration.toString(), the methodDurationStringConverter.fromString(CharSequence)usesDuration.parse(CharSequence)to create theDurationinstance for the given value.An implementation ofStringConverterforURLvalues.EnumStringConverter<T extends Enum<T>>An implementation ofStringConverterfor types that are derived fromEnum.An implementation ofStringConverterforFilevalues.
The file or folder that will be identified by the respectiveFileobject do not need to exist nor is it guaranteed that it can be accessed or create through the current user.
File names will not be normalised or canonicalized.
A file name of only blanks will be accepted as valid, while the empty String will cause anIllegalArgumentException.The implementation ofNumberStringConverterforfloatandFloat.
Thefloatliterals are expected in the format as they are emitted byFloat.toString(float); in particular, it expects decimal points instead of decimal commas for each locale.The implementation ofStringConverterforStringvalues representing a hash value.The implementation ofStringConverterforInetAddressvalues.
The methodInetAddressStringConverter.fromString(CharSequence)will useInetAddress.getByName(String)to create aInetAddressinstance from the given value; this means, that when a host name is given as an argument – instead of an IP4 or IP6 address String – anIllegalArgumentExceptionis thrown when that host is unknown (cannot be resolved by DNS).The implementation ofTimeDateStringConverterforInstant.The implementation ofNumberStringConverterInteger.An implementation ofStringConverterfor arbitrary instances ofListimplementations.The implementation ofTimeDateStringConverterforjava.time.LocalDate.The implementation ofTimeDateStringConverterforjava.time.LocalDateTime.An implementation ofStringConverterforLocalevalues.
The methodLocaleStringConverter.fromString(CharSequence)will useSystemUtils.retrieveLocale(CharSequence)to obtain an instance ofLocalebased on the given value.The implementation ofTimeDateStringConverterforjava.time.LocalTime.The implementation ofNumberStringConverterLong.The implementation ofTimeDateStringConverterforjava.time.MonthDay.An implementation ofEnumStringConverterforMonthvalues.NumberStringConverter<T extends Number>The base class for implementations ofStringConverterfor types that extendNumber.The implementation ofTimeDateStringConverterforjava.time.OffsetDateTime.The implementation ofTimeDateStringConverterforjava.time.OffsetTime.An implementation ofStringConverterforPathvalues.
The methodPathStringConverter.fromString(CharSequence)usesPath.of(String, String...)to create thePathinstance for the given value.
The file or folder that will be identified by the respectivePathobject do not need to exist nor is it guaranteed that it can be accessed or create through the current user.
Names will not be normalised or canonicalized.
A path name of only blanks will be accepted as valid, while the empty String will cause anIllegalArgumentException.An implementation ofStringConverterfor regular expressions that are stored asPatternvalues.An implementation ofStringConverterforPeriodvalues.The implementation ofNumberStringConverterforShort.The implementation ofStringConverterforStringvalues.An implementation ofStringConverterfor text values.TimeDateStringConverter<T extends TemporalAccessor>The abstract base class for implementations ofStringConverterfor types that extendTemporalAccessor.The implementation ofEnumStringConverterforTimeUnitvalues.An implementation ofStringConverterforTimeZonevalues.An implementation ofStringConverterforURIvalues.
The methodURIStringConverter.fromString(CharSequence)will use the constructorURI(String)to create aURIinstance from the given value.An implementation ofStringConverterforURLvalues.An implementation ofStringConverterforUUIDvalues.The implementation ofTimeDateStringConverterforjava.time.YearMonth.The implementation ofTimeDateStringConverterforjava.time.Year.The implementation ofTimeDateStringConverterforjava.time.ZonedDateTime.An implementation ofStringConverterforZoneIdvalues.
