File tree 1 file changed +19
-0
lines changed
src/main/java/org/ohdsi/webapi/service
1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import java .util .ArrayList ;
4
4
import java .util .Collection ;
5
+ import java .util .Collections ;
6
+ import java .util .Comparator ;
5
7
import javax .ws .rs .GET ;
6
8
import javax .ws .rs .Path ;
7
9
import javax .ws .rs .PathParam ;
18
20
@ Component
19
21
public class SourceService extends AbstractDaoService {
20
22
23
+ public class SortByKey implements Comparator <SourceInfo >
24
+ {
25
+ private boolean isAscending ;
26
+
27
+ public SortByKey (boolean ascending ) {
28
+ isAscending = ascending ;
29
+ }
30
+
31
+ public SortByKey () {
32
+ this (true );
33
+ }
34
+
35
+ public int compare (SourceInfo s1 , SourceInfo s2 ) {
36
+ return s1 .sourceKey .compareTo (s2 .sourceKey ) * (isAscending ? 1 : -1 );
37
+ }
38
+ }
21
39
@ Autowired
22
40
private SourceRepository sourceRepository ;
23
41
@@ -33,6 +51,7 @@ public Collection<SourceInfo> getSources() {
33
51
for (Source source : sourceRepository .findAll ()) {
34
52
sources .add (new SourceInfo (source ));
35
53
}
54
+ Collections .sort (sources , new SortByKey ());
36
55
cachedSources = sources ;
37
56
}
38
57
return cachedSources ;
You can’t perform that action at this time.
0 commit comments