org.tbull.util
Class Grepper.RegexGrepper

Object
  extended by org.tbull.util.Grepper.RegexGrepper
All Implemented Interfaces:
Grepper<CharSequence>
Enclosing interface:
Grepper<E>

public static class Grepper.RegexGrepper
extends Object
implements Grepper<CharSequence>

A Grepper that matches string-like elements against a regular expression.

      List<String> integer_strings = grep(new Grepper.RegexGrepper("[0-9]+"), strings);
  

ToDo:
This grepper has not yet been tested.

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.tbull.util.Grepper
Grepper.ANDGrepper<E>, Grepper.InverseGrepper<E>, Grepper.NULLGrepper<E>, Grepper.ONEGrepper<E>, Grepper.ORGrepper<E>, Grepper.RegexGrepper
 
Constructor Summary
Grepper.RegexGrepper(Pattern pattern)
          Constructs a RegexGrepper from a precompiled Pattern.
Grepper.RegexGrepper(String regex)
          Constructs a RegexGrepper from a given regular expression.
 
Method Summary
 boolean grep(CharSequence element)
          Greps elements that match the regular expression as per Matcher.matches().
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Grepper.RegexGrepper

public Grepper.RegexGrepper(String regex)
                     throws PatternSyntaxException
Constructs a RegexGrepper from a given regular expression.

Throws:
PatternSyntaxException

Grepper.RegexGrepper

public Grepper.RegexGrepper(Pattern pattern)
Constructs a RegexGrepper from a precompiled Pattern.

Method Detail

grep

public boolean grep(CharSequence element)
Greps elements that match the regular expression as per Matcher.matches().

Specified by:
grep in interface Grepper<CharSequence>
Parameters:
element - The element under test.
Returns:
true if the element matches the grep condition, thus should be added to the results, otherwise false.