Interface HasParents<T>

Type Parameters:
T - The type of the parent objects.
All Known Implementing Classes:
GLine, GPoint

public interface HasParents<T>
An interface for objects that can be part of a composite structure, allowing them to maintain references to their parent or owner objects.

This is particularly useful in a scene graph or a composite geometry system where child objects (e.g., a GPoint) need to notify their parent objects (e.g., a GLine or GTri) of changes. By implementing this interface, an object can track multiple parents that depend on its state.

Author:
Lehlogonolo Poole
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addParent(T parent)
    Adds a parent to this object's set of parents.
    default void
    addParents(T... parents)
    A convenience method to add multiple parent objects at once.
    default void
     
    Retrieves the set of all parent objects that this object belongs to.
    default boolean
    Checks if this object has at least one parent.
    void
    removeParent(T parent)
    Removes a parent from this object's set of parents.
  • Method Details

    • getParents

      HashSet<T> getParents()
      Retrieves the set of all parent objects that this object belongs to.
      Returns:
      A HashSet containing all parent objects. Using a Set ensures that a parent can only be added once.
    • addParent

      void addParent(T parent)
      Adds a parent to this object's set of parents.
      Parameters:
      parent - The parent object to add.
    • removeParent

      void removeParent(T parent)
      Removes a parent from this object's set of parents.
      Parameters:
      parent - The parent object to remove.
    • addParents

      default void addParents(T... parents)
      A convenience method to add multiple parent objects at once.
      Parameters:
      parents - A varargs array of parent objects to add.
    • hasParent

      default boolean hasParent()
      Checks if this object has at least one parent.
      Returns:
      true if the set of parents is not empty, false otherwise.
    • clearParents

      default void clearParents()