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

File DefaultExtensionRepositoryDescriptor.java

 

Coverage histogram

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

Code metrics

4
27
13
1
183
93
15
0.56
2.08
13
1.15

Classes

Class Line # Actions
DefaultExtensionRepositoryDescriptor 37 27 0% 15 8
0.818181881.8%
 

Contributing tests

This file is covered by 78 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.extension.repository;
21   
22    import java.net.URI;
23    import java.util.Collections;
24    import java.util.HashMap;
25    import java.util.Map;
26   
27    import org.apache.commons.lang3.builder.HashCodeBuilder;
28   
29    import com.google.common.base.Objects;
30   
31    /**
32    * Default implementation of {@link ExtensionRepositoryDescriptor}.
33    *
34    * @version $Id: 9c7f03c4eb02f8248da26f63984ca82cd979d6fc $
35    * @since 4.3M1
36    */
 
37    public class DefaultExtensionRepositoryDescriptor implements ExtensionRepositoryDescriptor
38    {
39    /**
40    * @see #getId()
41    */
42    private final String id;
43   
44    /**
45    * @see #getType()
46    */
47    private final String type;
48   
49    /**
50    * @see #getURI()
51    */
52    private final URI uri;
53   
54    /**
55    * @see #getProperties()
56    */
57    private Map<String, String> properties = new HashMap<String, String>();
58   
59    private int hashCode = -1;
60   
61    /**
62    * @param descriptor the identifier to clone
63    */
 
64  0 toggle public DefaultExtensionRepositoryDescriptor(ExtensionRepositoryDescriptor descriptor)
65    {
66  0 this(descriptor.getId(), descriptor.getType(), descriptor.getURI());
67   
68  0 setProperties(descriptor.getProperties());
69    }
70   
71    /**
72    * Constructor to use only for "virtual" repositories having no storage like the ExtensionRepositoryManager.
73    *
74    * @param id the unique identifier
75    * @since 8.3RC1
76    */
 
77  246 toggle public DefaultExtensionRepositoryDescriptor(String id)
78    {
79  246 this(id, null, null);
80    }
81   
82    /**
83    * @param id the unique identifier
84    * @param type the repository type (maven, xwiki, etc.)
85    * @param uri the repository address
86    */
 
87  47564 toggle public DefaultExtensionRepositoryDescriptor(String id, String type, URI uri)
88    {
89  47564 this.id = id;
90  47564 this.type = type;
91  47564 this.uri = uri;
92    }
93   
 
94  135822 toggle @Override
95    public String getId()
96    {
97  135822 return this.id;
98    }
99   
 
100  135268 toggle @Override
101    public String getType()
102    {
103  135268 return this.type;
104    }
105   
 
106  135556 toggle @Override
107    public URI getURI()
108    {
109  135556 return this.uri;
110    }
111   
 
112  135217 toggle @Override
113    public Map<String, String> getProperties()
114    {
115  135217 return Collections.unmodifiableMap(this.properties);
116    }
117   
 
118  268 toggle @Override
119    public String getProperty(String key)
120    {
121  268 return this.properties.get(key);
122    }
123   
124    /**
125    * Set a property.
126    *
127    * @param key the property key
128    * @param value the property value
129    * @see #getProperty(String)
130    */
 
131  2 toggle public void putProperty(String key, String value)
132    {
133  2 this.properties.put(key, value);
134    }
135   
136    /**
137    * Replace existing properties with provided properties.
138    *
139    * @param properties the properties
140    */
 
141  0 toggle public void setProperties(Map<String, String> properties)
142    {
143  0 this.properties.clear();
144  0 this.properties.putAll(properties);
145    }
146   
 
147  44331 toggle @Override
148    public boolean equals(Object obj)
149    {
150  44331 if (obj instanceof ExtensionRepositoryDescriptor) {
151  44331 ExtensionRepositoryDescriptor repository = (ExtensionRepositoryDescriptor) obj;
152   
153  44331 return Objects.equal(getId(), repository.getId()) && Objects.equal(getType(), repository.getType())
154    && Objects.equal(getURI(), repository.getURI())
155    && Objects.equal(getProperties(), repository.getProperties());
156    }
157   
158  0 return false;
159    }
160   
 
161  48598 toggle @Override
162    public int hashCode()
163    {
164  48598 if (this.hashCode == -1) {
165  46429 HashCodeBuilder builder = new HashCodeBuilder();
166   
167  46429 builder.append(getId());
168  46429 builder.append(getType());
169  46429 builder.append(getURI());
170  46429 builder.append(getProperties());
171   
172  46429 this.hashCode = builder.toHashCode();
173    }
174   
175  48598 return this.hashCode;
176    }
177   
 
178  1 toggle @Override
179    public String toString()
180    {
181  1 return getId() + ':' + getType() + ':' + getURI();
182    }
183    }