org.vostok.glob
Class Glob

java.lang.Object
  extended by org.vostok.glob.Glob

public class Glob
extends java.lang.Object

This class provide a glob implementation, using the same signature as Pattern.

Glob is a pattern matching behavior, but using fewer action, a more simple syntax, no sub selection and only intented to match string against a pattern. It's therefore much faster than using a regexp. A typical use is to validate en input, match a file name against a pattern, like *.jpg or *.r[0-9], etc...

This implementation recognize * ? grouping - with range - escape char and can work on case insensitive/sensitive pattern

Syntax is based on the linux' bash one.

Limitations :
Asterisk :

Group :

Match is done from begining of the string to the end.

Cost of a case insensitive operation :
the cost of an case insensitive operation is 1 time convertion to lower case of pattern and one 1 convertion of input for each Glob.matches call.

Version:
1.0
Author:
levreau.jerome@vostoksystem.eu

Field Summary
static int CASE_INSENSITIVE
           
static int CASE_SENSITIVE
           
 
Method Summary
static Glob compile(java.lang.String pattern)
          compile a new Glob parser, with CASE_INSENSITIVE matching
static Glob compile(java.lang.String pattern, int flag)
          compile a new Glob parser
 boolean matches(java.lang.CharSequence input)
          try to match an input data
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CASE_SENSITIVE

public static int CASE_SENSITIVE

CASE_INSENSITIVE

public static int CASE_INSENSITIVE
Method Detail

compile

public static Glob compile(java.lang.String pattern)
                    throws java.util.regex.PatternSyntaxException
compile a new Glob parser, with CASE_INSENSITIVE matching

Parameters:
pattern -
Returns:
Throws:
java.util.regex.PatternSyntaxException - if pattern is not valid

compile

public static Glob compile(java.lang.String pattern,
                           int flag)
                    throws java.util.regex.PatternSyntaxException
compile a new Glob parser

Parameters:
pattern -
flag - can be Glob.CASE_SENSITIVE or Glob.CASE_INSENSITIVE
Returns:
Throws:
java.util.regex.PatternSyntaxException - if pattern is not valid

matches

public boolean matches(java.lang.CharSequence input)
try to match an input data

Parameters:
input - data to check againt the glob pattern. can be empty but not null
Returns:
true if match, false else

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object