net.sf.sdedit.util
Class Grep

java.lang.Object
  extended by net.sf.sdedit.util.Grep

public final class Grep
extends Object

Utility class for matching strings against regular expressions and accessing substrings that match groups of the regular expression.

Author:
Markus Strauch

Method Summary
static String[] parse(String regexp, String string)
          Matches a string against a regular expression and returns an array of the substrings corresponding to the groups of the regular expression, or null, if the string does not match the regular expression.
static boolean parseAndSetProperties(Object bean, String regexp, String string, String... properties)
          Matches a string against a regular expression and uses the resulting groups (corresponding to portions of the regular expression between braces) for setting properties of a bean.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

parse

public static String[] parse(String regexp,
                             String string)
Matches a string against a regular expression and returns an array of the substrings corresponding to the groups of the regular expression, or null, if the string does not match the regular expression.

Parameters:
regexp - a regular expression
string - a string
Returns:
an array of the substrings corresponding to the groups of the regular expression, or null, if the string does not match the regular expression

parseAndSetProperties

public static boolean parseAndSetProperties(Object bean,
                                            String regexp,
                                            String string,
                                            String... properties)
                                     throws IntrospectionException
Matches a string against a regular expression and uses the resulting groups (corresponding to portions of the regular expression between braces) for setting properties of a bean. The write method for the i-th property is called with an object of the write method's parameter type, that object is created by calling the type's string constructor with the string of the i-th group.

Parameters:
bean - a bean
regexp - a regular expression
string - a string to match the regular expression against
properties - names of properties of the bean
Returns:
true if the string matched and if the properties could be set
Throws:
IntrospectionException - if the bean could not be introspected


Copyright © 2011. All Rights Reserved.