Record Class Node

java.lang.Object
java.lang.Record
it.auties.whatsapp.model.node.Node
Record Components:
description - a non-null String that describes the content of this node
attributes - a non-null Map that describes the metadata of this object
content - a nullable object: a List of Node, a String or a Number

public record Node(String description, Attributes attributes, Object content) extends Record
An immutable model class that represents the primary unit used by WhatsappWeb's WebSocket to communicate with the client
  • Field Details

    • description

      private final String description
      The field for the description record component.
    • attributes

      private final Attributes attributes
      The field for the attributes record component.
    • content

      private final Object content
      The field for the content record component.
  • Constructor Details

    • Node

      public Node(String description, Attributes attributes, Object content)
      Creates an instance of a Node record class.
      Parameters:
      description - the value for the description record component
      attributes - the value for the attributes record component
      content - the value for the content record component
  • Method Details

    • of

      public static Node of(String description)
      Constructs a Node that only provides a non-null tag
      Parameters:
      description - a non-null String that describes the data that this object holds
      Returns:
      a new node with the above characteristics
    • of

      public static Node of(String description, Object contentOrAttributes)
      Constructs a Node that provides a non-null tag and a nullable content
      Parameters:
      description - a non-null String that describes the data that this object holds
      contentOrAttributes - a nullable object, usually a List of Node, a String or a Number, or the request's attributes
      Returns:
      a new node with the above characteristics
    • of

      public static Node of(String description, Node... content)
      Constructs a Node that provides a non-null tag and a nullable content
      Parameters:
      description - a non-null String that describes the data that this object holds
      content - any number of non-null nodes
      Returns:
      a new node with the above characteristics
    • of

      public static Node of(String description, Map<String,Object> attributes, Node... content)
      Constructs a Node that provides a non-null tag and a nullable content
      Parameters:
      description - a non-null String that describes the data that this object holds
      attributes - the attributes of this node
      content - any number of non-null nodes
      Returns:
      a new node with the above characteristics
    • of

      public static Node of(String description, Attributes attributes, Node... content)
      Constructs a Node that provides a non-null tag and a nullable content
      Parameters:
      description - a non-null String that describes the data that this object holds
      attributes - the attributes of this node
      content - any number of non-null nodes
      Returns:
      a new node with the above characteristics
    • of

      public static Node of(String description, Map<String,Object> attributes, Object content)
      Constructs a Node that provides a non-null tag and a nullable content
      Parameters:
      description - a non-null String that describes the data that this object holds
      attributes - the attributes of this node
      content - any number of non-null nodes
      Returns:
      a new node with the above characteristics
    • of

      public static Node of(String description, Attributes attributes, Object content)
      Constructs a Node that provides a non-null tag and a nullable content
      Parameters:
      description - a non-null String that describes the data that this object holds
      attributes - the attributes of this node
      content - any number of non-null nodes
      Returns:
      a new node with the above characteristics
    • getAttributesOrThrow

      private static Attributes getAttributesOrThrow(Map<?,?> attributes)
    • getNodesOrThrow

      private static Collection<Node> getNodesOrThrow(Node[] entries)
    • getNodesOrThrow

      private static Collection<Node> getNodesOrThrow(Collection<?> entries)
    • contentAsString

      public Optional<String> contentAsString()
      Returns the content of this object as string
      Returns:
      an optional
    • contentAsBytes

      public Optional<byte[]> contentAsBytes()
      Returns the content of this object as bytes
      Returns:
      an optional
    • contentAsLong

      public OptionalLong contentAsLong()
      Returns the content of this object as a long
      Returns:
      an optional
    • contentAsDouble

      public OptionalDouble contentAsDouble()
      Returns the content of this object as a double
      Returns:
      an optional
    • contentAsBoolean

      public Optional<Boolean> contentAsBoolean()
      Returns the content of this object as a double
      Returns:
      an optional
    • hasNode

      public boolean hasNode(String description)
      Checks whether the child node with the given description whatsappOldEligible
      Returns:
      true if a child node with the given description whatsappOldEligible
    • children

      public LinkedList<Node> children()
      Returns a non-null list of children of this node
      Returns:
      a non-null list
    • hasDescription

      public boolean hasDescription(String description)
      Checks whether this node's description is equal to the one provided
      Parameters:
      description - the non-null description to check against
      Returns:
      a boolean
    • findNode

      public Optional<Node> findNode()
      Finds the first child node
      Returns:
      an optional
    • findNode

      public Optional<Node> findNode(String description)
      Returns the first node that matches the description provided
      Parameters:
      description - the nullable description
      Returns:
      an optional
    • findNodes

      public List<Node> findNodes(String description)
      Returns all the nodes that match the description provided
      Parameters:
      description - the nullable description
      Returns:
      an optional body, present if a newsletters was found
    • assertNode

      public void assertNode(String description, Supplier<String> error)
      Asserts that a child node with the provided description whatsappOldEligible
    • size

      public int size()
      Returns the size of this object
      Returns:
      an unsigned int
    • hasContent

      public boolean hasContent()
      Returns whether this object's content is non-null
      Returns:
      true if this object has a content
    • id

      public String id()
      Returns the nullable id of this node
      Returns:
      a nullable String
    • equals

      public boolean equals(Object other)
      Checks if this object is equal to another
      Specified by:
      equals in class Record
      Parameters:
      other - the reference object with which to compare
      Returns:
      whether other is equal to this object
    • toString

      public String toString()
      Converts this node into a String
      Specified by:
      toString in class Record
      Returns:
      a non null String
    • toJson

      public String toJson()
      Converts this node into a JSON String
      Returns:
      a non null String
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • description

      public String description()
      Returns the value of the description record component.
      Returns:
      the value of the description record component
    • attributes

      public Attributes attributes()
      Returns the value of the attributes record component.
      Returns:
      the value of the attributes record component
    • content

      public Object content()
      Returns the value of the content record component.
      Returns:
      the value of the content record component