source: trunk/src/org/expeditee/agents/DisplayGreenstoneSession.java@ 1430

Last change on this file since 1430 was 919, checked in by jts21, 10 years ago

Added license headers to all files, added full GPL3 license file, moved license header generator script to dev/bin/scripts

File size: 2.8 KB
Line 
1/**
2 * DisplayGreenstoneSession.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program 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
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.agents;
20
21import java.util.ArrayList;
22import java.util.Collections;
23import java.util.Comparator;
24import java.util.List;
25import java.util.Map;
26
27import org.expeditee.greenstone.ResultDocument;
28import org.expeditee.gui.FrameCreator;
29import org.expeditee.stats.Formatter;
30
31public class DisplayGreenstoneSession extends SearchGreenstone {
32
33 public DisplayGreenstoneSession(int resultsCount) {
34 super(resultsCount);
35 }
36
37 public DisplayGreenstoneSession() {
38 super();
39 }
40
41 protected void createResults() {
42 if (!_gsdl.getSessionResults().isEmpty()) {
43 viewSessionResults(_gsdl.getSessionResults(), _results);
44 }
45 }
46
47 protected String getResultsTitle() {
48 return "SessionResults at " + Formatter.getDateTime();
49 }
50
51 /**
52 * This method provides an alternative view of the result set It uses the
53 * dateMap which organises results according to the year in which they were
54 * published
55 *
56 * You will need to write a similar method for any additional view that you
57 * implement
58 *
59 * You may wish to modify this method to provide a better layout of the
60 * output
61 */
62 private void viewSessionResults(Map<String, ResultDocument> sessionResults,
63 FrameCreator results) {
64
65 List<ResultDocument> resultDocArrayList = new ArrayList<ResultDocument>(
66 sessionResults.values());
67 Collections.sort(resultDocArrayList,
68 new DescendingSessionScoreComparator());
69
70 int docRank = 1;
71
72 for(ResultDocument rd: resultDocArrayList){
73 addText(rd, results, docRank++ + ". " + rd.getTitle());
74 }
75
76 }
77
78 protected String getCursorText() {
79 return getResultsTitle();
80 }
81
82 static class DescendingSessionScoreComparator implements Comparator<ResultDocument> {
83
84 public int compare(ResultDocument d1, ResultDocument d2) {
85
86 double sessionScore1 = d1.getSessionScore();
87 double sessionScore2 = d2.getSessionScore();
88
89 if (sessionScore1 > sessionScore2) {
90 return -1;
91 } else if (sessionScore1 < sessionScore2) {
92 return 1;
93 } else {
94 return 0;
95 }
96 }
97 }
98
99 protected String getNoResultsMessage() {
100 return "The session results set is empty";
101 }
102}
Note: See TracBrowser for help on using the repository browser.