Interface CellCluster

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:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static class 
    The ClusterCloseException 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 Type
    Method
    Description
    boolean
    addCell(Cell cell)
    Adds a Cell to this cluster.
    void
    Clears all cells from the cluster.
    void
    Handles the internal behaviour triggered by a click on this cluster.
    boolean
    Closes and validates the cluster, meaning no more cells can be added, removed, or cleared.
    boolean
    contains(Cell cell)
    Determines if the given Cell argument belongs to this cluster
    void
    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 all Cell references within the internal collection.
    getCellAt(int index)
    Retrieves the Cell at the specified index.
    All Cells in this cluster.
    Retrieves the first cell in the cluster.
    int
    Retrieves the index of a specific cell within the cluster.
    Retrieves the last cell in the cluster.
    int
    Retrieves the size of the cluster, which is the number of cells it contains.
    Concatenates each cell's content into a single string and returns it.
    boolean
    Checks if the cluster is currently active.
    boolean
    Checks if the cluster is closed.
    boolean
    Checks if the cluster is empty, i.e., contains no cells.
    boolean
    Removes the Cell from this cluster.
    void
    setActive(boolean newState)
    Sets the active state of the cluster, activating all cells in the cluster or deactivating them
    boolean
    Validates the Cluster according to the specific implementation rules.
  • Method Details

    • getCells

      List<Cell> getCells()
      All Cells in this cluster.
      Returns:
      A List of 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

      int getIndexOf(Cell cell)
      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

      Cell getCellAt(int index)
      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

      boolean addCell(Cell cell)
      Adds a Cell to this cluster.
      Parameters:
      cell - the Cell to add
      Returns:
      true if the operation was successful, false otherwise.
    • removeCell

      boolean removeCell(Cell cell)
      Removes the Cell from this cluster.
      Parameters:
      cell - the Cell to remove.
      Returns:
      true if the Cell object was successfully removed from the cluster OR if the Cell instance was never part of the cluster, or false if the Cell cannot be removed and remains in the cluster.
    • contains

      boolean contains(Cell cell)
      Determines if the given Cell argument belongs to this cluster

      Note: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 - the Cell 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 all Cell 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.