Class SymbolCell

java.lang.Object
com.slinky.hackmaster.model.cell.SymbolCell
All Implemented Interfaces:
Cell

public class SymbolCell extends Object
The SymbolCell class is a specialised subclass of AbstractCell designed to hold non-letter ASCII characters, particularly symbols. It supports functionality to identify and manage bracket types (both opening and closing) and interacts with CellCluster instances, allowing for cluster-related operations specific to symbol cells.

This class ensures that only valid non-letter ASCII characters can be set as the content of the cell, and it throws an exception if an invalid character (such as a letter) is added. It also provides methods to determine if the cell contains an opening or closing bracket and to manage its membership within CellCluster instances.

The SymbolCell can only be added to clusters that are instances of SymbolCluster, and it offers functionality to check if it is part of any active or non-active clusters.

Version:
3.0
Author:
Kheagen Haskins
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface com.slinky.hackmaster.model.cell.Cell

    Cell.IllegalCharAddition
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final char[]
    Characters that are considered as closing brackets.
    static final char[]
    Characters that are considered as opening brackets.
  • Constructor Summary

    Constructors
    Constructor
    Description
    SymbolCell(char content)
    Constructs a new SymbolCell instance containing the given content.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addClickListener(javafx.beans.value.ChangeListener<? super Boolean> cl)
    Adds a listener that will be notified whenever the value of the `clickCount` property changes.
    void
    addContentListener(javafx.beans.value.ChangeListener<? super Character> listener)
    Registers a listener that will be notified when the content of the cell changes, such as when it is filled or modified.
    void
    addStateListener(javafx.beans.value.ChangeListener<? super Boolean> listener)
    Adds a listener to the `isActiveProperty` to monitor changes in its value.
    boolean
    Adds this SymbolCell to the specified CellCluster.
    void
    Toggles the value of the `clickProperty`, thereby triggering any event listeners that are bound to this property.
    int
    Gets the type index of the closing bracket contained in the cell.
    char
    Retrieves the character content of this cell.
    Returns the CellCluster where this SymbolCell is the first cell in the cluster.
    int
    Gets the type index of the opening bracket contained in the cell.
    boolean
    Checks if this SymbolCell is part of an active CellCluster.
    boolean
    Checks if this SymbolCell is part of any CellCluster.
    boolean
    Checks if the cell is currently active.
    boolean
    Checks if the cell contains a closing bracket type.
    boolean
    Checks if the cell contains an opening bracket type.
    boolean
    matches(Cell cell)
    Determines whether the content of this SymbolCell matches the content of the specified Cell.
    boolean
    Removes this SymbolCell from the specified CellCluster.
    void
    setActive(boolean newState)
    Sets the active state of this cell.
    final void
    setContent(char c)
    Sets the content of the cell.
    boolean
    Determines whether this Cell shares the same cluster with another specified Cell.
    Returns a string representation of the LetterCell object.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • OPEN_TYPES

      public static final char[] OPEN_TYPES
      Characters that are considered as opening brackets.
    • CLOSE_TYPES

      public static final char[] CLOSE_TYPES
      Characters that are considered as closing brackets.
  • Constructor Details

    • SymbolCell

      public SymbolCell(char content)
      Constructs a new SymbolCell instance containing the given content. The content must be a valid non-letter ASCII character.
      Parameters:
      content - the content this cell should contain.
  • Method Details

    • isOpenType

      public boolean isOpenType()
      Checks if the cell contains an opening bracket type.
      Returns:
      true if the cell contains an opening bracket, false otherwise.
    • isCloseType

      public boolean isCloseType()
      Checks if the cell contains a closing bracket type.
      Returns:
      true if the cell contains a closing bracket, false otherwise.
    • getOpenType

      public int getOpenType()
      Gets the type index of the opening bracket contained in the cell.
      Returns:
      the type index of the opening bracket, or -1 if none.
    • getCloseType

      public int getCloseType()
      Gets the type index of the closing bracket contained in the cell.
      Returns:
      the type index of the closing bracket, or -1 if none.
    • setContent

      public final void setContent(char c)
      Sets the content of the cell. The content must be a non-letter ASCII character. This method also determines if the character is an opening or closing bracket.
      Specified by:
      setContent in interface Cell
      Parameters:
      c - the character to set as the content of the cell.
      Throws:
      IllegalArgumentException - if the character is a letter.
    • addToCluster

      public boolean addToCluster(CellCluster cluster)
      Adds this SymbolCell to the specified CellCluster.

      This method allows a SymbolCell to be part of multiple clusters at the same time. It checks if the provided cluster is a SymbolCluster. If it is, the cell is added to the cluster. If not, an IllegalArgumentException is thrown.

      The method also adds the provided cluster to this cell's internal list of clusters, keeping track of all the clusters this cell belongs to.

      Parameters:
      cluster - The CellCluster to which this SymbolCell should be added. Must be an instance of SymbolCluster.
      Returns:
      true if the cell was successfully added to the cluster.
      Throws:
      IllegalArgumentException - If the given CellCluster is not a SymbolCluster.
    • removeCluster

      public boolean removeCluster(CellCluster cluster)
      Removes this SymbolCell from the specified CellCluster.

      This method removes the provided cluster from this cell's internal list of clusters, effectively disassociating the cell from that cluster. If the cell is not part of the given cluster, the method does nothing.

      Since a SymbolCell can belong to multiple clusters, this method ensures that only the specified cluster is removed, leaving the cell's membership in other clusters unaffected.

      Note: This method only removes the reference to the cluster from the cell but does not remove the cell from the cluster. This is by design, as this method should be invoked by the owning cluster when it is being cleared or when the cluster itself is managing the removal process. The actual removal of the cell from the cluster should be handled by the cluster's management logic.

      Parameters:
      cluster - The CellCluster from which this SymbolCell should be removed.
      Returns:
      true if the cluster was successfully removed from the list of clusters, or false if the cell was not part of the cluster.
    • getMainCluster

      public CellCluster getMainCluster()
      Returns the CellCluster where this SymbolCell is the first cell in the cluster.
      Returns:
      the CellCluster that contains this SymbolCell as its first element, or null if this cell is not the first in any cluster.
    • inActiveCluster

      public boolean inActiveCluster()
      Checks if this SymbolCell is part of an active CellCluster.
      Returns:
      true if this cell is in an active cluster, false otherwise.
    • inCluster

      public boolean inCluster()
      Checks if this SymbolCell is part of any CellCluster.
      Returns:
      true if this cell is in at least one cluster, false if it is not part of any cluster.
    • matches

      public boolean matches(Cell cell)
      Determines whether the content of this SymbolCell matches the content of the specified Cell.

      This method is specifically designed for SymbolCell objects and checks for a more nuanced match based on symbol types. If the provided Cell is not an instance of SymbolCell, the method immediately returns false.

      For SymbolCells, the method considers the relationship between open and close types. If this SymbolCell is of an open type, it will match with another SymbolCell of the corresponding close type, and vice versa. The match occurs if the open type of one cell matches the close type of the other or the close type of one matches the open type of the other.

      Specified by:
      matches in interface Cell
      Parameters:
      cell - The Cell to compare with this SymbolCell.
      Returns:
      true if the SymbolCells are of corresponding open and close types; false otherwise.
    • toString

      public String toString()
      Returns a string representation of the LetterCell object.

      This method overrides the toString method to provide a detailed description of the LetterCell instance. The output includes the content of the cell enclosed in square brackets, followed by a list of clusters to which the cell belongs. If the cell is not part of any clusters, the output will indicate "NONE"; otherwise, it will display the text content of each associated cluster.

      Overrides:
      toString in class Object
      Returns:
      A string that represents the LetterCell, including its content and associated clusters' information.
    • sharesClusterWith

      public boolean sharesClusterWith(Cell cell)
      Description copied from interface: Cell
      Determines whether this Cell shares the same cluster with another specified Cell.

      This method checks if both Cell instances are part of the same cluster. A cluster is a group of cells that are logically connected in the context of the game. This connection could be based on proximity, content similarity, or game-specific rules.

      Parameters:
      cell - the Cell to compare with this instance for cluster membership.
      Returns:
      true if this Cell and the specified Cell are part of the same cluster; false otherwise.
    • getContent

      public char getContent()
      Retrieves the character content of this cell.
      Specified by:
      getContent in interface Cell
      Returns:
      the character content of this cell.
    • isActive

      public boolean isActive()
      Checks if the cell is currently active.
      Specified by:
      isActive in interface Cell
      Returns:
      true if the cell is active, false otherwise.
    • setActive

      public void setActive(boolean newState)
      Sets the active state of this cell.
      Specified by:
      setActive in interface Cell
      Parameters:
      newState - the new active state of this cell.
    • addStateListener

      public void addStateListener(javafx.beans.value.ChangeListener<? super Boolean> listener)
      Adds a listener to the `isActiveProperty` to monitor changes in its value. The listener will be notified whenever the value of the `isActiveProperty` changes.
      Specified by:
      addStateListener in interface Cell
      Parameters:
      listener - the listener to add; it must be an implementation of ChangeListener that can handle the value of type Boolean.
    • addContentListener

      public void addContentListener(javafx.beans.value.ChangeListener<? super Character> listener)
      Registers a listener that will be notified when the content of the cell changes, such as when it is filled or modified. The listener will receive a notification whenever the character content within the cell is altered.
      Specified by:
      addContentListener in interface Cell
      Parameters:
      listener - the ChangeListener to be added; it will be triggered with a Character when the cell's content changes
    • addClickListener

      public void addClickListener(javafx.beans.value.ChangeListener<? super Boolean> cl)
      Adds a listener that will be notified whenever the value of the `clickCount` property changes.
      Specified by:
      addClickListener in interface Cell
      Parameters:
      cl - the listener to be added, which should implement the ChangeListener<? super Number> interface. This listener will be notified with the new value whenever the `clickCount` changes.
    • click

      public void click()
      Toggles the value of the `clickProperty`, thereby triggering any event listeners that are bound to this property. When called, this method switches the current state of the `clickProperty` to its opposite value, which causes any registered listeners to react accordingly.
      Specified by:
      click in interface Cell