- All Known Implementing Classes:
LetterCluster,SymbolCluster
public interface CellCluster
The
CellCluster interface defines the contract for managing a
collection of Cell objects within the context of the hacking
mini-game. A cluster represents a group of cells that are treated as a
cohesive unit, with the ability to add, remove, and manipulate cells. The
interface provides various methods for interacting with the cluster,
including retrieving cells, checking the cluster's state, and performing
operations such as clearing or closing the cluster.
Implementations of this interface, such as SymbolCluster and
LetterCluster, typically represent specific types of clusters in the
game, where the cluster's behaviour may vary based on the type of cells it
contains. The CellCluster interface also includes mechanisms for
validating and closing clusters, ensuring that they meet specific criteria
before becoming immutable.
This interface is central to the game's model, interacting closely with the
Cell and AbstractCluster classes, and handling complex game
logic like cluster validation and interaction.- Version:
- 2.0
- Author:
- Kheagen Haskins
- See Also:
-
CellAbstractClusterSymbolClusterLetterClusterCellCluster.ClusterCloseException
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classTheClusterCloseExceptionclass represents an exception that is thrown when there is an issue closing a cell cluster within the hacking mini-game grid. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds aCellto this cluster.voidclear()Clears all cells from the cluster.voidclick()Handles the internal behaviour triggered by a click on this cluster.booleanclose()Closes and validates the cluster, meaning no more cells can be added, removed, or cleared.booleanDetermines if the givenCellargument belongs to this clustervoidfill(char c) Sets the content of each cell in the cluster to the specified character.voidForces the cluster to clear regardless of its state, removing allCellreferences within the internal collection.getCellAt(int index) Retrieves the Cell at the specified index.getCells()All Cells in this cluster.Retrieves the first cell in the cluster.intgetIndexOf(Cell cell) Retrieves the index of a specific cell within the cluster.Retrieves the last cell in the cluster.intgetSize()Retrieves the size of the cluster, which is the number of cells it contains.getText()Concatenates each cell's content into a single string and returns it.booleanisActive()Checks if the cluster is currently active.booleanisClosed()Checks if the cluster is closed.booleanisEmpty()Checks if the cluster is empty, i.e., contains no cells.booleanremoveCell(Cell cell) Removes theCellfrom this cluster.voidsetActive(boolean newState) Sets the active state of the cluster, activating all cells in the cluster or deactivating thembooleanvalidate()Validates the Cluster according to the specific implementation rules.
-
Method Details
-
getCells
All Cells in this cluster. -
getSize
int getSize()Retrieves the size of the cluster, which is the number of cells it contains.- Returns:
- the size of the cluster.
-
isActive
boolean isActive()Checks if the cluster is currently active. In the context of the game, an active cluster means that all its cells are treated as active.- Returns:
trueif the cluster is active,falseotherwise.
-
isClosed
boolean isClosed()Checks if the cluster is closed. A closed cluster cannot be modified further, meaning cells cannot be added, removed, or cleared.- Returns:
trueif the cluster is closed,falseotherwise.
-
isEmpty
boolean isEmpty()Checks if the cluster is empty, i.e., contains no cells.- Returns:
trueif the cluster is empty,falseotherwise.
-
getIndexOf
Retrieves the index of a specific cell within the cluster.- Parameters:
cell- the cell whose index is to be found.- Returns:
- the index of the cell within the cluster, or -1 if the cell is not found.
-
getCellAt
Retrieves the Cell at the specified index.- Parameters:
index- The index of the cell to return- Returns:
- the Cell at the specified index.
-
getText
String getText()Concatenates each cell's content into a single string and returns it. This is vital for guessing passwords and removing duds in the game.- Returns:
- a string representing the concatenated content of the cells in the cluster.
-
getFirstCell
Cell getFirstCell()Retrieves the first cell in the cluster. This is particularly important for symbol sets, where the first cell must be an open bracket type.- Returns:
- the first cell in the cluster.
-
getLastCell
Cell getLastCell()Retrieves the last cell in the cluster. This is particularly important for symbol sets, where the last cell must be a close bracket type.- Returns:
- the last cell in the cluster.
-
setActive
void setActive(boolean newState) Sets the active state of the cluster, activating all cells in the cluster or deactivating them- Parameters:
newState- the new state of the cluster
-
addCell
Adds aCellto this cluster.- Parameters:
cell- theCellto add- Returns:
trueif the operation was successful,falseotherwise.
-
removeCell
Removes theCellfrom this cluster.- Parameters:
cell- theCellto remove.- Returns:
trueif theCellobject was successfully removed from the cluster OR if theCellinstance was never part of the cluster, orfalseif theCellcannot be removed and remains in the cluster.
-
contains
Determines if the givenCellargument belongs to this clusterNote:Do not call this method directly after removing or adding a cell, as the corresponding methods to both of those operations returns true or false to indicate if the given Cell is within the cluster.
- Parameters:
cell- theCellto query.- Returns:
trueif this cluster contains the given cell.
-
validate
boolean validate()Validates the Cluster according to the specific implementation rules. This method should be called internally when the a client attempts to close the cluster.- Returns:
trueif the Cluster is valid,falseotherwise.
-
close
boolean close()Closes and validates the cluster, meaning no more cells can be added, removed, or cleared. The content of the cells can still be modified.- Returns:
falseif the cluster is empty, indicating an invalid cluster,trueif the cluster closes successfully.
-
clear
void clear()Clears all cells from the cluster. If the cluster is closed or otherwise immutable, it cannot be cleared. -
forceClear
void forceClear()Forces the cluster to clear regardless of its state, removing allCellreferences within the internal collection. -
fill
void fill(char c) Sets the content of each cell in the cluster to the specified character.- Parameters:
c- the character to set as the content of each cell.
-
click
void click()Handles the internal behaviour triggered by a click on this cluster. This typically involves deactivating the cluster and force clearing it. The exact behavior may vary depending on the implementation specifics.
-