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

File AbstractFilterableEvent.java

 

Coverage histogram

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

Code metrics

10
19
7
1
136
61
12
0.63
2.71
7
1.71

Classes

Class Line # Actions
AbstractFilterableEvent 36 19 0% 12 0
1.0100%
 

Contributing tests

This file is covered by 225 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.observation.event;
21   
22    import java.io.Serializable;
23    import java.util.Objects;
24   
25    import org.apache.commons.lang3.builder.HashCodeBuilder;
26    import org.xwiki.observation.event.filter.AlwaysMatchingEventFilter;
27    import org.xwiki.observation.event.filter.EventFilter;
28    import org.xwiki.observation.event.filter.FixedNameEventFilter;
29   
30    /**
31    * A generic Event implementation to extend for all Events that want to support {@link EventFilter}s.
32    *
33    * @version $Id: 902b85802f340ec34370f8507170c1377caf260d $
34    * @since 2.4M2
35    */
 
36    public abstract class AbstractFilterableEvent implements FilterableEvent, Serializable
37    {
38    /**
39    * The version identifier for this Serializable class. Increment only if the <i>serialized</i> form of the class
40    * changes.
41    */
42    private static final long serialVersionUID = 1L;
43   
44    /**
45    * A filter for comparing document names, used in {@link #matches(Object)}.
46    */
47    private EventFilter eventFilter;
48   
49    /**
50    * Constructor initializing the event filter with an
51    * {@link org.xwiki.observation.event.filter.AlwaysMatchingEventFilter}, meaning that this event will match any
52    * other event of the same type.
53    */
 
54  5253 toggle public AbstractFilterableEvent()
55    {
56  5253 this.eventFilter = AlwaysMatchingEventFilter.INSTANCE;
57    }
58   
59    /**
60    * Constructor initializing the event filter with a {@link org.xwiki.observation.event.filter.FixedNameEventFilter},
61    * meaning that this event will match only events of the same type affecting the same passed name.
62    *
63    * @param name a generic name that uniquely identifies an event type
64    */
 
65  26374 toggle public AbstractFilterableEvent(String name)
66    {
67  26374 this.eventFilter = new FixedNameEventFilter(name);
68    }
69   
70    /**
71    * Constructor using a custom {@link EventFilter}.
72    *
73    * @param eventFilter the filter to use for matching events
74    */
 
75  497 toggle public AbstractFilterableEvent(EventFilter eventFilter)
76    {
77  497 this.eventFilter = eventFilter;
78    }
79   
 
80  185304 toggle @Override
81    public EventFilter getEventFilter()
82    {
83  185304 return this.eventFilter;
84    }
85   
86    /**
87    * {@inheritDoc}
88    * <p>
89    * This type of events match only events of the same type, and only if the internal {@link #eventFilter}s also
90    * {@link EventFilter#matches(EventFilter)} match.
91    * </p>
92    *
93    * @see Event#matches(Object)
94    * @see EventFilter#matches(EventFilter)
95    */
 
96  92476 toggle @Override
97    public boolean matches(Object otherEvent)
98    {
99  92475 if (otherEvent == this) {
100  3 return true;
101    }
102   
103  92472 boolean isMatching = false;
104   
105  92473 if (this.getClass().isAssignableFrom(otherEvent.getClass())) {
106  92468 isMatching = getEventFilter().matches(((AbstractFilterableEvent) otherEvent).getEventFilter());
107    }
108   
109  92472 return isMatching;
110    }
111   
 
112  128 toggle @Override
113    public boolean equals(Object object)
114    {
115  128 if (object == null) {
116  2 return false;
117    }
118   
119  126 if (object == this) {
120  3 return true;
121    }
122   
123  123 if (object.getClass() != getClass()) {
124  64 return false;
125    }
126   
127  59 FilterableEvent rhs = (FilterableEvent) object;
128  59 return Objects.equals(getEventFilter(), rhs.getEventFilter());
129    }
130   
 
131  55 toggle @Override
132    public int hashCode()
133    {
134  55 return new HashCodeBuilder(3, 125).append(getEventFilter()).toHashCode();
135    }
136    }