- 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:
-
Cell
AbstractCluster
SymbolCluster
LetterCluster
CellCluster.ClusterCloseException
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic class
TheClusterCloseException
class 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 TypeMethodDescriptionboolean
Adds aCell
to this cluster.void
clear()
Clears all cells from the cluster.void
click()
Handles the internal behaviour triggered by a click on this cluster.boolean
close()
Closes and validates the cluster, meaning no more cells can be added, removed, or cleared.boolean
Determines if the givenCell
argument belongs to this clustervoid
fill
(char c) Sets the content of each cell in the cluster to the specified character.void
Forces the cluster to clear regardless of its state, removing allCell
references 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.int
getIndexOf
(Cell cell) Retrieves the index of a specific cell within the cluster.Retrieves the last cell in the cluster.int
getSize()
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.boolean
isActive()
Checks if the cluster is currently active.boolean
isClosed()
Checks if the cluster is closed.boolean
isEmpty()
Checks if the cluster is empty, i.e., contains no cells.boolean
removeCell
(Cell cell) Removes theCell
from this cluster.void
setActive
(boolean newState) Sets the active state of the cluster, activating all cells in the cluster or deactivating themboolean
validate()
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:
true
if the cluster is active,false
otherwise.
-
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:
true
if the cluster is closed,false
otherwise.
-
isEmpty
boolean isEmpty()Checks if the cluster is empty, i.e., contains no cells.- Returns:
true
if the cluster is empty,false
otherwise.
-
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 aCell
to this cluster.- Parameters:
cell
- theCell
to add- Returns:
true
if the operation was successful,false
otherwise.
-
removeCell
Removes theCell
from this cluster.- Parameters:
cell
- theCell
to remove.- Returns:
true
if theCell
object was successfully removed from the cluster OR if theCell
instance was never part of the cluster, orfalse
if theCell
cannot be removed and remains in the cluster.
-
contains
Determines if the givenCell
argument 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
- theCell
to query.- Returns:
true
if 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:
true
if the Cluster is valid,false
otherwise.
-
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:
false
if the cluster is empty, indicating an invalid cluster,true
if 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 allCell
references 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.
-