Class GameLog


  • public class GameLog
    extends java.lang.Object
    Class representing a log for a game.
    • Constructor Detail

      • GameLog

        public GameLog()
    • Method Detail

      • addEntry

        public boolean addEntry​(GameLogEntry entry)
        Adds a given entry to the internal game log. If an entry with the round number already exists, it won't be added. Invalid entries can be added multiple times.
        Parameters:
        entry - Entry to add to the game log
        Returns:
        true if entry was added, else false since it was already in the log
      • removeEntry

        public boolean removeEntry​(GameLogEntry entry)
        Removes a given entry from the internal game log.
        Parameters:
        entry - Entry to remove from the game log
        Returns:
        true if entry was removed, else false since it wasn't in the log
      • removeEntryFromRound

        public boolean removeEntryFromRound​(int roundNr)
        Removes the entry with a given round number from the log.
        Parameters:
        roundNr - Round number of entry to remove from the game log
        Returns:
        true if entry was removed, else false since it wasn't in the log
      • getEntry

        public GameLogEntry getEntry​(int index)
        Gets the log entry from a given position. If the given index is out of bounds, null will be returned.
        Parameters:
        index - Index to access in the internal log
        Returns:
        Possibly null entry at the given index.
      • getEntryFromRound

        public java.util.Optional<GameLogEntry> getEntryFromRound​(int roundNr)
        Gets the log entry from a specific round.
        Parameters:
        roundNr - Round number to check the game log for
        Returns:
        Possibly empty optional containing the entry from the given round
      • getLastEntry

        public GameLogEntry getLastEntry()
        Gets the last entry from the log.
        Returns:
        Possibly null entry being the last entry from the log
      • getEntries

        public java.util.List<GameLogEntry> getEntries()
        Returns an immutable view of the current entries.
        Returns:
        An immutable view of the current entries
      • getValidEntries

        public java.util.List<GameLogEntry> getValidEntries()
        Returns all valid entries from the log.
        Returns:
        All valid entries from the log
      • getInvalidEntries

        public java.util.List<GameLogEntry> getInvalidEntries()
        Returns all invalid entries from the log.
        Returns:
        All invalid entries from the log
      • getEntriesAsString

        public java.lang.String getEntriesAsString​(boolean valid)
        Gets all valid or invalid entries from the log as a string separated with a newline.
        Parameters:
        valid - Flag determining if valid or invalid entries are wanted
        Returns:
        (In)valid entries from the log as a string
      • getAllEntriesAsString

        public java.lang.String getAllEntriesAsString()
        Gets all entries from the log as a string separated with a newline.
        Returns:
        All entries from the log as a string
      • toString

        public java.lang.String toString()
        Returns all entries as a string.
        Overrides:
        toString in class java.lang.Object
        Returns:
        All entries as a string
        See Also:
        getAllEntriesAsString()