Package tk.dmanstrator.connectfour.log
Class GameLog
- java.lang.Object
-
- tk.dmanstrator.connectfour.log.GameLog
-
public class GameLog extends java.lang.ObjectClass representing a log for a game.
-
-
Constructor Summary
Constructors Constructor Description GameLog()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddEntry(GameLogEntry entry)Adds a given entry to the internal game log.java.lang.StringgetAllEntriesAsString()Gets all entries from the log as a string separated with a newline.java.util.List<GameLogEntry>getEntries()Returns an immutable view of the current entries.java.lang.StringgetEntriesAsString(boolean valid)Gets all valid or invalid entries from the log as a string separated with a newline.GameLogEntrygetEntry(int index)Gets the log entry from a given position.java.util.Optional<GameLogEntry>getEntryFromRound(int roundNr)Gets the log entry from a specific round.java.util.List<GameLogEntry>getInvalidEntries()Returns all invalid entries from the log.GameLogEntrygetLastEntry()Gets the last entry from the log.java.util.List<GameLogEntry>getValidEntries()Returns all valid entries from the log.booleanremoveEntry(GameLogEntry entry)Removes a given entry from the internal game log.booleanremoveEntryFromRound(int roundNr)Removes the entry with a given round number from the log.java.lang.StringtoString()Returns all entries as a string.
-
-
-
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:
trueif entry was added, elsefalsesince 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:
trueif entry was removed, elsefalsesince 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:
trueif entry was removed, elsefalsesince 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,nullwill 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:
toStringin classjava.lang.Object- Returns:
- All entries as a string
- See Also:
getAllEntriesAsString()
-
-