Revision 379eb203
Added by Andreas Müller over 3 years ago
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/markup/FeatureSorter.java | ||
---|---|---|
1 | 1 |
/** |
2 |
*
|
|
2 |
* |
|
3 | 3 |
*/ |
4 | 4 |
package eu.etaxonomy.cdm.io.markup; |
5 | 5 |
|
... | ... | |
16 | 16 |
/** |
17 | 17 |
* This class is supposed to find the best sorting order for features (descriptive and other). |
18 | 18 |
* Currently it is not yet very sophisticated. |
19 |
* |
|
20 |
* @author a.mueller |
|
21 | 19 |
* |
20 |
* @author a.mueller |
|
22 | 21 |
*/ |
23 | 22 |
public class FeatureSorter { |
24 | 23 |
|
25 |
|
|
26 | 24 |
class FeatureStatistic{ |
27 | 25 |
|
28 | 26 |
private UUID uuid; |
... | ... | |
30 | 28 |
private int before = 0; //number of features before this feature |
31 | 29 |
private int after = 0; //number of features after this feature |
32 | 30 |
private int n = 0; //number of occurrences of this feature |
33 |
|
|
31 |
|
|
34 | 32 |
public FeatureStatistic(UUID uuid) { |
35 | 33 |
this.uuid = uuid; |
36 | 34 |
} |
... | ... | |
46 | 44 |
public String toString(){ |
47 | 45 |
return uuid != null? uuid.toString(): super.toString(); |
48 | 46 |
} |
49 |
|
|
50 | 47 |
} |
51 |
|
|
52 |
|
|
48 |
|
|
53 | 49 |
/** |
54 | 50 |
* Compute the order of features. |
55 | 51 |
* @param orderLists |
... | ... | |
72 | 68 |
|
73 | 69 |
|
74 | 70 |
private void removeEmptyLists(Map<String, List<FeatureSorterInfo>> listMap) { |
75 |
Set<String> keysToRemove = new HashSet<String>();
|
|
71 |
Set<String> keysToRemove = new HashSet<>(); |
|
76 | 72 |
for(String key : listMap.keySet()){ |
77 | 73 |
List<FeatureSorterInfo> list = listMap.get(key); |
78 | 74 |
if (list.isEmpty()){ |
... | ... | |
82 | 78 |
for (String key : keysToRemove){ |
83 | 79 |
listMap.remove(key); |
84 | 80 |
} |
85 |
|
|
81 |
|
|
86 | 82 |
} |
87 | 83 |
|
88 | 84 |
|
... | ... | |
92 | 88 |
* @param uuid |
93 | 89 |
*/ |
94 | 90 |
private Map<String, List<FeatureSorterInfo>> removeFromLists(Map<String, List<FeatureSorterInfo>> orderListsMap, UUID uuid) { |
95 |
Map<String, List<FeatureSorterInfo>> childLists = new HashMap<String, List<FeatureSorterInfo>>();
|
|
96 |
|
|
91 |
Map<String, List<FeatureSorterInfo>> childLists = new HashMap<>(); |
|
92 |
|
|
97 | 93 |
Set<String> keySet = orderListsMap.keySet(); |
98 | 94 |
Iterator<String> keySetIterator = keySet.iterator(); |
99 | 95 |
while (keySetIterator.hasNext()){ |
100 | 96 |
String key = keySetIterator.next(); |
101 |
List<FeatureSorterInfo> list = orderListsMap.get(key);
|
|
97 |
List<FeatureSorterInfo> list = orderListsMap.get(key); |
|
102 | 98 |
Iterator<FeatureSorterInfo> it = list.listIterator(); |
103 | 99 |
while (it.hasNext()){ |
104 | 100 |
FeatureSorterInfo info = it.next(); |
... | ... | |
116 | 112 |
return childLists; |
117 | 113 |
} |
118 | 114 |
|
119 |
|
|
120 | 115 |
private FeatureStatistic findBest(Map<UUID, FeatureStatistic> statisticMap) { |
121 | 116 |
FeatureStatistic result; |
122 | 117 |
Set<FeatureStatistic> highest = getOnlyHighestFeatures(statisticMap); |
... | ... | |
150 | 145 |
return result; |
151 | 146 |
} |
152 | 147 |
|
153 |
|
|
154 | 148 |
/** |
155 | 149 |
* If no feature is always highest this method can be called to use an alternative criteria |
156 |
* to find the "highest" feature.
|
|
157 |
*
|
|
150 |
* to find the "highest" feature. |
|
151 |
* |
|
158 | 152 |
* @param statisticMap |
159 | 153 |
* @return |
160 | 154 |
*/ |
... | ... | |
173 | 167 |
return result; |
174 | 168 |
} |
175 | 169 |
|
176 |
|
|
177 | 170 |
private Set<FeatureStatistic> getOnlyHighestFeatures(Map<UUID, FeatureStatistic> statisticMap) { |
178 |
Set<FeatureStatistic> result = new HashSet<FeatureStatistic>();
|
|
171 |
Set<FeatureStatistic> result = new HashSet<>(); |
|
179 | 172 |
for (FeatureStatistic statistic : statisticMap.values()){ |
180 | 173 |
if (statistic.isAlwaysHighest){ |
181 | 174 |
result.add(statistic); |
... | ... | |
186 | 179 |
|
187 | 180 |
|
188 | 181 |
private Map<UUID, FeatureStatistic> computeStatistic(Map<String,List<FeatureSorterInfo>> orderLists) { |
189 |
Map<UUID, FeatureStatistic> result = new HashMap<UUID, FeatureStatistic>();
|
|
182 |
Map<UUID, FeatureStatistic> result = new HashMap<>(); |
|
190 | 183 |
for (String key : orderLists.keySet()){ |
191 | 184 |
List<FeatureSorterInfo> list = orderLists.get(key); |
192 | 185 |
int n = list.size(); |
... | ... | |
199 | 192 |
return result; |
200 | 193 |
} |
201 | 194 |
|
202 |
|
|
203 | 195 |
private FeatureStatistic getFeatureStatistic(FeatureSorterInfo info, Map<UUID, FeatureStatistic> statisticMap) { |
204 | 196 |
UUID uuid = info.getUuid(); |
205 | 197 |
FeatureStatistic result = statisticMap.get(uuid); |
Also available in: Unified diff
cleanup