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

File ExtensionId.java

 

Coverage histogram

../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

8
23
9
1
158
75
13
0.57
2.56
9
1.44

Classes

Class Line # Actions
ExtensionId 40 23 0% 13 3
0.92592.5%
 

Contributing tests

This file is covered by 207 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.version.Version;
30    import org.xwiki.extension.version.internal.DefaultVersion;
31   
32    import com.google.common.base.Objects;
33   
34    /**
35    * The combination of properties which makes an extension unique.
36    *
37    * @version $Id: 8a0b23660dccd4b97341b8423153706da7fb85e7 $
38    * @since 4.0M1
39    */
 
40    public class ExtensionId implements Serializable, Comparable<ExtensionId>
41    {
42    /**
43    * Type instance for {@code List<ExtensionId>}.
44    *
45    * @since 8.0M1
46    */
47    public static final ParameterizedType TYPE_LIST = new DefaultParameterizedType(null, List.class, ExtensionId.class);
48   
49    /**
50    * Serialization identifier.
51    */
52    private static final long serialVersionUID = 1L;
53   
54    /**
55    * @see #getId()
56    */
57    private final String id;
58   
59    /**
60    * @see #getVersion()
61    */
62    private final Version version;
63   
64    private int hashCode = -1;
65   
66    /**
67    * @param id the extension identifier
68    * @since 8.0M1
69    * @since 7.4.6
70    */
 
71  16 toggle public ExtensionId(String id)
72    {
73  16 this(id, (Version) null);
74    }
75   
76    /**
77    * @param id the extension identifier
78    * @param version the extension version
79    */
 
80  3278 toggle public ExtensionId(String id, String version)
81    {
82  3278 this(id, version != null ? new DefaultVersion(version) : null);
83    }
84   
85    /**
86    * @param id the extension identifier
87    * @param version the extension version
88    */
 
89  43372 toggle public ExtensionId(String id, Version version)
90    {
91  43372 this.id = id;
92  43372 this.version = version;
93    }
94   
95    /**
96    * @return the extension identifier
97    */
 
98  131321 toggle public String getId()
99    {
100  131321 return this.id;
101    }
102   
103    /**
104    * @return the extension version
105    */
 
106  61490 toggle public Version getVersion()
107    {
108  61490 return this.version;
109    }
110   
 
111  1084 toggle @Override
112    public boolean equals(Object obj)
113    {
114  1084 if (obj instanceof ExtensionId) {
115  1082 ExtensionId extensionId = (ExtensionId) obj;
116   
117  1082 return Objects.equal(extensionId.getId(), getId()) && Objects.equal(extensionId.getVersion(), getVersion());
118    }
119   
120  2 return false;
121    }
122   
 
123  26457 toggle @Override
124    public int hashCode()
125    {
126  26457 if (this.hashCode == -1) {
127  2585 HashCodeBuilder builder = new HashCodeBuilder();
128   
129  2585 builder.append(getId());
130  2585 builder.append(getVersion());
131   
132  2585 this.hashCode = builder.toHashCode();
133    }
134   
135  26457 return this.hashCode;
136    }
137   
 
138  9419 toggle @Override
139    public String toString()
140    {
141  9419 return getId() + '-' + getVersion();
142    }
143   
 
144  1 toggle @Override
145    public int compareTo(ExtensionId o)
146    {
147  1 if (o == null) {
148  0 return -1;
149    }
150   
151  1 CompareToBuilder builder = new CompareToBuilder();
152   
153  1 builder.append(getId(), o.getId());
154  1 builder.append(getVersion(), o.getVersion());
155   
156  1 return builder.toComparison();
157    }
158    }