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

    Fields
    Modifier and Type
    Field
    Description
    private LocalDate
    Internal field holding the actual date object.
    Format pattern of a stardate; set as "day month fullyear" format eg 25 Dec 2702.
    private static org.slf4j.Logger
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Initialise with real-world now.
    Construct and initialise a starDate.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add​(int days)
    Add the specified number of days to the current stardate, updating it in-situ.
    boolean
    canConvert​(Class clazz)
     
    Allows the parse of a date string in dd MMM yyyy format to a starDate object, part of the XStream conversion.
     
    A string of the current date in a "day month fullyear" format.

    Methods inherited from class com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter

    toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • dateformat

      public static DateTimeFormatter dateformat
      Format pattern of a stardate; set as "day month fullyear" format eg 25 Dec 2702.
    • date

      private LocalDate date
      Internal field holding the actual date object. LocalDate represents dates without complexities like timezone.
  • Constructor Details

    • starDate

      public starDate(LocalDate ld)
      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

      public LocalDate getDate()
      Returns:
    • toString

      public String toString()
      A string of the current date in a "day month fullyear" format.
      Overrides:
      toString in class Object
      Returns:
    • add

      public void add(int days)
      Add the specified number of days to the current stardate, updating it in-situ.
      Parameters:
      days -
    • canConvert

      public boolean canConvert(Class clazz)
      Specified by:
      canConvert in interface com.thoughtworks.xstream.converters.ConverterMatcher
      Overrides:
      canConvert in class com.thoughtworks.xstream.converters.time.LocalDateConverter
    • fromString

      public Object fromString(String s)
      Allows the parse of a date string in dd MMM yyyy format to a starDate object, part of the XStream conversion.
      Specified by:
      fromString in interface com.thoughtworks.xstream.converters.SingleValueConverter
      Overrides:
      fromString in class com.thoughtworks.xstream.converters.time.LocalDateConverter
      Parameters:
      s -
      Returns: