Package net.diversionmc.parser.group
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 theendrecord component.booleanend(ExpressionPiece toTest)Check if a piece matches the ending boundary of the group.booleanequals(java.lang.Object o)Indicates whether some other object is "equal to" this one.ExpressionPiecegroup(ExpressionPiece left, ExpressionPiece right, java.util.List<ExpressionPiece> content)Create a group from the given pieces.inthashCode()Returns a hash code value for this object.java.util.function.Predicate<ExpressionPiece>start()Returns the value of thestartrecord component.booleanstart(ExpressionPiece toTest)Check if a piece matches the starting boundary of the group.GroupSupplier<L,R>supplier()Returns the value of thesupplierrecord component.java.lang.StringtoString()Returns a string representation of this record.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Constructor Details
-
Grouper
public Grouper(java.util.function.Predicate<ExpressionPiece> start, java.util.function.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:
Parser.group(Predicate, Predicate, GroupSupplier)
-
-
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, java.util.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
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:
toStringin classjava.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:
hashCodein classjava.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 withObjects::equals(Object,Object).- Specified by:
equalsin classjava.lang.Record- Parameters:
o- the object with which to compare- Returns:
trueif this object is the same as theoargument;falseotherwise.
-
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
-