model
Class Tournament

java.lang.Object
  extended by model.tournament.TournamentDataModel
      extended by model.Tournament

public class Tournament
extends TournamentDataModel

Class Tournament is used to store all the information and entries of a particular tournament. The data structure of the tournament is based on the class model.tournament.TournamentDataModel. Editing and creating a completely new tournament is handled via the TournamentUpdater and TournamentInitializer objects. A Tournament object also controls the reading and writing of the XML data-, log- and export files of the tournament through classes that extend the File class.


Nested Class Summary
static class Tournament.EntryComparator
          EntryComparator class is used so that Entry objects can be sorted by different fields of the objects.
 
Field Summary
private  java.util.HashMap<ID,Entry> confirmed_pre_entries
           
private  ID discount_id_counter
           
private  java.util.HashMap<ID,Entry> entries
           
private  ID entry_id_counter
           
private  LogFile log_file
           
private  java.util.HashMap<ID,Entry> pre_entries
           
private  ExportFile pre_registration_export_file
           
private  ExportFile registration_export_file
           
static java.lang.String[] TOURNAMENT_HEADER_FIELDS
           
private  XMLFile xml_file
           
 
Constructor Summary
private Tournament(ID tournament_id)
          Private constructor, common for the two public constructors.
protected Tournament(TournamentInitializer initializer)
          Constructor creates a new Tournament object from a TournamentInitializer object.
protected Tournament(XMLFile existing_xml_file)
          Constructor creates a Tournament object from an existing XML data file
 
Method Summary
protected  void addEntry(Entry entry)
          Method adds a registered entry to the tournament
protected  void addPreEntry(Entry... pre_entries_to_add)
          Method adds pre-entries to the tournament
protected  void closeTournament()
          Closes the tournament so that its data cannot be modified.
protected  void confirmPreEntry(ID entry_id)
          Moves the given pre-entry to the confirmed pre-entries list.
private  java.util.HashMap<ID,Entry> createEntryMap(java.util.ArrayList<Entry> entry_list)
           
protected  void delete()
          Deletes a closed tournament.
protected  void deleteEntry(ID entry_id)
          Deletes a given entry.
protected  void editEntry(ID entry_id, EntryUpdater updater)
          Edits the information of the entry.
protected  void editTournament(TournamentUpdater updater)
          Edits the general information and discounts of the tournament.
 Entry[] getConfirmedPreEntries()
           
 Entry[] getConfirmedPreEntries(Tournament.EntryComparator.SortBy sort_by)
           
 Country[] getCountryList()
           
 java.lang.String getDataFilename()
           
 Entry[] getEntries()
           
 Entry[] getEntries(Tournament.EntryComparator.SortBy sort_by)
           
 Entry getEntry(ID entry_id)
          Returns a given entry.
protected  EntryInitializer getEntryInitializer()
          Returns an EntryInitializer object that can be used to create a new entry for this tournament.
protected  EntryUpdater getEntryUpdater(ID target_entry_id)
          Returns an EntryUpdater object that can be used to modify an entry of this tournament.
 java.lang.String getLogFileName()
           
protected  ID getNextDiscountId()
          Used to get the next available discount ID for the tournament and update the counter by one.
protected  ID getNextEntryId()
          Used to get the next available entry ID for the tournament and update the counter by one.
protected  ID getNextEntryId(int increment)
          Used to get the next available entry ID for the tournament and update the counter.
 int getNumberOfDiscounts(ID discount_id)
          Returns the no.
 int getNumberOfEntries()
           
 int getNumberOfPreEntries()
           
 Entry[] getPreEntries()
           
 Entry[] getPreEntries(Tournament.EntryComparator.SortBy sort_by)
           
 Entry getPreEntry(ID entry_id)
          Returns a given pre-entry.
protected  EntryInitializer getPreEntryInitializer()
          Returns an EntryInitializer object that can be used to create a new pre-entry for this tournament.
protected  EntryInitializer[] getPreEntryInitializer(int amount)
          Returns an array EntryInitializer objects that can be used to create new pre-entries for this tournament.
protected  EntryUpdater getPreEntryUpdater(ID target_entry_id)
          Returns an EntryUpdater object that can be used to modify a pre-entry of this tournament.
 Rank[] getRankList()
           
 java.math.BigDecimal getTotalFees()
           
 java.math.BigDecimal getTotalPaid()
           
