1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.resource

File AbstractResourceReference.java

 

Coverage histogram

../../../img/srcFileCovDistChart9.png
41% of files have more coverage

Code metrics

16
36
9
1
152
103
17
0.47
4
9
1.89

Classes

Class Line # Actions
AbstractResourceReference 41 36 0% 17 7
0.885245988.5%
 

Contributing tests

This file is covered by 100 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.resource;
21   
22    import java.util.ArrayList;
23    import java.util.Collection;
24    import java.util.Collections;
25    import java.util.LinkedHashMap;
26    import java.util.List;
27    import java.util.Map;
28   
29    import org.apache.commons.lang3.builder.EqualsBuilder;
30    import org.apache.commons.lang3.builder.HashCodeBuilder;
31    import org.apache.commons.lang3.builder.ToStringBuilder;
32    import org.xwiki.text.XWikiToStringBuilder;
33   
34    /**
35    * Base XWiki Resource Reference implementation common to all extending classes. Manages XWiki Resource Reference
36    * parameters.
37    *
38    * @version $Id: 0be08c3e0b372a5cb0cd25db77cb4e3e53d70ab7 $
39    * @since 6.1M2
40    */
 
41    public abstract class AbstractResourceReference implements ResourceReference
42    {
43    /**
44    * @see #getParameters()
45    */
46    private final Map<String, List<String>> parameters = new LinkedHashMap<>();
47   
48    /**
49    * @see #getType()
50    */
51    private ResourceType type;
52   
 
53  44695 toggle @Override
54    public ResourceType getType()
55    {
56  44723 return this.type;
57    }
58   
59    /**
60    * @param type see {@link #getType()}
61    */
 
62  315776 toggle public void setType(ResourceType type)
63    {
64  315781 this.type = type;
65    }
66   
 
67  226624 toggle @Override
68    public void addParameter(String name, Object value)
69    {
70  226636 List<String> list = this.parameters.get(name);
71  226584 if (list == null) {
72  226624 list = new ArrayList<>();
73    }
74  226631 if (value != null) {
75    // If the value is a Collection or an Array then add a multivalued parameter!
76  224357 if (value.getClass().isArray()) {
77  4 Object[] objectValues = (Object[]) value;
78  4 for (Object objectValue : objectValues) {
79  8 list.add(objectValue.toString());
80    }
81  224334 } else if (Collection.class.isAssignableFrom(value.getClass())) {
82  94371 Collection<?> collectionValues = (Collection<?>) value;
83  94378 for (Object collectionValue : collectionValues) {
84  105156 list.add(collectionValue.toString());
85    }
86    } else {
87  129969 list.add(value.toString());
88    }
89    }
90  226626 this.parameters.put(name, list);
91    }
92   
 
93  261158 toggle @Override
94    public Map<String, List<String>> getParameters()
95    {
96  261178 return Collections.unmodifiableMap(this.parameters);
97    }
98   
 
99  1 toggle @Override
100    public List<String> getParameterValues(String name)
101    {
102  1 return this.parameters.get(name);
103    }
104   
 
105  10822 toggle @Override
106    public String getParameterValue(String name)
107    {
108  10824 String result = null;
109  10824 List<String> list = this.parameters.get(name);
110  10829 if (list != null) {
111  9419 result = list.get(0);
112    }
113  10829 return result;
114    }
115   
 
116  36690 toggle @Override
117    public String toString()
118    {
119  36703 ToStringBuilder builder = new XWikiToStringBuilder(this);
120  36709 builder.append("type", getType());
121  36700 builder.append("parameters", getParameters());
122  36720 return builder.toString();
123    }
124   
 
125  2 toggle @Override
126    public int hashCode()
127    {
128  2 return new HashCodeBuilder(9, 5)
129    .append(getType())
130    .append(getParameters())
131    .toHashCode();
132    }
133   
 
134  122 toggle @Override
135    public boolean equals(Object object)
136    {
137  122 if (object == null) {
138  0 return false;
139    }
140  122 if (object == this) {
141  0 return true;
142    }
143  122 if (object.getClass() != getClass()) {
144  0 return false;
145    }
146  122 ResourceReference rhs = (ResourceReference) object;
147  122 return new EqualsBuilder()
148    .append(getType(), rhs.getType())
149    .append(getParameters(), rhs.getParameters())
150    .isEquals();
151    }
152    }