Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/schema_salad/java/main_utils/IdMapLoader.java @ 5:9b1c78e6ba9c draft default tip
"planemo upload commit 6c0a8142489327ece472c84e558c47da711a9142"
author | shellac |
---|---|
date | Mon, 01 Jun 2020 08:59:25 -0400 |
parents | 79f47841a781 |
children |
comparison
equal
deleted
inserted
replaced
4:79f47841a781 | 5:9b1c78e6ba9c |
---|---|
1 package ${package}.utils; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.HashMap; | |
5 import java.util.List; | |
6 import java.util.Map; | |
7 import java.util.TreeSet; | |
8 | |
9 public class IdMapLoader<T> implements Loader<T> { | |
10 private final Loader<T> innerLoader; | |
11 private final String mapSubject; | |
12 private final String mapPredicate; | |
13 | |
14 public IdMapLoader( | |
15 final Loader<T> innerLoader, final String mapSubject, final String mapPredicate) { | |
16 this.innerLoader = innerLoader; | |
17 this.mapSubject = mapSubject; | |
18 this.mapPredicate = mapPredicate; | |
19 } | |
20 | |
21 public T load( | |
22 final Object doc_, | |
23 final String baseUri, | |
24 final LoadingOptions loadingOptions, | |
25 final String docRoot) { | |
26 Object doc = doc_; | |
27 if (doc instanceof Map) { | |
28 final Map<String, Object> docMap = (Map<String, Object>) doc; | |
29 final List<Object> asList = new ArrayList(); | |
30 final TreeSet<String> sortedKeys = new TreeSet<String>(); | |
31 sortedKeys.addAll(docMap.keySet()); | |
32 for (final String key : sortedKeys) { | |
33 final Object el = docMap.get(key); | |
34 if (el instanceof Map) { | |
35 final Map<String, Object> v2 = new HashMap<String, Object>((Map<String, Object>) el); | |
36 v2.put(this.mapSubject, key); | |
37 asList.add(v2); | |
38 } else { | |
39 if (this.mapPredicate != null) { | |
40 final Map<String, Object> v3 = new HashMap<String, Object>(); | |
41 v3.put(this.mapPredicate, el); | |
42 v3.put(this.mapSubject, key); | |
43 asList.add(v3); | |
44 } else { | |
45 throw new ValidationException("No mapPredicate"); | |
46 } | |
47 } | |
48 } | |
49 doc = asList; | |
50 } | |
51 return this.innerLoader.load(doc, baseUri, loadingOptions); | |
52 } | |
53 } |