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

File RoleHint.java

 

Coverage histogram

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

Code metrics

10
19
8
1
129
60
14
0.74
2.38
8
1.75

Classes

Class Line # Actions
RoleHint 33 19 0% 14 6
0.837837883.8%
 

Contributing tests

This file is covered by 3657 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.component.internal;
21   
22    import java.lang.reflect.Type;
23   
24    import org.xwiki.component.util.ReflectionUtils;
25   
26    /**
27    * Represent the unique identifier of a Component (pair Role/Hint).
28    *
29    * @param <T> the role type
30    * @version $Id: dc2b3d62943eb0594eb537e412a274f3f194bd35 $
31    * @since 2.0M1
32    */
 
33    public class RoleHint<T>
34    {
35    /**
36    * @see #getRoleType()
37    */
38    private Type role;
39   
40    /**
41    * @see #getHint()
42    */
43    private String hint;
44   
45    /**
46    * @param role the component role
47    * @since 4.0M1
48    */
 
49  402615 toggle public RoleHint(Type role)
50    {
51  402581 this(role, null);
52    }
53   
54    /**
55    * @param role the component role
56    * @param hint the component hint
57    * @since 4.0M1
58    */
 
59  110091660 toggle public RoleHint(Type role, String hint)
60    {
61  110091697 this.role = role;
62  110091694 this.hint = hint;
63  110091730 if (this.hint == null) {
64  402800 this.hint = "default";
65    }
66    }
67   
68    /**
69    * @return the component role
70    * @since 4.0M1
71    */
 
72  2147483647 toggle public Type getRoleType()
73    {
74  2147483647 return this.role;
75    }
76   
77    /**
78    * @return the component role as class
79    * @since 4.0M1
80    */
 
81  72084 toggle @SuppressWarnings("unchecked")
82    public Class<T> getRoleClass()
83    {
84  72079 return ReflectionUtils.getTypeClass(this.role);
85    }
86   
87    /**
88    * @return the component hint
89    */
 
90  1192880670 toggle public String getHint()
91    {
92  1192880996 return this.hint;
93    }
94   
 
95  2147483647 toggle @Override
96    @SuppressWarnings("unchecked")
97    public boolean equals(Object obj)
98    {
99  2147483647 if (this == obj) {
100  0 return true;
101    }
102   
103  2147483647 if ((obj == null) || (obj.getClass() != this.getClass())) {
104  0 return false;
105    }
106   
107  2147483647 RoleHint<T> rolehint = (RoleHint<T>) obj;
108   
109  2147483647 return getRoleType().equals(rolehint.getRoleType())
110    && (getHint() == rolehint.getHint() || (getHint() != null && getHint().equals(rolehint.getHint())));
111    }
112   
 
113  70862996 toggle @Override
114    public int hashCode()
115    {
116  70862813 int hash = 8;
117   
118  70862899 hash = 31 * hash + (null == getRoleType() ? 0 : getRoleType().hashCode());
119  70862878 hash = 31 * hash + (null == getHint() ? 0 : getHint().hashCode());
120   
121  70862673 return hash;
122    }
123   
 
124  74096 toggle @Override
125    public String toString()
126    {
127  74096 return "role = [" + getRoleType() + "] hint = [" + getHint() + "]";
128    }
129    }