1 | package org.greenstone.server;
|
---|
2 |
|
---|
3 | import java.sql.ResultSet;
|
---|
4 | import java.util.ArrayList;
|
---|
5 | import java.util.HashMap;
|
---|
6 |
|
---|
7 | import org.greenstone.client.Place;
|
---|
8 | import org.greenstone.server.ServerPlace;
|
---|
9 |
|
---|
10 | public class ScanResultSet
|
---|
11 | {
|
---|
12 | HashMap<String, ServerPlace> _resultSet = new HashMap<String, ServerPlace>();
|
---|
13 | String _name = null;
|
---|
14 |
|
---|
15 | /*
|
---|
16 | public ScanResultSet(String name, ArrayList<ServerPlace> results, Object nothing)
|
---|
17 | {
|
---|
18 | _name = name;
|
---|
19 | for(ServerPlace p : results)
|
---|
20 | {
|
---|
21 | if(_resultSet.containsKey(p.getName()))
|
---|
22 | {
|
---|
23 | ServerPlace old = _resultSet.get(p.getName());
|
---|
24 | if (p.getScore() > old.getScore())
|
---|
25 | {
|
---|
26 | _resultSet.put(p.getName(), p);
|
---|
27 | }
|
---|
28 | }
|
---|
29 | else
|
---|
30 | {
|
---|
31 | _resultSet.put(p.getName(), p);
|
---|
32 | }
|
---|
33 | }
|
---|
34 | }
|
---|
35 | */
|
---|
36 | public ScanResultSet(String name, ArrayList<Place> results)
|
---|
37 | {
|
---|
38 | _name = name;
|
---|
39 | for(Place p : results)
|
---|
40 | {
|
---|
41 | if(_resultSet.containsKey(p.getName()))
|
---|
42 | {
|
---|
43 | ServerPlace old = _resultSet.get(p.getName());
|
---|
44 | if (p.getScore() > old.getScore())
|
---|
45 | {
|
---|
46 | _resultSet.put(p.getName(), ServerPlace.convert(p));
|
---|
47 | }
|
---|
48 | else if(p.getScore() == old.getScore())
|
---|
49 | {
|
---|
50 | if(p.getPopulation() > old.getPopulation())
|
---|
51 | {
|
---|
52 | _resultSet.put(p.getName(), ServerPlace.convert(p));
|
---|
53 | }
|
---|
54 | }
|
---|
55 | }
|
---|
56 | else
|
---|
57 | {
|
---|
58 | _resultSet.put(p.getName(), ServerPlace.convert(p));
|
---|
59 | }
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | public ScanResultSet(String name, Long[] ids)
|
---|
64 | {
|
---|
65 | _name = name;
|
---|
66 | for(int i = 0; i < ids.length; i++)
|
---|
67 | {
|
---|
68 | // if(i >= ids.length)
|
---|
69 | // {
|
---|
70 | // return;
|
---|
71 | // }
|
---|
72 |
|
---|
73 | ServerPlace p = ServerPlace.createPlaceFromId(ids[i]);
|
---|
74 |
|
---|
75 | if(PlaceInformation.getPlaces(p.getName()).size() > 1)
|
---|
76 | {
|
---|
77 | _resultSet.put(p.getName(), p);
|
---|
78 | }
|
---|
79 | //_resultSet.put(p.getName(), p);
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | public int[] compareResults (ScanResultSet otherResults)
|
---|
84 | {
|
---|
85 | if(otherResults == null)
|
---|
86 | {
|
---|
87 | return null;
|
---|
88 | }
|
---|
89 |
|
---|
90 | int count = 0;
|
---|
91 | int total = 0;
|
---|
92 | for(String s : _resultSet.keySet())
|
---|
93 | {
|
---|
94 | if(otherResults.getResult(s) != null && otherResults.getResult(s).equals(_resultSet.get(s)))
|
---|
95 | {
|
---|
96 | count++;
|
---|
97 | }
|
---|
98 | else
|
---|
99 | {
|
---|
100 | if(otherResults.getResult(s) != null)
|
---|
101 | {
|
---|
102 | //System.out.println(_resultSet.get(s).getName() + ", " + _resultSet.get(s).getParentPlaceName() + " (" + _resultSet.get(s).getScore() + ") != " + otherResults.getResult(s).getName() + ", " + otherResults.getResult(s).getParentPlaceName() + " (" + otherResults.getResult(s).getScore() + ")");
|
---|
103 | }
|
---|
104 | else
|
---|
105 | {
|
---|
106 | //System.out.println(_resultSet.get(s).getName() + ", " + _resultSet.get(s).getParentPlaceName() + " != " + otherResults.getResult(s));
|
---|
107 | }
|
---|
108 | }
|
---|
109 | total++;
|
---|
110 | }
|
---|
111 |
|
---|
112 | System.out.println("Result = " + count + "/" + total);
|
---|
113 |
|
---|
114 | return new int[]{count, total};
|
---|
115 | }
|
---|
116 |
|
---|
117 | public ServerPlace getResult(String key)
|
---|
118 | {
|
---|
119 | return _resultSet.get(key);
|
---|
120 | }
|
---|
121 |
|
---|
122 | public String getName()
|
---|
123 | {
|
---|
124 | return _name;
|
---|
125 | }
|
---|
126 |
|
---|
127 | public void updateScores(ArrayList<Place> places)
|
---|
128 | {
|
---|
129 | for(String s : _resultSet.keySet())
|
---|
130 | {
|
---|
131 | for(int i = 0; i < places.size(); i++)
|
---|
132 | {
|
---|
133 | if(_resultSet.get(s).equals(places.get(i)) && _resultSet.get(s).getScore() < places.get(i).getScore())
|
---|
134 | {
|
---|
135 | _resultSet.get(s).setScore(places.get(i).getScore());
|
---|
136 | }
|
---|
137 | }
|
---|
138 | }
|
---|
139 | }
|
---|
140 | }
|
---|