Record Class PatternMatch
java.lang.Object
java.lang.Record
cloud.opencode.base.string.match.PatternMatch
- Record Components:
pattern- the pattern that was matched | 匹配的模式start- the start index in the text (inclusive) | 在文本中的起始索引(包含)end- the end index in the text (exclusive) | 在文本中的结束索引(不包含)Security | 安全性:
- Thread-safe: Yes (record is immutable) - 线程安全: 是(记录不可变)
matchedText- the actual text that was matched | 实际匹配的文本
Pattern Match Result - Represents a pattern match found in text
模式匹配结果 - 表示在文本中找到的模式匹配
Contains the matched pattern, its position, and the actual matched text.
包含匹配的模式、位置和实际匹配的文本。
Features | 主要功能:
- Match position and length tracking - 匹配位置和长度跟踪
- Overlap detection between matches - 匹配重叠检测
- Text extraction from original source - 从原始源提取文本
Usage Examples | 使用示例:
PatternMatch match = ...;
String pattern = match.pattern(); // The pattern that matched
int start = match.start(); // Start index (inclusive)
int end = match.end(); // End index (exclusive)
String text = match.matchedText(); // The actual matched text
int length = match.length(); // Length of the match
- Since:
- JDK 25, opencode-base-string V1.2.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionPatternMatch(String pattern, int start, int end, String matchedText) Creates an instance of aPatternMatchrecord class. -
Method Summary
Modifier and TypeMethodDescriptionbooleancontains(PatternMatch other) Checks if this match contains another.intend()Returns the value of theendrecord component.final booleanIndicates whether some other object is "equal to" this one.extractFrom(String originalText) Extracts the matched portion from the original text.final inthashCode()Returns a hash code value for this object.intlength()Returns the length of the match.Returns the value of thematchedTextrecord component.booleanoverlaps(PatternMatch other) Checks if this match overlaps with another.pattern()Returns the value of thepatternrecord component.intstart()Returns the value of thestartrecord component.Returns a formatted string representation.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
PatternMatch
Creates an instance of aPatternMatchrecord class.- Parameters:
pattern- the value for thepatternrecord componentstart- the value for thestartrecord componentend- the value for theendrecord componentmatchedText- the value for thematchedTextrecord component
-
-
Method Details
-
length
public int length()Returns the length of the match. 返回匹配的长度。- Returns:
- match length | 匹配长度
-
overlaps
Checks if this match overlaps with another. 检查此匹配是否与另一个重叠。- Parameters:
other- the other match | 另一个匹配- Returns:
- true if overlapping | 如果重叠则返回true
-
contains
Checks if this match contains another. 检查此匹配是否包含另一个。- Parameters:
other- the other match | 另一个匹配- Returns:
- true if this contains other | 如果此匹配包含另一个则返回true
-
extractFrom
-
toDisplayString
Returns a formatted string representation. 返回格式化的字符串表示。- Returns:
- formatted string | 格式化字符串
-
toString
-
hashCode
-
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. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
pattern
-
start
-
end
-
matchedText
Returns the value of thematchedTextrecord component.- Returns:
- the value of the
matchedTextrecord component
-