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

File WebJarsResourceReference.java

 

Coverage histogram

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

Code metrics

6
15
6
1
119
63
9
0.6
2.5
6
1.5

Classes

Class Line # Actions
WebJarsResourceReference 37 15 0% 9 6
0.777777877.8%
 

Contributing tests

This file is covered by 17 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.webjars.internal;
21   
22    import java.util.ArrayList;
23    import java.util.List;
24   
25    import org.apache.commons.lang3.StringUtils;
26    import org.apache.commons.lang3.builder.EqualsBuilder;
27    import org.apache.commons.lang3.builder.HashCodeBuilder;
28    import org.xwiki.resource.AbstractResourceReference;
29    import org.xwiki.resource.ResourceType;
30   
31    /**
32    * Represents a reference to a WebJar resource.
33    *
34    * @version $Id: 8d66201b37c82aed842f2d93eff9efc4f213e7c8 $
35    * @since 7.1M1
36    */
 
37    public class WebJarsResourceReference extends AbstractResourceReference
38    {
39    /**
40    * Represents a WebJars Resource Type.
41    */
42    public static final ResourceType TYPE = new ResourceType("webjars");
43   
44    private static final char RESOURCE_PATH_SEPARATOR = '/';
45   
46    private String namespace;
47   
48    private List<String> resourceSegments;
49   
50    /**
51    * @param namespace see {@link #getNamespace()}
52    * @param resourceSegments see {@link #getResourceSegments()}
53    */
 
54  27457 toggle public WebJarsResourceReference(String namespace, List<String> resourceSegments)
55    {
56  27457 setType(TYPE);
57  27449 this.namespace = namespace;
58  27447 this.resourceSegments = new ArrayList<>(resourceSegments);
59    }
60   
61    /**
62    * @return the list of segments making up the WebJar Resource (e.g. {@code ["angular", "2.1.11", "angular.js"]} for
63    * a Resource located in a {@code angular/2.1.11/angular.js} directory in a WebJar JAR
64    */
 
65  30259 toggle public List<String> getResourceSegments()
66    {
67  30259 return this.resourceSegments;
68    }
69   
70    /**
71    * @return the String representation with "/" separating each resource segment, e.g.
72    * {@code angular/2.1.11/angular.js}
73    */
 
74  4541 toggle public String getResourceName()
75    {
76  4544 return StringUtils.join(getResourceSegments(), RESOURCE_PATH_SEPARATOR);
77    }
78   
79    /**
80    * @return the namespace under which the webjars resource can be found. A name can be for example a wiki (e.g.
81    * {@code wiki:<wikiId>})
82    */
 
83  27405 toggle public String getNamespace()
84    {
85  27407 return this.namespace;
86    }
87   
 
88  6 toggle @Override
89    public int hashCode()
90    {
91  6 return new HashCodeBuilder(5, 5)
92    .append(getResourceSegments())
93    .append(getType())
94    .append(getNamespace())
95    .append(getParameters())
96    .toHashCode();
97    }
98   
 
99  10 toggle @Override
100    public boolean equals(Object object)
101    {
102  10 if (object == null) {
103  0 return false;
104    }
105  10 if (object == this) {
106  0 return true;
107    }
108  10 if (object.getClass() != getClass()) {
109  0 return false;
110    }
111  10 WebJarsResourceReference rhs = (WebJarsResourceReference) object;
112  10 return new EqualsBuilder()
113    .append(getResourceSegments(), rhs.getResourceSegments())
114    .append(getType(), rhs.getType())
115    .append(getNamespace(), rhs.getNamespace())
116    .append(getParameters(), rhs.getParameters())
117    .isEquals();
118    }
119    }