Package net.diversionmc.parser.group
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 Summary
ConstructorsConstructorDescriptionGrouper(Predicate<ExpressionPiece> start, Predicate<ExpressionPiece> end, GroupSupplier<L, R> supplier) Construct a grouper for specific pieces. -
Method Summary
Modifier and TypeMethodDescriptionend()Returns the value of theendrecord component.booleanend(ExpressionPiece toTest) Check if a piece matches the ending boundary of the group.final booleanIndicates whether some other object is "equal to" this one.group(ExpressionPiece left, ExpressionPiece right, List<ExpressionPiece> content) Create a group from the given pieces.final inthashCode()Returns a hash code value for this object.start()Returns the value of thestartrecord component.booleanstart(ExpressionPiece toTest) Check if a piece matches the starting boundary of the group.supplier()Returns the value of thesupplierrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
Grouper
public Grouper(Predicate<ExpressionPiece> start, Predicate<ExpressionPiece> end, GroupSupplier<L, R> supplier) Construct a grouper for specific pieces.- Parameters:
start- Start boundary check.end- End bounary check.supplier- Group supplier.- Throws:
ParserException- If any of the parameters are null.- See Also:
-
-
Method Details
-
start
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
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 matchesstart(ExpressionPiece)right- Right boundary. Make sure it matchesend(ExpressionPiece)content- Pieces inside the group.- Returns:
- Group made from the pieces.
-
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. -
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. -
equals
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 withObjects::equals(Object,Object). -
start
Returns the value of thestartrecord component.- Returns:
- the value of the
startrecord component
-
end
Returns the value of theendrecord component.- Returns:
- the value of the
endrecord component
-
supplier
Returns the value of thesupplierrecord component.- Returns:
- the value of the
supplierrecord component
-