Overview
TheElection class is a core domain entity that represents an election in the Consensus e-voting platform. It encapsulates all election-related data and business logic, including candidate management, status transitions, and active state validation.
Constructor
Unique identifier for the election
Name of the election (cannot be empty)
Type of election voting system. Supported values:
ElectionType.FPTP- First Past The PostElectionType.STV- Single Transferable VoteElectionType.AV- Alternative VoteElectionType.PREFERENTIAL- Preferential voting
Date when the election begins
Date when the election ends
Detailed description of the election
Current status of the election. Defaults to
DRAFT if not specified.Example
Properties
Unique identifier for the election (read-only)
Name of the election. Can be updated via setter with validation.
Type of election voting system (read-only)
Current status of the election. Can be updated via setter to transition between states.
Date when the election begins (read-only)
Date when the election ends (read-only)
Detailed description of the election (read-only)
Array of candidates in the election. Returns a copy for encapsulation (read-only array).
Setters
name
Updates the election name with validation.- Throws
Errorif name is empty or contains only whitespace
status
Updates the election status.DRAFT→ACTIVEACTIVE→CLOSEDDRAFT→CLOSED
Methods
isActive()
Checks if the election is currently active.true if the election status is ACTIVE and the current date is within the start and end dates.
Example:
isClosed()
Checks if the election is closed.true if the election status is CLOSED.
addCandidate()
Adds a candidate to the election.The candidate to add to the election
Error if the election status is not DRAFT.
Note: Candidates can only be added to draft elections.
removeCandidate()
Removes a candidate from the election by ID.The ID of the candidate to remove
Error if the election status is not DRAFT.
Note: Candidates can only be removed from draft elections.