Mercurial > repos > shellac > guppy_basecaller
diff env/lib/python3.7/site-packages/schema_salad/java/main_utils/OneOrListOfLoader.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/OneOrListOfLoader.java Sat May 02 07:14:21 2020 -0400 @@ -0,0 +1,35 @@ +package ${package}.utils; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + + +public class OneOrListOfLoader<T> implements Loader<OneOrListOf<T>> { + private final Loader<T> oneLoader; + private final Loader<List<T>> listLoader; + + public OneOrListOfLoader(Loader<T> oneLoader, Loader<List<T>> listLoader) { + this.oneLoader = oneLoader; + this.listLoader = listLoader; + } + + public OneOrListOf<T> load( + final Object doc, + final String baseUri, + final LoadingOptions loadingOptions, + final String docRoot) { + final List<ValidationException> errors = new ArrayList(); + try { + return OneOrListOf.oneOf(this.oneLoader.load(doc, baseUri, loadingOptions, docRoot)); + } catch (ValidationException e) { + errors.add(e); + } + try { + return OneOrListOf.listOf(this.listLoader.load(doc, baseUri, loadingOptions, docRoot)); + } catch (ValidationException e) { + errors.add(e); + } + throw new ValidationException("Failed to one or list of of type", errors); + } +}