ch.sahits.game.openpatrician.model
Class Date

java.lang.Object
  extended by ch.sahits.game.openpatrician.model.Date
All Implemented Interfaces:
IClockUpdateListenable

public class Date
extends Object
implements IClockUpdateListenable

Representation of the date within the game. This class is thread safe. The Date is implemented as a singleton. However there is no getInstance method to retrieve the once created instance, so it must be referenced elsewhere.

Author:
Andi Hotz, (c) Sahits GmbH, 2011 Created on Sep 16, 2011

Field Summary
private  Calendar cal
          Current date
private static Date instance
          This instance
private  CopyOnWriteArrayList<IClockUpdateListener> listeners
           
private static Object lock
          Lock for guaranteeing thread safty
private  ResourceBundle messages
           
private  int startYear
          Start year
private  int update
          Tick update in minutes
 
Constructor Summary
(package private) Date(Calendar cal)
          Constructor for testing purposes only
private Date(int year)
          Initialize the date with start year.
 
Method Summary
 void add(IClockUpdateListener listener)
          Add a new listener that should be updated
 Calendar getCurrentDate()
          Retrieve a copy of the current date
 String getEndOfWeek()
          Retrieve the date of the end of the week in the form {Day of month}.
(package private)  Calendar getEndOfWeekInternal()
          Retrieve the date of the of the Sunday of last week
static Date getInstance(int year)
          Retrieve the singleton instance of the date.
 String getStartOfWeek()
          Retrieve the date of the start of the week in the form {Day of month}.
(package private)  Calendar getStartOfWeekInternal()
          Retrieve the date of the start of the last week
 int getStartYear()
          Retrieve the start year
 int getUpdateInterval()
          Retrieve the update interval
 int getWeekdayIndex()
          Retrieve an index for the current weekday.
 void notifyTick()
          Notify all registered listeners of a clock tick
 void notifyTickUpdate()
          Notify all registered listeners of the change in update tick size in minutes
 void remove(IClockUpdateListener listener)
          Remove a listener from the queue
 void setTickUpdate(int minutes)
          Set the tick update in number of minutes
 void tick()
          Update the time by one tick.
 String toDisplayString()
          Create a string representation for the user interface of the form {Day of month}.
 String todisplayString(int day, int month, int year)
           
private  String toShortDate(Calendar c)
          Convert the date into the form {Day in month}.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

update

private int update
Tick update in minutes


cal

private final Calendar cal
Current date


startYear

private final int startYear
Start year


instance

private static Date instance
This instance


lock

private static Object lock
Lock for guaranteeing thread safty


listeners

private CopyOnWriteArrayList<IClockUpdateListener> listeners

messages

private ResourceBundle messages
Constructor Detail

Date

private Date(int year)
Initialize the date with start year. The initial date is 13th July of the start year. The default tick update is 5 minutes.


Date

Date(Calendar cal)
Constructor for testing purposes only

Parameters:
cal -
Method Detail

getInstance

public static Date getInstance(int year)
Retrieve the singleton instance of the date. If the instance is not yet created, it will be created

Parameters:
year -
Returns:

tick

public void tick()
Update the time by one tick.


setTickUpdate

public void setTickUpdate(int minutes)
Set the tick update in number of minutes

Parameters:
minutes - tick update

getStartYear

public int getStartYear()
Retrieve the start year

Returns:
the startYear

getStartOfWeek

public String getStartOfWeek()
Retrieve the date of the start of the week in the form {Day of month}. {Month}. The week starts with Monday

Returns:

getStartOfWeekInternal

Calendar getStartOfWeekInternal()
Retrieve the date of the start of the last week

Returns:

toShortDate

private String toShortDate(Calendar c)
Convert the date into the form {Day in month}. {Month}

Parameters:
c -
Returns:

getEndOfWeek

public String getEndOfWeek()
Retrieve the date of the end of the week in the form {Day of month}. {Month}. The week ends with Sunday

Returns:

getEndOfWeekInternal

Calendar getEndOfWeekInternal()
Retrieve the date of the of the Sunday of last week

Returns:

toDisplayString

public String toDisplayString()
Create a string representation for the user interface of the form {Day of month}. {Month} {Year}.

Returns:

todisplayString

public String todisplayString(int day,
                              int month,
                              int year)

add

public void add(IClockUpdateListener listener)
Description copied from interface: IClockUpdateListenable
Add a new listener that should be updated

Specified by:
add in interface IClockUpdateListenable

remove

public void remove(IClockUpdateListener listener)
Description copied from interface: IClockUpdateListenable
Remove a listener from the queue

Specified by:
remove in interface IClockUpdateListenable

notifyTick

public void notifyTick()
Description copied from interface: IClockUpdateListenable
Notify all registered listeners of a clock tick

Specified by:
notifyTick in interface IClockUpdateListenable

notifyTickUpdate

public void notifyTickUpdate()
Description copied from interface: IClockUpdateListenable
Notify all registered listeners of the change in update tick size in minutes

Specified by:
notifyTickUpdate in interface IClockUpdateListenable

getCurrentDate

public Calendar getCurrentDate()
Retrieve a copy of the current date

Returns:

getUpdateInterval

public final int getUpdateInterval()
Retrieve the update interval

Returns:

getWeekdayIndex

public final int getWeekdayIndex()
Retrieve an index for the current weekday. Mondy is 0.

Returns:


Copyright © 2011-2012 Sahits GmbH. All Rights Reserved.