Package name.moore.kevin.ze.game
Class starDate
java.lang.Object
com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter
com.thoughtworks.xstream.converters.time.LocalDateConverter
name.moore.kevin.ze.game.starDate
- All Implemented Interfaces:
com.thoughtworks.xstream.converters.ConverterMatcher,com.thoughtworks.xstream.converters.SingleValueConverter
public class starDate
extends com.thoughtworks.xstream.converters.time.LocalDateConverter
Holds an in-game date (obviously in the far-future!). The game's 'now' and
other planned events may be represented by instances of this class.
Serialised in XML as
<starDate>02 Jun 2414</starDate> so its
readable, the class acts as an XStream converter to parse this.
It would be feasible to just use a standard LocalDate but that allows formatting
to vary. The formatting is within this class so we can be consistent and maybe create a format
completely different from the day-month-year concept.- Author:
- Kevin Moore
<dev@kevin.moore.name>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate LocalDateInternal field holding the actual date object.static DateTimeFormatterFormat pattern of a stardate; set as "day month fullyear" format eg 25 Dec 2702.private static org.slf4j.Logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(int days)Add the specified number of days to the current stardate, updating it in-situ.booleancanConvert(Class clazz)fromString(String s)Allows the parse of a date string in dd MMM yyyy format to a starDate object, part of the XStream conversion.getDate()toString()A string of the current date in a "day month fullyear" format.Methods inherited from class com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter
toString
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
dateformat
Format pattern of a stardate; set as "day month fullyear" format eg 25 Dec 2702. -
date
Internal field holding the actual date object. LocalDate represents dates without complexities like timezone.
-
-
Constructor Details
-
starDate
Construct and initialise a starDate. The LocalDate can be specified with static method eg LocalDate.of(2410, Month.DECEMBER, 25)- Parameters:
ld-
-
starDate
public starDate()Initialise with real-world now.
-
-
Method Details
-
getDate
- Returns:
-
toString
A string of the current date in a "day month fullyear" format. -
add
public void add(int days)Add the specified number of days to the current stardate, updating it in-situ.- Parameters:
days-
-
canConvert
- Specified by:
canConvertin interfacecom.thoughtworks.xstream.converters.ConverterMatcher- Overrides:
canConvertin classcom.thoughtworks.xstream.converters.time.LocalDateConverter
-
fromString
Allows the parse of a date string in dd MMM yyyy format to a starDate object, part of the XStream conversion.- Specified by:
fromStringin interfacecom.thoughtworks.xstream.converters.SingleValueConverter- Overrides:
fromStringin classcom.thoughtworks.xstream.converters.time.LocalDateConverter- Parameters:
s-- Returns:
-