Record 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>(java.util.function.Predicate<ExpressionPiece> start, java.util.function.Predicate<ExpressionPiece> end, GroupSupplier<L extends ExpressionPiece,​R extends ExpressionPiece> supplier)
extends java.lang.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 Summary

    Constructors
    Constructor Description
    Grouper​(java.util.function.Predicate<ExpressionPiece> start, java.util.function.Predicate<ExpressionPiece> end, GroupSupplier<L,​R> supplier)
    Construct a grouper for specific pieces.
  • Method Summary

    Modifier and Type Method Description
    java.util.function.Predicate<ExpressionPiece> end()
    Returns the value of the end record component.
    boolean end​(ExpressionPiece toTest)
    Check if a piece matches the ending boundary of the group.
    boolean equals​(java.lang.Object o)
    Indicates whether some other object is "equal to" this one.
    ExpressionPiece group​(ExpressionPiece left, ExpressionPiece right, java.util.List<ExpressionPiece> content)
    Create a group from the given pieces.
    int hashCode()
    Returns a hash code value for this object.
    java.util.function.Predicate<ExpressionPiece> start()
    Returns the value of the start record component.
    boolean start​(ExpressionPiece toTest)
    Check if a piece matches the starting boundary of the group.
    GroupSupplier<L,​R> supplier()
    Returns the value of the supplier record component.
    java.lang.String toString()
    Returns a string representation of this record.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • 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, java.util.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 java.lang.String toString()
      Returns a string representation of this record. The representation contains the name of the type, followed by the name and value of each of the record components.
      Specified by:
      toString in class java.lang.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 java.lang.Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals​(java.lang.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 are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class java.lang.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 java.util.function.Predicate<ExpressionPiece> start()
      Returns the value of the start record component.
      Returns:
      the value of the start record component
    • end

      public java.util.function.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