com.myjavaworld.util
Class RegexFilter

java.lang.Object
  extended by com.myjavaworld.util.RegexFilter
All Implemented Interfaces:
Filter

public class RegexFilter
extends Object
implements Filter

Version:
1.0
Author:
Sai Pullabhotla, psai [at] jMethods [dot] com

Constructor Summary
RegexFilter(String pattern, int flags)
          Creates an instance of RegexFilter.
 
Method Summary
 boolean accept(Object value)
          Checks to see if the given value can pass through this filter.
 Pattern getPattern()
          Returns the current pattern being used by this filter.
 void setPattern(Pattern pattern)
          Sets the pattern to be used by this filter to the given pattern.
 void setPattern(String pattern, int flags)
          Sets the pattern to be used by this filter to the given pattern.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RegexFilter

public RegexFilter(String pattern,
                   int flags)
Creates an instance of RegexFilter.

Parameters:
pattern - The regular expression or pattern.
flags - Additional flags to apply to the pattern.
Method Detail

setPattern

public void setPattern(String pattern,
                       int flags)
Sets the pattern to be used by this filter to the given pattern. The given string will be compiled to java.util.Pattern and a call to the setPattern(Pattern pattern) is made.

Parameters:
pattern - The pattern to be used by this filter.
flags - Additional flags to apply to the pattern.

setPattern

public void setPattern(Pattern pattern)
Sets the pattern to be used by this filter to the given pattern.

Parameters:
pattern - The pattern to be used by this filter.

getPattern

public Pattern getPattern()
Returns the current pattern being used by this filter.

Returns:
the pattern in use.

accept

public boolean accept(Object value)
Checks to see if the given value can pass through this filter. This method only accepts java.lang.String.

Specified by:
accept in interface Filter
Parameters:
value - The object to test.
Returns:
true if the given value contains the pattern as set by the setPattern() method. false otherwise. ClassCastException will thrown if the given vlue is not an instance java.lang.String.


Copyright © 2000-2012 jMethods, Inc.. All Rights Reserved.