Mercurial > repos > shellac > guppy_basecaller
diff env/lib/python3.7/site-packages/schema_salad/java/main_utils/OneOrListOf.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/OneOrListOf.java Sat May 02 07:14:21 2020 -0400 @@ -0,0 +1,48 @@ +package ${package}.utils; + +import java.util.List; +import java.util.Optional; + +public class OneOrListOf<T> { + private Optional<T> object; + private Optional<List<T>> objects; + + private OneOrListOf(final T object, final List<T> objects) { + this.object = Optional.ofNullable(object); + this.objects = Optional.ofNullable(objects); + } + + public static <T> OneOrListOf<T> oneOf(T object) { + return new OneOrListOf(object, null); + } + + public static <T> OneOrListOf<T> listOf(List<T> objects) { + assert objects != null; + return new OneOrListOf(null, objects); + } + + public boolean isOne() { + return this.getOneOptional().isPresent(); + } + + public boolean isList() { + return this.getListOptional().isPresent(); + } + + public Optional<T> getOneOptional() { + return this.object; + } + + public Optional<List<T>> getListOptional() { + return this.objects; + } + + public T getOne() { + return this.getOneOptional().get(); + } + + public List<T> getList() { + return this.getListOptional().get(); + } + +}