comparison env/lib/python3.7/site-packages/schema_salad/java/main_utils/IdMapLoader.java @ 0:26e78fe6e8c4 draft

"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
author shellac
date Sat, 02 May 2020 07:14:21 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:26e78fe6e8c4
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 }