1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.model.reference

File RegexEntityReference.java

 

Coverage histogram

../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

0
6
4
1
84
26
4
0.67
1.5
4
1

Classes

Class Line # Actions
RegexEntityReference 41 6 0% 4 2
0.880%
 

Contributing tests

This file is covered by 34 tests. .

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.model.reference;
21   
22    import java.util.regex.Pattern;
23   
24    import org.xwiki.model.EntityType;
25   
26    /**
27    * An {@link EntityReference} used to match another one.
28    * <p>
29    * This {@link EntityReference} contains a {@link Pattern} which will tries to match provided {@link EntityReference}
30    * name and type.
31    * <p>
32    * The {@link RegexEntityReference} can be partial or contain holes, for example if only the space regex reference is
33    * provided it will tries to match only space part of the provided reference and consider other parts as matched.
34    * <p>
35    * It's of course possible to mix regex and "normal" {@link EntityReference} member. In that case normal member
36    * {@link #equals(Object)} method behave as usual and then call following member {@link #equals(Object)} etc.
37    *
38    * @version $Id: c0f926c92e1d47206167027c18026202ccfc3dd8 $
39    * @since 3.2M1
40    */
 
41    public class RegexEntityReference extends PartialEntityReference
42    {
43    /**
44    *
45    */
46    private Pattern pattern;
47   
48    /**
49    * @param pattern the pattern used to match the name
50    * @param type the type of the reference
51    */
 
52  437 toggle public RegexEntityReference(Pattern pattern, EntityType type)
53    {
54  437 super(pattern.pattern(), type);
55   
56  437 this.pattern = pattern;
57    }
58   
59    /**
60    * @param pattern the pattern used to match the name
61    * @param type the type of the reference
62    * @param parent the parent of the reference
63    */
 
64  150 toggle public RegexEntityReference(Pattern pattern, EntityType type, EntityReference parent)
65    {
66  150 super(pattern.pattern(), type, parent);
67   
68  150 this.pattern = pattern;
69    }
70   
71    /**
72    * @return the pattern used to match the name
73    */
 
74  0 toggle public Pattern getPattern()
75    {
76  0 return this.pattern;
77    }
78   
 
79  33983 toggle @Override
80    protected boolean isNameEqual(String name)
81    {
82  33983 return this.pattern == null || this.pattern.matcher(name).matches();
83    }
84    }