- All Implemented Interfaces:
Cell
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:
-
CellAbstractCellSymbolCluster
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.slinky.hackmaster.model.cell.Cell
Cell.IllegalCharAddition -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final char[]Characters that are considered as closing brackets.static final char[]Characters that are considered as opening brackets. -
Constructor Summary
ConstructorsConstructorDescriptionSymbolCell(char content) Constructs a newSymbolCellinstance containing the given content. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddClickListener(javafx.beans.value.ChangeListener<? super Boolean> cl) Adds a listener that will be notified whenever the value of the `clickCount` property changes.voidaddContentListener(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.voidaddStateListener(javafx.beans.value.ChangeListener<? super Boolean> listener) Adds a listener to the `isActiveProperty` to monitor changes in its value.booleanaddToCluster(CellCluster cluster) Adds thisSymbolCellto the specifiedCellCluster.voidclick()Toggles the value of the `clickProperty`, thereby triggering any event listeners that are bound to this property.intGets the type index of the closing bracket contained in the cell.charRetrieves the character content of this cell.Returns theCellClusterwhere thisSymbolCellis the first cell in the cluster.intGets the type index of the opening bracket contained in the cell.booleanChecks if thisSymbolCellis part of an activeCellCluster.booleanChecks if thisSymbolCellis part of anyCellCluster.booleanisActive()Checks if the cell is currently active.booleanChecks if the cell contains a closing bracket type.booleanChecks if the cell contains an opening bracket type.booleanDetermines whether the content of thisSymbolCellmatches the content of the specifiedCell.booleanremoveCluster(CellCluster cluster) Removes thisSymbolCellfrom the specifiedCellCluster.voidsetActive(boolean newState) Sets the active state of this cell.final voidsetContent(char c) Sets the content of the cell.booleansharesClusterWith(Cell cell) Determines whether thisCellshares the same cluster with another specifiedCell.toString()Returns a string representation of theLetterCellobject.
-
Field Details
-
OPEN_TYPES
public static final char[] OPEN_TYPESCharacters that are considered as opening brackets. -
CLOSE_TYPES
public static final char[] CLOSE_TYPESCharacters that are considered as closing brackets.
-
-
Constructor Details
-
SymbolCell
public SymbolCell(char content) Constructs a newSymbolCellinstance 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:
trueif the cell contains an opening bracket,falseotherwise.
-
isCloseType
public boolean isCloseType()Checks if the cell contains a closing bracket type.- Returns:
trueif the cell contains a closing bracket,falseotherwise.
-
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:
setContentin interfaceCell- Parameters:
c- the character to set as the content of the cell.- Throws:
IllegalArgumentException- if the character is a letter.
-
addToCluster
Adds thisSymbolCellto the specifiedCellCluster.This method allows a
SymbolCellto be part of multiple clusters at the same time. It checks if the provided cluster is aSymbolCluster. If it is, the cell is added to the cluster. If not, anIllegalArgumentExceptionis 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- TheCellClusterto which thisSymbolCellshould be added. Must be an instance ofSymbolCluster.- Returns:
trueif the cell was successfully added to the cluster.- Throws:
IllegalArgumentException- If the givenCellClusteris not aSymbolCluster.
-
removeCluster
Removes thisSymbolCellfrom the specifiedCellCluster.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
SymbolCellcan 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- TheCellClusterfrom which thisSymbolCellshould be removed.- Returns:
trueif the cluster was successfully removed from the list of clusters, orfalseif the cell was not part of the cluster.
-
getMainCluster
Returns theCellClusterwhere thisSymbolCellis the first cell in the cluster.- Returns:
- the
CellClusterthat contains thisSymbolCellas its first element, ornullif this cell is not the first in any cluster.
-
inActiveCluster
public boolean inActiveCluster()Checks if thisSymbolCellis part of an activeCellCluster.- Returns:
trueif this cell is in an active cluster,falseotherwise.
-
inCluster
public boolean inCluster()Checks if thisSymbolCellis part of anyCellCluster.- Returns:
trueif this cell is in at least one cluster,falseif it is not part of any cluster.
-
matches
Determines whether the content of thisSymbolCellmatches the content of the specifiedCell.This method is specifically designed for
SymbolCellobjects and checks for a more nuanced match based on symbol types. If the providedCellis not an instance ofSymbolCell, the method immediately returnsfalse.For
SymbolCells, the method considers the relationship between open and close types. If thisSymbolCellis of an open type, it will match with anotherSymbolCellof 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. -
toString
Returns a string representation of theLetterCellobject.This method overrides the
toStringmethod to provide a detailed description of theLetterCellinstance. 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. -
getContent
public char getContent()Retrieves the character content of this cell.- Specified by:
getContentin interfaceCell- Returns:
- the character content of this cell.
-
isActive
public boolean isActive()Checks if the cell is currently active. -
setActive
public void setActive(boolean newState) Sets the active state of this cell. -
addStateListener
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:
addStateListenerin interfaceCell- Parameters:
listener- the listener to add; it must be an implementation ofChangeListenerthat can handle the value of typeBoolean.
-
addContentListener
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:
addContentListenerin interfaceCell- Parameters:
listener- theChangeListenerto be added; it will be triggered with aCharacterwhen the cell's content changes
-
addClickListener
Adds a listener that will be notified whenever the value of the `clickCount` property changes.- Specified by:
addClickListenerin interfaceCell- Parameters:
cl- the listener to be added, which should implement theChangeListener<? 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.
-