protected  TournamentUpdater getTournamentUpdater()
          Returns a TournamentUpdater object that can be used to edit information and discounts of this tournament.
 Entry[] getUnpaidEntries()
           
 Entry[] getUnpaidEntries(Tournament.EntryComparator.SortBy sort_by)
           
 int importPreEntriesFromWiki(java.lang.String pre_entries_from_wiki)
          Adds pre-entries from a string in wiki-format.
protected  void reopenTournament()
          Opens a closed tournament so that its data can be modified.
private  void setHeaderData(TournamentInitializer initializer)
          Method is used by the constructor that creates a completely new Tournament object to set the tournament information
 void setPreregistrationOpen(boolean open)
          Opens/closes the tournament preregistration.
 java.lang.String toString()
           
 java.lang.String writeExportFile(boolean from_pre_entries)
          Writes a file that can be read by the Go player pairing program McMahon.
private  void writeLogMessage(java.lang.String message)
          Writes a message with system date and time to the tournament log file.
 
Methods inherited from class model.tournament.TournamentDataModel
addDiscount, getBaseFee, getDate, getDefaultCountry, getDiscounts, getHtml, getId, getName, hasDiscountId, isPreRegistrationOpen, isTournamentOpen, removeDiscount, setBaseFee, setBaseFee, setDate, setDate, setDefaultCountry, setDefaultCountry, setDiscounts, setHtml, setName, setTournamentOpen
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TOURNAMENT_HEADER_FIELDS

public static final java.lang.String[] TOURNAMENT_HEADER_FIELDS

entries

private transient java.util.HashMap<ID,Entry> entries

pre_entries

private transient java.util.HashMap<ID,Entry> pre_entries

confirmed_pre_entries

private transient java.util.HashMap<ID,Entry> confirmed_pre_entries

xml_file

private transient XMLFile xml_file

registration_export_file

private transient ExportFile registration_export_file

pre_registration_export_file

private transient ExportFile pre_registration_export_file

log_file

private transient LogFile log_file

entry_id_counter

private transient ID entry_id_counter

discount_id_counter

private transient ID discount_id_counter
Constructor Detail

Tournament

protected Tournament(XMLFile existing_xml_file)
              throws GoException
Constructor creates a Tournament object from an existing XML data file

Parameters:
existing_xml_file -
Throws:
GoException - thrown if the XML data file cannot be read or parsed.

Tournament

protected Tournament(TournamentInitializer initializer)
              throws GoException
Constructor creates a new Tournament object from a TournamentInitializer object. The tournament information is read from the initializer. (the tournament created by this constructor has no entries)

Parameters:
initializer - contains tournament information
Throws:
GoException - throw if the initializer cannot be read

Tournament

private Tournament(ID tournament_id)
Private constructor, common for the two public constructors. Creates the IO files used by the Tournament object.

Parameters:
tournament_id - the ID of the tournament to be created
Method Detail

setHeaderData

private void setHeaderData(TournamentInitializer initializer)
                    throws GoException
Method is used by the constructor that creates a completely new Tournament object to set the tournament information

Parameters:
initializer - contains the tournament information
Throws:
GoException - thrown if the initializer cannot be read

getTotalFees

public java.math.BigDecimal getTotalFees()
Returns:
the combined sum of the total fees of all the registered entries in the tournament

getTotalPaid

public java.math.BigDecimal getTotalPaid()
Returns:
the combined sum of the money paid of by the registered entries(i.e. players) in the tournament

getNumberOfDiscounts

public int getNumberOfDiscounts(ID discount_id)
Returns the no. of times a particular discount has been used in the registered entries of the tournament.

Parameters:
discount_id - id of the discount
Returns:
no. of times the discount has been used

getNumberOfEntries

public int getNumberOfEntries()
Returns:
no. of registered entries in the tournament

getNumberOfPreEntries

public int getNumberOfPreEntries()
Returns:
no. of pre-entries in the tournament

getLogFileName

public java.lang.String getLogFileName()
Returns:
the name of the tournament log file

confirmPreEntry

protected final void confirmPreEntry(ID entry_id)
                              throws PreEntryNotFoundException,
                                     GoIOException
Moves the given pre-entry to the confirmed pre-entries list. (does not create a new registered entry, this must be done separately!)

