Class Spiel

java.lang.Object
net.bjmsw.hda.vs.model.db.Spiel

public class Spiel extends Object
The Spiel class represents a game between two teams in the database.

Works like a simple mini ORM.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private long
     
    private double
     
    private double
     
    private String
     
    private double
     
    private String
     
    private int
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Spiel(long id, String team1name, String team2name, int winningTeam, double team0chance, double team1chance, double team2chance)
    Represents a Spiel (game) with unique ID, two team names, winning team, and chances for each team.
     
    Spiel(String team1name, String team2name, double team0chance, double team1chance, double team2chance)
    Represents a Spiel (game) with two team names and chances for each team.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    endGame(int winningTeam)
    Updates the winning team of the game and saves it to the database.
    static Spiel
    fromDB(long id)
    Retrieves a Spiel (game) object from the database based on its unique ID.
    static Map<Long,Spiel>
    Retrieves all Spiel (game) objects from the database.
    long
    Gets the unique ID of the Spiel (game).
    double
    Gets the chance of a draw.
    double
    Gets the chance of team 1 winning.
    Gets the name of team 1.
    double
    Gets the chance of team 2 winning.
    Gets the name of team 2.
    int
    Gets the winning team of the game.
    boolean
    Inserts the Spiel (game) object into the database.
    boolean
    Checks if the game has ended.
    boolean
    Checks if the Spiel (game) object is already in the database.

    Methods inherited from class java.lang.Object

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

    • id

      private long id
    • team1name

      private String team1name
    • team2name

      private String team2name
    • winningTeam

      private int winningTeam
    • team0chance

      private double team0chance
    • team1chance

      private double team1chance
    • team2chance

      private double team2chance
  • Constructor Details

    • Spiel

      private Spiel(long id, String team1name, String team2name, int winningTeam, double team0chance, double team1chance, double team2chance)
      Represents a Spiel (game) with unique ID, two team names, winning team, and chances for each team.

      This is a private constructor that initializes the Spiel object with the given parameters from the database.

      Parameters:
      id - The unique ID of the Spiel.
      team1name - The name of team 1.
      team2name - The name of team 2.
      winningTeam - The winning team (team 1, team 2, or draw).
      team0chance - The chance of a draw.
      team1chance - The chance of team 1 winning.
      team2chance - The chance of team 2 winning.
    • Spiel

      public Spiel(String team1name, String team2name, double team0chance, double team1chance, double team2chance)
      Represents a Spiel (game) with two team names and chances for each team.

      This is the public constructor that initializes the Spiel object with the given parameters. It will not be automatically inserted into the database. To insert the Spiel object into the database, call the insert() method.

      Parameters:
      team1name - The name of team 1.
      team2name - The name of team 2.
      team0chance - The chance of a draw.
      team1chance - The chance of team 1 winning.
      team2chance - The chance of team 2 winning.
  • Method Details

    • fromDB

      public static Spiel fromDB(long id)
      Retrieves a Spiel (game) object from the database based on its unique ID.
      Parameters:
      id - The unique ID of the Spiel to retrieve from the database.
      Returns:
      The Spiel object with the given ID if found, otherwise null.
    • getAll

      public static Map<Long,Spiel> getAll()
      Retrieves all Spiel (game) objects from the database.
      Returns:
      A map of Spiel objects, where the key is the unique ID of each Spiel and the value is the corresponding Spiel object. Returns null if there was an error fetching Spiele from the database.
    • insert

      public boolean insert()
      Inserts the Spiel (game) object into the database.
      Returns:
      true if the Spiel was successfully inserted into the database, false otherwise.
    • endGame

      public void endGame(int winningTeam) throws SQLException
      Updates the winning team of the game and saves it to the database.
      Parameters:
      winningTeam - The winning team of the game (0 for draw, 1 for team 1, 2 for team 2).
      Throws:
      SQLException - If there is an error executing the database query.
      IllegalArgumentException - If the winningTeam parameter is not 0, 1, or 2.
    • getTeam1name

      public String getTeam1name()
      Gets the name of team 1.
      Returns:
      The name of team 1.
    • getTeam2name

      public String getTeam2name()
      Gets the name of team 2.
      Returns:
      The name of team 2.
    • isInDb

      public boolean isInDb()
      Checks if the Spiel (game) object is already in the database.
      Returns:
      true if the Spiel is in the database, false otherwise.
    • getId

      public long getId()
      Gets the unique ID of the Spiel (game).
      Returns:
      The unique ID of the Spiel.
    • getWinningTeam

      public int getWinningTeam()
      Gets the winning team of the game.
      Returns:
      The winning team of the game (0 for draw, 1 for team 1, 2 for team 2).
    • isEnded

      public boolean isEnded()
      Checks if the game has ended.
      Returns:
      true if the game has ended, false otherwise.
    • getTeam0chance

      public double getTeam0chance()
      Gets the chance of a draw.
      Returns:
      The chance of a draw.
    • getTeam1chance

      public double getTeam1chance()
      Gets the chance of team 1 winning.
      Returns:
      The chance of team 1 winning.
    • getTeam2chance

      public double getTeam2chance()
      Gets the chance of team 2 winning.
      Returns:
      The chance of team 2 winning.