Here’s how to use objexj in your project.
To use the objexj project, please see the Dependency Information report for full details.
In brief, the following dependency in a Maven project will work:
<dependency> <groupId>com.edugility</groupId> <artifactId>objexj</artifactId> <version>1.3.0</version> </dependency>
First, decide on the kind of pattern you want to use. See the Syntax Guide for help.
Next, you are probably going to match this pattern over an input list of a particular kind (say, Number or Exception). For this example, we’ll use Exception.
Next, you’ll need to compile that source code into an actual Pattern. To do this, use the Pattern#compile(String) method:
final Pattern<Exception> p = Pattern.compile("^(java.lang.Exception)");
The Pattern you get back is guaranteed to be non-null.
In this example, we’ll build an input List of Exceptions:
final List<Exception> input = new ArrayList<Exception>(); input.add(new Exception("first")); input.add(new Exception("second")); input.add(new Exception("third"));
Armed with a compiled Pattern and a List comprising the input, you can now use the Pattern to acquire a Matcher that will be used to match the input:
final Matcher<Exception> matcher = p.matcher(input);
The Matcher that is returned is guaranteed to be non-null.
See if the Matcher matches the whole input:
if (matcher.matches()) { // ... }
Or see if the Matcher matches part of the input, starting with element 0:
if (matcher.lookingAt()) { // ... }
Get the value of a capture group:
final List<Exception> group1 = matcher.group(1);
Get a List representing the items that matched:
final List<Exception> group0 = matcher.group(0);