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

File PartialEntityReference.java

 

Coverage histogram

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

Code metrics

12
15
5
1
109
43
11
0.73
3
5
2.2

Classes

Class Line # Actions
PartialEntityReference 36 15 0% 11 10
0.687568.8%
 

Contributing tests

This file is covered by 34 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.model.reference;
21   
22    import org.xwiki.model.EntityType;
23   
24    /**
25    * An {@link EntityReference} used to match another one.
26    * <p>
27    * The {@link PartialEntityReference} can be partial or contain holes, for example if only the space regex reference is
28    * provided it will tries to match only space part of the provided reference and consider other parts as matched.
29    * <p>
30    * It's of course possible to mix regex and "normal" {@link EntityReference} member. In that case normal member
31    * {@link #equals(Object)} method behave as usual and then call following member {@link #equals(Object)} etc.
32    *
33    * @version $Id: c77ff4a314d47034942d6d3451d4fe6e1e872c0d $
34    * @since 5.2M2
35    */
 
36    public class PartialEntityReference extends EntityReference
37    {
38    /**
39    * Create a new root EntityReference.
40    *
41    * @param name name for the newly created entity reference, could not be null.
42    * @param type type for the newly created entity reference, could not be null.
43    */
 
44  437 toggle public PartialEntityReference(String name, EntityType type)
45    {
46  437 super(name, type);
47    }
48   
49    /**
50    * Create a new EntityReference.
51    *
52    * @param name name for the newly created entity reference, could not be null.
53    * @param type type for the newly created entity reference, could not be null.
54    * @param parent parent reference for the newly created entity reference, may be null.
55    */
 
56  150 toggle public PartialEntityReference(String name, EntityType type, EntityReference parent)
57    {
58  150 super(name, type, parent);
59    }
60   
 
61  0 toggle @Override
62    public int hashCode()
63    {
64  0 return super.hashCode();
65    }
66   
67    /**
68    * {@inheritDoc}
69    * <p>
70    * This equals method actually skip null elements.
71    * </p>
72    *
73    * @see org.xwiki.model.reference.EntityReference#equals(java.lang.Object)
74    */
 
75  33983 toggle @Override
76    public boolean equals(Object obj)
77    {
78  33983 if (obj == this) {
79  0 return true;
80    }
81   
82  33983 if (!(obj instanceof EntityReference)) {
83  0 return false;
84    }
85   
86  33983 EntityReference reference = (EntityReference) obj;
87   
88  33986 for (EntityReference entity = reference; entity != null; entity = entity.getParent()) {
89  33986 if (getType().equals(entity.getType())) {
90  33983 if (!isNameEqual(entity.getName())) {
91  33738 return false;
92    } else {
93  245 return getParent() != null ? getParent().equals(entity.getParent()) : true;
94    }
95    }
96    }
97   
98  0 return true;
99    }
100   
101    /**
102    * @param name the name to compare to this name
103    * @return true of the passed name is equal to this name
104    */
 
105  0 toggle protected boolean isNameEqual(String name)
106    {
107  0 return getName() != null && getName().equals(name);
108    }
109    }