1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.observation.event.filter

File RegexEventFilter.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

0
5
3
1
68
26
3
0.6
1.67
3
1

Classes

Class Line # Actions
RegexEventFilter 31 5 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.observation.event.filter;
21   
22    import java.io.Serializable;
23    import java.util.regex.Matcher;
24    import java.util.regex.Pattern;
25   
26    /**
27    * An {@link EventFilter} that selects only events whose affected document name matches a regular expression.
28    *
29    * @version $Id: 4ff8990dc88f580cb6922e254d30b7b8e2e880f2 $
30    */
 
31    public class RegexEventFilter implements EventFilter, Serializable
32    {
33    /**
34    * The version identifier for this Serializable class. Increment only if the <i>serialized</i> form of the class
35    * changes.
36    */
37    private static final long serialVersionUID = 1L;
38   
39    /** The regular expression, as a string. */
40    private String filter;
41   
42    /** The regular expression, as a regexp Pattern object. */
43    private Pattern pattern;
44   
45    /**
46    * Constructor initializing this event filter with a regular expression that should be matched.
47    *
48    * @param filter the regular expression to check against document names
49    */
 
50  8 toggle public RegexEventFilter(String filter)
51    {
52  8 this.filter = filter;
53  8 this.pattern = Pattern.compile(filter);
54    }
55   
 
56  1 toggle @Override
57    public String getFilter()
58    {
59  1 return this.filter;
60    }
61   
 
62  341 toggle @Override
63    public boolean matches(EventFilter eventFilter)
64    {
65  341 Matcher matcher = this.pattern.matcher(eventFilter.getFilter());
66  341 return matcher.matches();
67    }
68    }