Class BoundedCharSequence

java.lang.Object
io.jenkins.plugins.mcp.server.extensions.util.BoundedCharSequence
All Implemented Interfaces:
CharSequence

public final class BoundedCharSequence extends Object implements 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.

  • Constructor Details

    • BoundedCharSequence

      public BoundedCharSequence(CharSequence delegate, long budget)
      Parameters:
      delegate - the text to read
      budget - how many reads to allow; must be positive
  • Method Details