net.sf.mmm.util.pattern.base
Class AbstractGlobPatternCompiler

java.lang.Object
  extended by net.sf.mmm.util.pattern.base.AbstractGlobPatternCompiler
All Implemented Interfaces:
PatternCompiler
Direct Known Subclasses:
GlobPatternCompiler, PathPatternCompiler, WildcardGlobPatternCompiler

public abstract class AbstractGlobPatternCompiler
extends Object
implements PatternCompiler

This is an abstract base-implementation of the PatternCompiler interface for glob-patterns.

Since:
1.0.0
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)
See Also:
GlobPatternCompiler, PathPatternCompiler

Field Summary
private static char[] CHARS_TO_ESCAPE
          The characters that have to be escaped in a regular expression.
 
Constructor Summary
AbstractGlobPatternCompiler()
          The constructor.
 
Method Summary
 Pattern compile(String pattern)
          
protected  String convertPattern(String pattern)
          This method converts the given pattern to a regex-pattern.
protected  boolean isRequireWildcard()
          This method gets the flag that determines if wildcards are required.
protected  int process(char[] chars, int charIndex, StringBuilder buffer)
          This method processes one or many characters from chars starting at the given charIndex and adds the translated regexp-sequence to buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHARS_TO_ESCAPE

private static final char[] CHARS_TO_ESCAPE
The characters that have to be escaped in a regular expression.

Constructor Detail

AbstractGlobPatternCompiler

public AbstractGlobPatternCompiler()
The constructor.

Method Detail

compile

public Pattern compile(String pattern)
                throws IllegalArgumentException

Specified by:
compile in interface PatternCompiler
Parameters:
pattern - is the expression to be compiled as pattern.
Returns:
the compiled pattern. May only return null if explicitly documented by the underlying implementation. E.g. if the given pattern is just a plain string without wildcards.
Throws:
IllegalArgumentException - if the given pattern has illegal syntax for the underlying compiler.
See Also:
Pattern.compile(String)

isRequireWildcard

protected boolean isRequireWildcard()
This method gets the flag that determines if wildcards are required.
This implementation always returns false. Override to change.

Returns:
true if wildcards are required. In that case null is returned if the given pattern contains no wildcard ('*' or '?'). false otherwise.

convertPattern

protected String convertPattern(String pattern)
This method converts the given pattern to a regex-pattern.

Parameters:
pattern - is the pattern to convert.
Returns:
the converted regex-pattern or null if isRequireWildcard() is true and the given pattern contains no wildcard ('*' or '?').

process

protected int process(char[] chars,
                      int charIndex,
                      StringBuilder buffer)
This method processes one or many characters from chars starting at the given charIndex and adds the translated regexp-sequence to buffer.

Parameters:
chars - are the characters of the original pattern string.
charIndex - is the current index in chars.
buffer - is where the translated regexp-pattern is appended to.
Returns:
the index of the next character that has NOT yet been consumed (typically charIndex + 1).


Copyright © 2001-2010 mmm-Team. All Rights Reserved.