Class BoundedCharSequence
java.lang.Object
io.jenkins.plugins.mcp.server.extensions.util.BoundedCharSequence
- All Implemented Interfaces:
CharSequence
Text that gives up once it has been read a given number of times.
Handy for putting a ceiling on a regex match: the matcher reads every character it compares
through charAt(int), so counting those is a cheap way to cap the work.
try {
return pattern.matcher(new BoundedCharSequence(line, budget)).find();
} catch (BoundedCharSequence.BudgetExceededException e) {
// gave up on this line
}
Use one per piece of text, from a single thread.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThrown when the budget runs out. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncharcharAt(int index) longgetReads()How many reads have been used so far.intlength()subSequence(int start, int end) toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.CharSequence
chars, codePoints, isEmpty
-
Constructor Details
-
BoundedCharSequence
- Parameters:
delegate- the text to readbudget- how many reads to allow; must be positive
-
-
Method Details
-
getReads
public long getReads()How many reads have been used so far. -
charAt
public char charAt(int index) - Specified by:
charAtin interfaceCharSequence
-
length
public int length()- Specified by:
lengthin interfaceCharSequence
-
subSequence
- Specified by:
subSequencein interfaceCharSequence
-
toString
- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classObject
-