Parameters:
entry_id - id of the pre-entry to confirm
Throws:
PreEntryNotFoundException - thrown if the pre-entry is not found
GoIOException - thrown if the modification of the XML data file fails

editTournament

protected void editTournament(TournamentUpdater updater)
                       throws GoException
Edits the general information and discounts of the tournament.

Parameters:
updater - a TournamentUpdater object that contains the new tournament information
Throws:
GoException - thrown if the updater cannot be read or the XML file modification fails

writeExportFile

public final java.lang.String writeExportFile(boolean from_pre_entries)
                                       throws GoException
Writes a file that can be read by the Go player pairing program McMahon.

Parameters:
from_pre_entries - if true the export file is created from the pre-entries, else from the registered entries
Returns:
the name of the export file
Throws:
GoException

getDataFilename

public final java.lang.String getDataFilename()

getEntry

public Entry getEntry(ID entry_id)
               throws EntryNotFoundException
Returns a given entry.

Parameters:
entry_id - id of the entry to return
Returns:
the specified Entry object
Throws:
EntryNotFoundException - thrown if the entry cannot be found

getPreEntry

public Entry getPreEntry(ID entry_id)
                  throws PreEntryNotFoundException
Returns a given pre-entry.

Parameters:
entry_id - id of the entry to return
Returns:
the specified Entry object
Throws:
PreEntryNotFoundException - thrown if the entry cannot be found

deleteEntry

protected void deleteEntry(ID entry_id)
                    throws EntryNotFoundException,
                           GoIOException
Deletes a given entry. (deleting a confirmed pre-entry is not allowed in order to keep the historical data intact)

Parameters:
entry_id - id of the entry to be deleted
Throws:
EntryNotFoundException - throw if the entry cannot be found
GoIOException - thrown if the modification of the XML data file fails.

getNextEntryId

protected ID getNextEntryId()
                     throws GoIOException
Used to get the next available entry ID for the tournament and update the counter by one.

Returns:
next entry ID
Throws:
GoIOException - thrown if the XML data file modification fails

getNextEntryId

protected ID getNextEntryId(int increment)
                     throws GoIOException
Used to get the next available entry ID for the tournament and update the counter. The entry id counter can be incremented by more than one if need. This is used when importing multiple entries at the same time so that the XML file update operation does not have to be made multiple times.

Parameters:
increment - the increment to be made
Returns:
next entry ID
Throws:
GoIOException - thrown if the XML data file modification fails

getNextDiscountId

protected ID getNextDiscountId()
                        throws GoIOException
Used to get the next available discount ID for the tournament and update the counter by one.

Returns:
next discount ID
Throws:
GoIOException - thrown if the XML data file modification fails

editEntry

protected void editEntry(ID entry_id,
                         EntryUpdater updater)
                  throws GoException
Edits the information of the entry.

Parameters:
entry_id - id of the entry to be edited
updater - EntryUpdater object containing the new information
Throws:
GoException - thrown if the updater cannot be read or the XML data file modification fails

getEntryInitializer

protected EntryInitializer getEntryInitializer()
                                        throws GoException
Returns an EntryInitializer object that can be used to create a new entry for this tournament.

Returns:
EntryInitializer object
Throws:
GoException - thrown if the necessary XML data file modification fails

getPreEntryInitializer

protected EntryInitializer getPreEntryInitializer()
                                           throws GoException
Returns an EntryInitializer object that can be used to create a new pre-entry for this tournament.

Returns:
EntryInitializer object
Throws:
GoException - thrown if the necessary XML data file modification fails

getPreEntryInitializer

protected EntryInitializer[] getPreEntryInitializer(int amount)
                                             throws GoException
Returns an array EntryInitializer objects that can be used to create new pre-entries for this tournament. Used when importing multiple pre-entries at the same time.

Parameters:
amount - no of initializers
Returns:
EntryInitializer object
Throws:
GoException - thrown if the necessary XML data file modification fails

getEntryUpdater

protected EntryUpdater getEntryUpdater(ID target_entry_id)
                                throws GoException
Returns an EntryUpdater object that can be used to modify an entry of this tournament.

Returns:
EntryUpdater object
Throws:
GoException - thrown if the necessary XML data file modification fails

getPreEntryUpdater

protected EntryUpdater getPreEntryUpdater(ID target_entry_id)
                                   throws GoException
