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

File FilterElementDescriptor.java

 

Coverage histogram

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

Code metrics

4
16
11
1
171
66
13
0.81
1.45
11
1.18

Classes

Class Line # Actions
FilterElementDescriptor 35 16 0% 13 6
0.806451680.6%
 

Contributing tests

This file is covered by 696 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.filter;
21   
22    import java.lang.reflect.Method;
23    import java.util.HashMap;
24    import java.util.Map;
25   
26    /**
27    * An element of the filter.
28    * <p>
29    * An element is defined by either an <code>on</code> event of a combination of <code>begin</code> and <code>end</code>
30    * events.
31    *
32    * @version $Id: e87af0a0cd2bd38becc35fd105cd1006b6df4eff $
33    * @since 5.2M1
34    */
 
35    public class FilterElementDescriptor
36    {
37    /**
38    * Empty parameters.
39    */
40    private static final FilterElementParameterDescriptor<?>[] EMPTY_PARAMETERS =
41    new FilterElementParameterDescriptor<?>[0];
42   
43    /**
44    * @see #getName()
45    */
46    private String name;
47   
48    /**
49    * @see #getParameters()
50    */
51    private FilterElementParameterDescriptor<?>[] parameters;
52   
53    /**
54    * Used to find parameter index by name.
55    */
56    private Map<String, Integer> parametersIndex = new HashMap<String, Integer>();
57   
58    /**
59    * @see #getBeginMethod()
60    */
61    private Method beginMethod;
62   
63    /**
64    * @see #getEndMethod()
65    */
66    private Method endMethod;
67   
68    /**
69    * @see #getOnMethod()
70    */
71    private Method onMethod;
72   
73    /**
74    * @param name the name of the element
75    */
 
76  0 toggle public FilterElementDescriptor(String name)
77    {
78  0 this(name, EMPTY_PARAMETERS);
79    }
80   
81    /**
82    * @param name the name of the element
83    * @param parameters the parameters
84    */
 
85  32017 toggle public FilterElementDescriptor(String name, FilterElementParameterDescriptor<?>[] parameters)
86    {
87  32017 this.name = name;
88  32017 this.parameters = parameters;
89  32017 for (FilterElementParameterDescriptor<?> parameter : parameters) {
90  47200 if (parameter.getName() != null) {
91  47200 this.parametersIndex.put(parameter.getName(), parameter.getIndex());
92    }
93    }
94    }
95   
96    /**
97    * @return the name of the element
98    */
 
99  0 toggle public String getName()
100    {
101  0 return this.name;
102    }
103   
104    /**
105    * @return the parameters of the element
106    */
 
107  83211 toggle public FilterElementParameterDescriptor<?>[] getParameters()
108    {
109  83211 return this.parameters;
110    }
111   
112    /**
113    * @param <T> the type of the parameter value
114    * @param name the name of the parameter
115    * @return the parameter associated to the passed name
116    */
 
117  2708 toggle public <T> FilterElementParameterDescriptor<T> getParameter(String name)
118    {
119  2708 Integer index = this.parametersIndex.get(name);
120   
121  2708 return index != null ? (FilterElementParameterDescriptor<T>) this.parameters[index] : null;
122    }
123   
124    /**
125    * @return the begin method, null if it's a <code>on</code> event based element
126    */
 
127  40245 toggle public Method getBeginMethod()
128    {
129  40245 return this.beginMethod;
130    }
131   
132    /**
133    * @param beginMethod the begin method, null if it's a <code>on</code> event based element
134    */
 
135  21013 toggle public void setBeginMethod(Method beginMethod)
136    {
137  21014 this.beginMethod = beginMethod;
138    }
139   
140    /**
141    * @return the end method, null if it's a <code>on</code> event based element
142    */
 
143  24129 toggle public Method getEndMethod()
144    {
145  24129 return this.endMethod;
146    }
147   
148    /**
149    * @param endMethod the end method, null if it's a <code>on</code> event based element
150    */
 
151  21014 toggle public void setEndMethod(Method endMethod)
152    {
153  21014 this.endMethod = endMethod;
154    }
155   
156    /**
157    * @return the on method, null if it's a <code>begin/end</code> event based element
158    */
 
159  16103 toggle public Method getOnMethod()
160    {
161  16103 return this.onMethod;
162    }
163   
164    /**
165    * @param onMethod the on method, null if it's a <code>begin/end</code> event based element
166    */
 
167  11084 toggle public void setOnMethod(Method onMethod)
168    {
169  11084 this.onMethod = onMethod;
170    }
171    }