- 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:
-
Cell
AbstractCell
SymbolCluster
-
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 newSymbolCell
instance containing the given content. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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
addToCluster
(CellCluster cluster) Adds thisSymbolCell
to the specifiedCellCluster
.void
click()
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 theCellCluster
where thisSymbolCell
is the first cell in the cluster.int
Gets the type index of the opening bracket contained in the cell.boolean
Checks if thisSymbolCell
is part of an activeCellCluster
.boolean
Checks if thisSymbolCell
is part of anyCellCluster
.boolean
isActive()
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
Determines whether the content of thisSymbolCell
matches the content of the specifiedCell
.boolean
removeCluster
(CellCluster cluster) Removes thisSymbolCell
from the specifiedCellCluster
.void
setActive
(boolean newState) Sets the active state of this cell.final void
setContent
(char c) Sets the content of the cell.boolean
sharesClusterWith
(Cell cell) Determines whether thisCell
shares the same cluster with another specifiedCell
.toString()
Returns a string representation of theLetterCell
object.
-
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 newSymbolCell
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 interfaceCell
- Parameters:
c
- the character to set as the content of the cell.- Throws:
IllegalArgumentException
- if the character is a letter.
-
addToCluster
Adds thisSymbolCell
to the specifiedCellCluster
.This method allows a
SymbolCell
to 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, anIllegalArgumentException
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
- TheCellCluster
to which thisSymbolCell
should be added. Must be an instance ofSymbolCluster
.- Returns:
true
if the cell was successfully added to the cluster.- Throws:
IllegalArgumentException
- If the givenCellCluster
is not aSymbolCluster
.
-
removeCluster
Removes thisSymbolCell
from 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
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
- TheCellCluster
from which thisSymbolCell
should be removed.- Returns:
true
if the cluster was successfully removed from the list of clusters, orfalse
if the cell was not part of the cluster.
-
getMainCluster
Returns theCellCluster
where thisSymbolCell
is the first cell in the cluster.- Returns:
- the
CellCluster
that contains thisSymbolCell
as its first element, ornull
if this cell is not the first in any cluster.
-
inActiveCluster
public boolean inActiveCluster()Checks if thisSymbolCell
is part of an activeCellCluster
.- Returns:
true
if this cell is in an active cluster,false
otherwise.
-
inCluster
public boolean inCluster()Checks if thisSymbolCell
is part of anyCellCluster
.- Returns:
true
if this cell is in at least one cluster,false
if it is not part of any cluster.
-
matches
Determines whether the content of thisSymbolCell
matches the content of the specifiedCell
.This method is specifically designed for
SymbolCell
objects and checks for a more nuanced match based on symbol types. If the providedCell
is not an instance ofSymbolCell
, the method immediately returnsfalse
.For
SymbolCell
s, the method considers the relationship between open and close types. If thisSymbolCell
is of an open type, it will match with anotherSymbolCell
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. -
toString
Returns a string representation of theLetterCell
object.This method overrides the
toString
method to provide a detailed description of theLetterCell
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. -
getContent
public char getContent()Retrieves the character content of this cell.- Specified by:
getContent
in 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:
addStateListener
in interfaceCell
- Parameters:
listener
- the listener to add; it must be an implementation ofChangeListener
that 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:
addContentListener
in interfaceCell
- Parameters:
listener
- theChangeListener
to be added; it will be triggered with aCharacter
when the cell's content changes
-
addClickListener
Adds a listener that will be notified whenever the value of the `clickCount` property changes.- Specified by:
addClickListener
in 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.
-