Mercurial > repos > shellac > guppy_basecaller
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/env/lib/python3.7/site-packages/schema_salad/java/main_utils/IdMapLoader.java Sat May 02 07:14:21 2020 -0400 @@ -0,0 +1,53 @@ +package ${package}.utils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.TreeSet; + +public class IdMapLoader<T> implements Loader<T> { + private final Loader<T> innerLoader; + private final String mapSubject; + private final String mapPredicate; + + public IdMapLoader( + final Loader<T> innerLoader, final String mapSubject, final String mapPredicate) { + this.innerLoader = innerLoader; + this.mapSubject = mapSubject; + this.mapPredicate = mapPredicate; + } + + public T load( + final Object doc_, + final String baseUri, + final LoadingOptions loadingOptions, + final String docRoot) { + Object doc = doc_; + if (doc instanceof Map) { + final Map<String, Object> docMap = (Map<String, Object>) doc; + final List<Object> asList = new ArrayList(); + final TreeSet<String> sortedKeys = new TreeSet<String>(); + sortedKeys.addAll(docMap.keySet()); + for (final String key : sortedKeys) { + final Object el = docMap.get(key); + if (el instanceof Map) { + final Map<String, Object> v2 = new HashMap<String, Object>((Map<String, Object>) el); + v2.put(this.mapSubject, key); + asList.add(v2); + } else { + if (this.mapPredicate != null) { + final Map<String, Object> v3 = new HashMap<String, Object>(); + v3.put(this.mapPredicate, el); + v3.put(this.mapSubject, key); + asList.add(v3); + } else { + throw new ValidationException("No mapPredicate"); + } + } + } + doc = asList; + } + return this.innerLoader.load(doc, baseUri, loadingOptions); + } +}