com.edugility.objexj
Class Pattern<T>

java.lang.Object
  extended by com.edugility.objexj.Pattern<T>
Type Parameters:
T - the type of Object a Pattern can match

public class Pattern<T>
extends Object

A regular expression pattern for arbitrary Objects.

A Pattern encapsulates the rules by which Lists of objects—the input—are matched or rejected. Patterns are compiled from textual representations that bear a striking and intentional similarity to regular regular expressions.

A normal user interaction with this class might consist of code like the following:

 final Pattern p = Pattern.compile("^javax.persistence.PersistenceException/java.lang.Throwable*");
 assert p != null;
 final Matcher<Exception> matcher = p.matcher(listOfExceptions);
 assert matcher != null;
 // Call matcher.lookingAt() or....

Patterns are not safe for use by multiple Java threads.

Author:
Laird Nelson
See Also:
compile(String), matcher(List), Matcher, Syntax Guide

Method Summary
static
<T> Pattern<T>
compile(String source)
          Compiles a new Pattern from the supplied source code.
 Matcher<T> matcher(List<? extends T> items)
          Returns a Matcher initialized to match the supplied List of items.
 String toString()
          Returns a non-null String representation of this Pattern.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

matcher

public final Matcher<T> matcher(List<? extends T> items)
Returns a Matcher initialized to match the supplied List of items. This method never returns null.

Parameters:
items - the input; may be null
Returns:
a new Matcher; never null

toString

public String toString()
Returns a non-null String representation of this Pattern.

This implementation attempts to return the original source code used to produce this Pattern. If that fails for some reason, then the normal Object.toString() method return value is returned instead.

Overrides:
toString in class Object
Returns:
a non-null String representation of this Pattern

compile

public static final <T> Pattern<T> compile(String source)
                                throws IOException,
                                       ParseException
Compiles a new Pattern from the supplied source code.

Type Parameters:
T - the type of Object the resulting Pattern will be capable of producing Matchers for
Parameters:
source - the source code for the Pattern; must not be null
Returns:
a new, non-null Pattern
Throws:
IllegalArgumentException - if source is null
IOException - if the source code could not be compiled because the source code could not be physically read for some reason
ParseException - if the source code could be read but was syntactically invalid
See Also:
Syntax Guide


Copyright © 2012–2013, Laird Nelson. All rights reserved.