Record Class Grouper<L extends ExpressionPiece,R extends ExpressionPiece>

java.lang.Object
java.lang.Record
net.diversionmc.parser.group.Grouper<L,R>
Type Parameters:
L - Start boundary.
R - End boundary.

public record Grouper<L extends ExpressionPiece,R extends ExpressionPiece>(Predicate<ExpressionPiece> start, Predicate<ExpressionPiece> end, GroupSupplier<L extends ExpressionPiece,R extends ExpressionPiece> supplier) extends Record

When all characters are converted successfully into Expression Pieces, some of the pieces are allowed to be converted again using a second pass. This time sequences of pieces (Content) surrounded by some specific pieces (Group Boundaries) can be grouped up into lists (into Group Pieces).

The mechanism that performs such an operation is called a Grouper. It consists of two predicates (Start and End) which define boundaries for a group and convert the content into the group pieces using a function called Group Supplier.

  • Constructor Details

  • Method Details

    • start

      public boolean start(ExpressionPiece toTest)
      Check if a piece matches the starting boundary of the group.
      Parameters:
      toTest - Piece to check.
      Returns:
      True if a piece is a start boundary.
    • end

      public boolean end(ExpressionPiece toTest)
      Check if a piece matches the ending boundary of the group.
      Parameters:
      toTest - Piece to check.
      Returns:
      True if a piece is an end boundary.
    • group

      public ExpressionPiece group(ExpressionPiece left, ExpressionPiece right, List<ExpressionPiece> content)
      Create a group from the given pieces.
      Parameters:
      left - Left boundary. Make sure it matches start(ExpressionPiece)
      right - Right boundary. Make sure it matches end(ExpressionPiece)
      content - Pieces inside the group.
      Returns:
      Group made from the pieces.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • start

      public Predicate<ExpressionPiece> start()
      Returns the value of the start record component.
      Returns:
      the value of the start record component
    • end

      public Predicate<ExpressionPiece> end()
      Returns the value of the end record component.
      Returns:
      the value of the end record component
    • supplier

      public GroupSupplier<L,R> supplier()
      Returns the value of the supplier record component.
      Returns:
      the value of the supplier record component