1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.internal.event

File AbstractEntityEvent.java

 

Coverage histogram

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

Code metrics

6
10
7
1
95
44
10
1
1.43
7
1.43

Classes

Class Line # Actions
AbstractEntityEvent 31 10 0% 10 8
0.6521739465.2%
 

Contributing tests

This file is covered by 98 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 com.xpn.xwiki.internal.event;
21   
22    import org.apache.commons.lang3.ObjectUtils;
23    import org.xwiki.model.reference.EntityReference;
24   
25    /**
26    * Base class for all entity {@link org.xwiki.observation.event.Event events}.
27    *
28    * @version $Id: eb2e7836f5cfa5f6ba5e4fddba0bed913ac2c2e2 $
29    * @since 3.2M1
30    */
 
31    public abstract class AbstractEntityEvent implements EntityEvent
32    {
33    /**
34    * @see #getReference()
35    */
36    private EntityReference reference;
37   
38    /**
39    * Default constructor. Matches any {@link EntityEvent}.
40    */
 
41  583 toggle public AbstractEntityEvent()
42    {
43    }
44   
45    /**
46    * @param reference the reference
47    */
 
48  28374 toggle public AbstractEntityEvent(EntityReference reference)
49    {
50  28374 this.reference = reference;
51    }
52   
 
53  149698 toggle @Override
54    public EntityReference getReference()
55    {
56  149698 return this.reference;
57    }
58   
 
59  50113 toggle @Override
60    public boolean matches(Object otherEvent)
61    {
62  50113 if (otherEvent == this) {
63  0 return true;
64    }
65   
66  50113 return otherEvent instanceof EntityEvent && matchesReference(((EntityEvent) otherEvent).getReference());
67    }
68   
69    /**
70    * Try to match the provided reference.
71    *
72    * @param otherReference the reference to match
73    * @return true if the provided reference is matched
74    */
 
75  50113 toggle protected boolean matchesReference(EntityReference otherReference)
76    {
77  50113 return getReference() == null || getReference().equals(otherReference);
78    }
79   
 
80  34 toggle @Override
81    public boolean equals(Object obj)
82    {
83  34 if (super.equals(obj)) {
84  0 return true;
85    }
86   
87  34 return getClass() == obj.getClass() && ObjectUtils.equals(this.reference, ((EntityEvent) obj).getReference());
88    }
89   
 
90  0 toggle @Override
91    public int hashCode()
92    {
93  0 return this.reference != null ? this.reference.hashCode() : 0;
94    }
95    }