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

File AbstractDocumentQuestionRecorder.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

8
13
2
1
72
35
6
0.46
6.5
2
3

Classes

Class Line # Actions
AbstractDocumentQuestionRecorder 37 13 0% 6 5
0.782608778.3%
 

Contributing tests

This file is covered by 2 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.extension.xar.internal.question;
21   
22    import java.util.HashMap;
23    import java.util.Map;
24   
25    import org.xwiki.extension.job.history.QuestionRecorder;
26    import org.xwiki.model.reference.DocumentReference;
27    import org.xwiki.model.reference.WikiReference;
28   
29    /**
30    * Base class for {@link QuestionRecorder}s that record/replay questions regarding documents.
31    *
32    * @param <Q> The question type
33    * @param <A> The answer type
34    * @version $Id: c1b28f54d1375796ae6b0f9a7f2006bc4cd8fbf3 $
35    * @since 7.1RC1
36    */
 
37    public abstract class AbstractDocumentQuestionRecorder<Q, A> implements QuestionRecorder<Q>
38    {
39    /**
40    * Serialization identifier.
41    */
42    private static final long serialVersionUID = 1L;
43   
44    protected final Map<DocumentReference, A> answers = new HashMap<>();
45   
 
46  7 toggle protected A getRecordedAnswer(DocumentReference documentReference)
47    {
48  7 A recordedAnswer = this.answers.get(documentReference);
49  7 if (recordedAnswer == null) {
50  7 WikiReference recordedWikiReference = getRecordedWikiReference();
51  7 if (recordedWikiReference != null) {
52  7 return this.answers.get(documentReference.replaceParent(documentReference.getWikiReference(),
53    recordedWikiReference));
54    }
55    }
56  0 return recordedAnswer;
57    }
58   
 
59  7 toggle private WikiReference getRecordedWikiReference()
60    {
61  7 WikiReference recordedWikiReference = null;
62  7 for (DocumentReference documentReference : this.answers.keySet()) {
63  18 if (recordedWikiReference == null) {
64  7 recordedWikiReference = documentReference.getWikiReference();
65  11 } else if (!recordedWikiReference.equals(documentReference.getWikiReference())) {
66    // There are multiple wikis recorded.
67  0 return null;
68    }
69    }
70  7 return recordedWikiReference;
71    }
72    }