Returns an EntryUpdater object that can be used to modify a pre-entry of this tournament.

Returns:
EntryUpdater object
Throws:
GoException - thrown if the necessary XML data file modification fails

getTournamentUpdater

protected TournamentUpdater getTournamentUpdater()
                                          throws GoException
Returns a TournamentUpdater object that can be used to edit information and discounts of this tournament.

Returns:
TournamentUpdater object
Throws:
GoException

createEntryMap

private java.util.HashMap<ID,Entry> createEntryMap(java.util.ArrayList<Entry> entry_list)
Parameters:
entry_list - an ArrayList of Entry objects
Returns:
a HashMap object with ID-Entry pairs

getUnpaidEntries

public Entry[] getUnpaidEntries()
Returns:
an array of all the registered entries in this tournament for which total fee != paid sum

getUnpaidEntries

public Entry[] getUnpaidEntries(Tournament.EntryComparator.SortBy sort_by)
Parameters:
sort_by - an enum that defines how the return array is sorted
Returns:
an array of all the registered entries in this tournament for which total fee != paid sum

getEntries

public Entry[] getEntries()
Returns:
an array of all the registered entries in this tournament

getEntries

public Entry[] getEntries(Tournament.EntryComparator.SortBy sort_by)
Parameters:
sort_by - an enum that defines how the return array is sorted
Returns:
an array of all the registered entries in this tournament

getPreEntries

public Entry[] getPreEntries()
Returns:
an array of all the pre-entries in this tournament

getPreEntries

public Entry[] getPreEntries(Tournament.EntryComparator.SortBy sort_by)
Parameters:
sort_by - an enum that defines how the return array is sorted
Returns:
an array of all the pre-entries in this tournament

getConfirmedPreEntries

public Entry[] getConfirmedPreEntries()
Returns:
an array of all the confirmed pre-entries in this tournament

getConfirmedPreEntries

public Entry[] getConfirmedPreEntries(Tournament.EntryComparator.SortBy sort_by)
Parameters:
sort_by - an enum that defines how the return array is sorted
Returns:
an array of all the confirmed pre-entries in this tournament

addEntry

protected void addEntry(Entry entry)
                 throws GoIOException,
                        TournamentClosedException,
                        DuplicatePlayerException
Method adds a registered entry to the tournament

Parameters:
entry - the Entry object to be added
Throws:
GoIOException - thrown if the XML date file cannot be modified for some reason
TournamentClosedException - thrown if the tournament is closed
DuplicatePlayerException - thrown if there already is a registered entry with the same first and last name.

addPreEntry

protected void addPreEntry(Entry... pre_entries_to_add)
                    throws GoException
Method adds pre-entries to the tournament

Parameters:
pre_entries_to_add - the Entry objects to be added
Throws:
GoIOException - thrown if the XML date file cannot be modified for some reason
TournamentClosedException - thrown if the tournament is closed
GoException - thrown if preregistration is not open

importPreEntriesFromWiki

public int importPreEntriesFromWiki(java.lang.String pre_entries_from_wiki)
                             throws GoException
Adds pre-entries from a string in wiki-format. Returns -1 if succeeds, otherwise the string line number.

Parameters:
pre_entries_from_wiki - wiki string
Throws:
GoIOException
TournamentClosedException
GoException

getRankList

public Rank[] getRankList()
Returns:
the common rank list

getCountryList

public Country[] getCountryList()
Returns:
the common country list

writeLogMessage

private void writeLogMessage(java.lang.String message)
Writes a message with system date and time to the tournament log file.

Parameters:
message -

setPreregistrationOpen

public void setPreregistrationOpen(boolean open)
Opens/closes the tournament preregistration.

Overrides:
setPreregistrationOpen in class TournamentDataModel

closeTournament

protected void closeTournament()
                        throws GoIOException
Closes the tournament so that its data cannot be modified.

Throws:
GoIOException - thrown if the XML data file cannot be modified

reopenTournament

protected void reopenTournament()
                         throws GoIOException
Opens a closed tournament so that its data can be modified.

Throws:
GoIOException - thrown if the XML data file cannot be modified

delete

protected void delete()
               throws TournamentOpenException
Deletes a closed tournament. Removes all the tournament files.

Throws:
TournamentOpenException - thrown if the tournament is not closed when trying to delete it

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
a string representation of the Tournament object