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

File ExtensionId.java

 

Coverage histogram

../../../img/srcFileCovDistChart7.png
66% of files have more coverage

Code metrics

14
31
11
1
194
95
20
0.65
2.82
11
1.82

Classes

Class Line # Actions
ExtensionId 41 31 0% 20 21
0.62562.5%
 

Contributing tests

This file is covered by 215 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;
21   
22    import java.io.Serializable;
23    import java.lang.reflect.ParameterizedType;
24    import java.util.List;
25   
26    import org.apache.commons.lang3.builder.CompareToBuilder;
27    import org.apache.commons.lang3.builder.HashCodeBuilder;
28    import org.xwiki.component.util.DefaultParameterizedType;
29    import org.xwiki.extension.internal.converter.ExtensionIdConverter;
30    import org.xwiki.extension.version.Version;
31    import org.xwiki.extension.version.internal.DefaultVersion;
32   
33    import com.google.common.base.Objects;
34   
35    /**
36    * The combination of properties which makes an extension unique.
37    *
38    * @version $Id: 8d372db520c2e482df25226ff8adc53e53633a5d $
39    * @since 4.0M1
40    */
 
41    public class ExtensionId implements Serializable, Comparable<ExtensionId>
42    {
43    /**
44    * Type instance for {@code List<ExtensionId>}.
45    *
46    * @since 8.0M1
47    */
48    public static final ParameterizedType TYPE_LIST = new DefaultParameterizedType(null, List.class, ExtensionId.class);
49   
50    /**
51    * Serialization identifier.
52    */
53    private static final long serialVersionUID = 1L;
54   
55    /**
56    * @see #getId()
57    */
58    private final String id;
59   
60    /**
61    * @see #getVersion()
62    */
63    private final Version version;
64   
65    private transient int hashCode;
66   
67    /**
68    * @param id the extension identifier
69    * @since 8.0M1
70    * @since 7.4.6
71    */
 
72  15 toggle public ExtensionId(String id)
73    {
74  15 this(id, (Version) null);
75    }
76   
77    /**
78    * @param id the extension identifier
79    * @param version the extension version
80    */
 
81  2167 toggle public ExtensionId(String id, String version)
82    {
83  2167 this(id, version != null ? new DefaultVersion(version) : null);
84    }
85   
86    /**
87    * @param id the extension identifier
88    * @param version the extension version
89    */
 
90  47778 toggle public ExtensionId(String id, Version version)
91    {
92  47778 this.id = id;
93  47778 this.version = version;
94    }
95   
96    /**
97    * @return the extension identifier
98    */
 
99  2512169 toggle public String getId()
100    {
101  2512169 return this.id;
102    }
103   
104    /**
105    * @return the extension version
106    */
 
107  4749392 toggle public Version getVersion()
108    {
109  4749392 return this.version;
110    }
111   
 
112  10572 toggle @Override
113    public boolean equals(Object obj)
114    {
115  10572 if (obj instanceof ExtensionId) {
116  10572 ExtensionId extensionId = (ExtensionId) obj;
117   
118  10572 return Objects.equal(extensionId.getId(), getId()) && Objects.equal(extensionId.getVersion(), getVersion());
119    }
120   
121  0 return false;
122    }
123   
 
124  126812 toggle @Override
125    public int hashCode()
126    {
127  126812 if (this.hashCode == 0) {
128  4833 HashCodeBuilder builder = new HashCodeBuilder();
129   
130  4833 builder.append(getId());
131  4833 builder.append(getVersion());
132   
133  4833 this.hashCode = builder.toHashCode();
134    }
135   
136  126812 return this.hashCode;
137    }
138   
 
139  2047923 toggle @Override
140    public String toString()
141    {
142  2047923 return ExtensionIdConverter.toString(this);
143    }
144   
 
145  1 toggle @Override
146    public int compareTo(ExtensionId o)
147    {
148  1 if (o == null) {
149  0 return -1;
150    }
151   
152  1 CompareToBuilder builder = new CompareToBuilder();
153   
154  1 builder.append(getId(), o.getId());
155  1 builder.append(getVersion(), o.getVersion());
156   
157  1 return builder.toComparison();
158    }
159   
160    /**
161    * Same as {@link #equals(Object)} but with {@code null} version meaning "any version".
162    *
163    * @param extensionId the extension identifier to match
164    * @return true if the passes extension id matches this extension id
165    * @since 9.5RC1
166    */
 
167  0 toggle public boolean matches(ExtensionId extensionId)
168    {
169  0 if (Objects.equal(getId(), extensionId.getId())) {
170  0 if (getVersion() == null || extensionId.getVersion() == null
171    || Objects.equal(getVersion(), extensionId.getVersion())) {
172  0 return true;
173    }
174    }
175   
176  0 return false;
177    }
178   
179    /**
180    * @param extensionIds the extension identifiers to match
181    * @return true if one of the passes extension ids matched this extension id
182    * @since 9.5RC1
183    */
 
184  0 toggle public boolean matchesOne(Iterable<ExtensionId> extensionIds)
185    {
186  0 for (ExtensionId extensionId : extensionIds) {
187  0 if (matches(extensionId)) {
188  0 return true;
189    }
190    }
191   
192  0 return false;
193    }
194    }