java.lang.Object
edu.ntnu.idatt2001.paths.models.Link

public class Link extends Object
Class link represents a link between two passages The reference is a string that points to the name of the passage
Version:
0.5 - 29.04.2023
Author:
Carl G. Callum G.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Link(String text, String reference)
    Instantiates a new Link.
    Link(String text, String reference, List<Action<?>> actions)
    Instantiates a new Link.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addAction(Action<?> action)
    Adds an action to the list of actions
    boolean
    Two links are equal if they have the same reference This is to make the required map of links to passages point links with different text and actions to the same passage
    Retrieves the list of actions
    Retrieves the passage reference.
    Retrieves the link text.
    int
    Returns a hashcode for the link based on the reference
    Returns a string representation of the link Uses text and reference example: Link 'Go to the kitchen' connects to 'kitchen'

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Link

      public Link(String text, String reference, List<Action<?>> actions) throws NullPointerException, IllegalArgumentException
      Instantiates a new Link. Both text and reference should be set, but reference can be null if there is no passage to link to.
      Parameters:
      text - String - text identification of the link
      reference - String - reference to the next passage
      actions - List - group of actions which are executed when the link is used
      Throws:
      NullPointerException - thrown if text is null, reference is null or actions is null or contains null
      IllegalArgumentException - thrown if text or reference is blank
    • Link

      public Link(String text, String reference) throws NullPointerException, IllegalArgumentException
      Instantiates a new Link. Both text and reference should be set, but reference can be null if there is no passage to link to.
      Parameters:
      text - String - text identification of the link
      reference - String - reference to the next passage
      Throws:
      NullPointerException - thrown if text or reference is null
      IllegalArgumentException - thrown if text or reference is only whitespace
  • Method Details

    • getText

      public String getText()
      Retrieves the link text.
      Returns:
      String - text identification of the link
    • getReference

      public String getReference()
      Retrieves the passage reference.
      Returns:
      String - reference to the next passage
    • getActions

      public List<Action<?>> getActions()
      Retrieves the list of actions
      Returns:
      List - list of actions to execute
    • addAction

      public void addAction(Action<?> action) throws NullPointerException
      Adds an action to the list of actions
      Parameters:
      action - Action - action to add
      Throws:
      NullPointerException - thrown if the action is null
    • toString

      public String toString()
      Returns a string representation of the link Uses text and reference example: Link 'Go to the kitchen' connects to 'kitchen'
      Overrides:
      toString in class Object
      Returns:
      String representation of the link
    • equals

      public boolean equals(Object o)
      Two links are equal if they have the same reference This is to make the required map of links to passages point links with different text and actions to the same passage
      Overrides:
      equals in class Object
      Parameters:
      o - Object - Any object equality checked with this link
      Returns:
      boolean - true if the links are equal, false if not
    • hashCode

      public int hashCode()
      Returns a hashcode for the link based on the reference
      Overrides:
      hashCode in class Object
      Returns:
      int - hashcode for the link