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

File AbstractQuestionEvent.java

 

Coverage histogram

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

Code metrics

6
18
10
1
130
67
13
0.72
1.8
10
1.3

Classes

Class Line # Actions
AbstractQuestionEvent 33 18 0% 13 6
0.823529482.4%
 

Contributing tests

This file is covered by 114 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.job.event.status;
21   
22    import java.util.List;
23   
24    import org.apache.commons.lang3.builder.EqualsBuilder;
25    import org.apache.commons.lang3.builder.HashCodeBuilder;
26   
27    /**
28    * Common implementation for job question events.
29    *
30    * @version $Id: c3e5f64bb9a7fe22dfce2ddf5e7063f28331eaf6 $
31    * @since 7.1RC1
32    */
 
33    public abstract class AbstractQuestionEvent implements QuestionEvent
34    {
35    /**
36    * The type of question that triggered this event.
37    */
38    private final String questionType;
39   
40    /**
41    * The id of the job that raised the question that triggered this event.
42    */
43    private final List<String> jobId;
44   
45    /**
46    * Creates an event that can be triggered by any type of question.
47    */
 
48  523 toggle public AbstractQuestionEvent()
49    {
50  523 this(null);
51    }
52   
53    /**
54    * Creates an event that can be triggered by a question of the specified type.
55    *
56    * @param questionType the type of question that can trigger this event
57    */
 
58  523 toggle public AbstractQuestionEvent(String questionType)
59    {
60  523 this(questionType, null);
61    }
62   
63    /**
64    * Creates an event that can be triggered by a question of the specified type when asked by a job with the specified
65    * id.
66    *
67    * @param questionType the type of question that can trigger this event
68    * @param jobId the id of the job that raised the question that triggered this event
69    */
 
70  537 toggle public AbstractQuestionEvent(String questionType, List<String> jobId)
71    {
72  537 this.questionType = questionType;
73  537 this.jobId = jobId;
74    }
75   
 
76  13 toggle @Override
77    public String getQuestionType()
78    {
79  13 return this.questionType;
80    }
81   
 
82  13 toggle @Override
83    public List<String> getJobId()
84    {
85  13 return this.jobId;
86    }
87   
 
88  8 toggle @Override
89    public boolean matches(Object event)
90    {
91  8 return this.getClass() == event.getClass() && matchesQuestionType(((QuestionEvent) event).getQuestionType())
92    && matchesJobId(((QuestionEvent) event).getJobId());
93    }
94   
 
95  8 toggle private boolean matchesQuestionType(String questionType)
96    {
97  8 return questionType == null || this.questionType == null || this.questionType.equals(questionType);
98    }
99   
 
100  8 toggle private boolean matchesJobId(List<String> jobId)
101    {
102  8 return jobId == null || this.jobId == null || this.jobId.equals(jobId);
103    }
104   
 
105  0 toggle @Override
106    public int hashCode()
107    {
108  0 return new HashCodeBuilder(7, 11).append(this.jobId).append(this.questionType).build();
109    }
110   
 
111  8 toggle @Override
112    public boolean equals(Object object)
113    {
114  8 if (object == null) {
115  0 return false;
116    }
117   
118  8 if (object == this) {
119  0 return true;
120    }
121   
122  8 if (object.getClass() != getClass()) {
123  3 return false;
124    }
125   
126  5 QuestionEvent event = (QuestionEvent) object;
127  5 return new EqualsBuilder().append(this.jobId, event.getJobId())
128    .append(this.questionType, event.getQuestionType()).build();
129    }
130    }