This is an automated email from the ASF dual-hosted git repository. danhaywood pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/isis.git
commit a2723b8f949eb4debacee5e79007bae1ee792370 Author: danhaywood <d...@haywood-associates.co.uk> AuthorDate: Sun Aug 12 16:47:08 2018 +0100 Revert "Revert "ISIS-1841: minor internal API polishing"" This reverts commit 80fdfae05d78ed95e17ef412f949ad2ead9b5f6e. --- .../apache/isis/commons/internal/base/_Bytes.java | 2 +- .../apache/isis/commons/internal/base/_Lazy.java | 3 + .../isis/commons/internal/base/_Reduction.java | 5 +- .../isis/commons/internal/base/_Strings.java | 9 ++- .../apache/isis/commons/internal/base/_With.java | 71 ++++++++++++++++++---- .../isis/commons/internal/collections/_Arrays.java | 13 ++-- .../commons/internal/collections/_Collections.java | 5 +- .../collections/_Collections_Collector.java | 7 ++- .../isis/commons/internal/collections/_Lists.java | 9 +-- .../isis/commons/internal/collections/_Maps.java | 5 +- .../commons/internal/collections/_Multimaps.java | 15 ++--- .../isis/commons/internal/collections/_Sets.java | 7 ++- .../isis/commons/internal/context/_Context.java | 3 +- .../isis/commons/internal/context/_Plugin.java | 10 +-- .../commons/internal/exceptions/_Exceptions.java | 6 +- .../internal/memento/_Mementos_MementoDefault.java | 15 ++--- .../isis/commons/internal/resources/_Resource.java | 15 +++++ .../plugins/classdiscovery/ClassDiscovery.java | 15 ++++- 18 files changed, 151 insertions(+), 64 deletions(-) diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Bytes.java b/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Bytes.java index 13ab5e8..09ee3ca 100644 --- a/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Bytes.java +++ b/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Bytes.java @@ -223,7 +223,7 @@ public final class _Bytes { // -- SPECIAL COMPOSITES - // using naming convention asX../ofX.. + // using naming convention asX .. encode / ofX .. decode public final static BytesOperator asUrlBase64 = operator() .andThen(bytes->encodeToBase64(Base64.getUrlEncoder(), bytes)); diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Lazy.java b/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Lazy.java index af4eb96..f3ba221 100644 --- a/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Lazy.java +++ b/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Lazy.java @@ -49,6 +49,9 @@ public final class _Lazy<T> implements Supplier<T> { this.supplier = requires(supplier, "supplier"); } + /** + * @return whether this lazy got initialized and holds a memoized value + */ public boolean isMemoized() { return memoized; } diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Reduction.java b/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Reduction.java index caa6396..0d9ce88 100644 --- a/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Reduction.java +++ b/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Reduction.java @@ -16,7 +16,8 @@ */ package org.apache.isis.commons.internal.base; -import java.util.Objects; +import static org.apache.isis.commons.internal.base._With.requires; + import java.util.Optional; import java.util.function.BinaryOperator; import java.util.function.Consumer; @@ -68,7 +69,7 @@ public final class _Reduction<T> implements Consumer<T> { } private _Reduction(@Nullable T identity, BinaryOperator<T> accumulator, boolean initialized) { - Objects.requireNonNull(accumulator); + requires(accumulator, "accumulator"); this.initialized = initialized; this.result = identity; this.accumulator = accumulator; diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Strings.java b/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Strings.java index eace548..273d44a 100644 --- a/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Strings.java +++ b/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Strings.java @@ -266,12 +266,15 @@ public final class _Strings { * @throws {@link IllegalArgumentException} if {@code separator} is empty */ public static Stream<String> splitThenStream(@Nullable final String input, final String separator) { - if(isEmpty(separator)) + if(isEmpty(separator)) { throw new IllegalArgumentException("a non empty separator is required"); - if(isEmpty(input)) + } + if(isEmpty(input)) { return Stream.of(); - if(!input.contains(separator)) + } + if(!input.contains(separator)) { return Stream.of(input); + } return StreamSupport.stream( Spliterators.spliteratorUnknownSize(splitIterator(input, separator), Spliterator.ORDERED), diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/base/_With.java b/core/commons/src/main/java/org/apache/isis/commons/internal/base/_With.java index bdecef2..726e15b 100644 --- a/core/commons/src/main/java/org/apache/isis/commons/internal/base/_With.java +++ b/core/commons/src/main/java/org/apache/isis/commons/internal/base/_With.java @@ -205,6 +205,13 @@ public final class _With<T> { // -- PARAMETER NON-NULL CHECK + /** + * Allows for convenient named parameter non-null-check. + * @param obj target for the non-null-check + * @param paramName to use for the exception message, when the non-null-check fails + * @return {@code obj!=null ? obj : throw NullPointerException} + * @throws NullPointerException if {@code obj} is {@code null} + */ public static <T> T requires(@Nullable T obj, String paramName) { if (obj == null) { throw new NullPointerException(String.format("Parameter '%s' is required to be non-null.", paramName)); @@ -214,28 +221,68 @@ public final class _With<T> { // -- CONVENIENT CONSTRUCTORS - public static <X> ArrayList<X> arrayList(Consumer<ArrayList<X>> consumer) { - return accept(new ArrayList<>(), consumer); + /** + * Allows for single line instantiation and initialization of an Object. + * @param factory + * @param initializer + * @return a new Object as provided by {@code factory} after calling the {@code initializer} on it + */ + public static <T> T create(Supplier<T> factory, Consumer<T> initializer) { + return accept(factory.get(), initializer); + } + + /** + * Allows for single line instantiation and initialization of an ArrayList. + * @param initializer + * @return a new ArrayList after calling the {@code initializer} on it + */ + public static <X> ArrayList<X> arrayList(Consumer<ArrayList<X>> initializer) { + return create(ArrayList::new, initializer); } - public static <X> HashSet<X> hashSet(Consumer<HashSet<X>> consumer) { - return accept(new HashSet<>(), consumer); + /** + * Allows for single line instantiation and initialization of a HashSet. + * @param initializer + * @return a new HashSet after calling the {@code initializer} on it + */ + public static <X> HashSet<X> hashSet(Consumer<HashSet<X>> initializer) { + return create(HashSet::new, initializer); } - public static <X> TreeSet<X> treeSet(Consumer<TreeSet<X>> consumer) { - return accept(new TreeSet<>(), consumer); + /** + * Allows for single line instantiation and initialization of a TreeSet. + * @param initializer + * @return a new TreeSet after calling the {@code initializer} on it + */ + public static <X> TreeSet<X> treeSet(Consumer<TreeSet<X>> initializer) { + return create(TreeSet::new, initializer); } - public static <K, V> HashMap<K, V> hashMap(Consumer<HashMap<K, V>> consumer) { - return accept(new HashMap<K, V>(), consumer); + /** + * Allows for single line instantiation and initialization of a HashMap. + * @param initializer + * @return a new HashMap after calling the {@code initializer} on it + */ + public static <K, V> HashMap<K, V> hashMap(Consumer<HashMap<K, V>> initializer) { + return accept(new HashMap<K, V>(), initializer); } - public static <K, V> TreeMap<K, V> treeMap(Consumer<TreeMap<K, V>> consumer) { - return accept(new TreeMap<K, V>(), consumer); + /** + * Allows for single line instantiation and initialization of a TreeMap. + * @param initializer + * @return a new TreeMap after calling the {@code initializer} on it + */ + public static <K, V> TreeMap<K, V> treeMap(Consumer<TreeMap<K, V>> initializer) { + return accept(new TreeMap<K, V>(), initializer); } - public static StringBuilder stringBuilder(Consumer<StringBuilder> consumer) { - return accept(new StringBuilder(), consumer); + /** + * Allows for single line instantiation and initialization of a StringBuilder. + * @param initializer + * @return a new StringBuilder after calling the {@code initializer} on it + */ + public static StringBuilder stringBuilder(Consumer<StringBuilder> initializer) { + return create(StringBuilder::new, initializer); } diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Arrays.java b/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Arrays.java index 2f1bfc2..0e508ef 100644 --- a/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Arrays.java +++ b/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Arrays.java @@ -19,9 +19,10 @@ package org.apache.isis.commons.internal.collections; +import static org.apache.isis.commons.internal.base._With.requires; + import java.lang.reflect.Array; import java.util.Collection; -import java.util.Objects; import java.util.stream.Collector; import javax.annotation.Nullable; @@ -75,7 +76,7 @@ public final class _Arrays { * @return */ public static <T> Collector<T,?,T[]> toArray(final Class<T> componentType, final int length){ - Objects.requireNonNull(componentType); + requires(componentType, "componentType"); return new _Arrays_Collector<T>(componentType, length); } @@ -85,7 +86,7 @@ public final class _Arrays { * @return */ public static <T> Collector<T,?,T[]> toArray(final Class<T> componentType){ - Objects.requireNonNull(componentType); + requires(componentType, "componentType"); return new _Arrays_CollectorUnknownSize<T>(componentType); } @@ -99,7 +100,7 @@ public final class _Arrays { */ @SafeVarargs public static <T> T[] combine(T first, @Nullable T... rest) { - Objects.requireNonNull(first); + requires(first, "first"); final int restLength = _NullSafe.size(rest); final T[] all = _Casts.uncheckedCast(Array.newInstance(first.getClass(), restLength+1)); all[0] = first; @@ -140,7 +141,7 @@ public final class _Arrays { * have been copied (non-null) */ public static <T> T[] toArray(@Nullable final Collection<? extends T> collection, final Class<T> componentType) { - Objects.requireNonNull(componentType); + requires(componentType, "componentType"); return _NullSafe.stream(collection) .collect(toArray(componentType, collection!=null ? collection.size() : 0)); } @@ -154,7 +155,7 @@ public final class _Arrays { * have been copied (non-null) */ public static <T> T[] toArray(@Nullable final Iterable<? extends T> iterable, final Class<T> componentType) { - Objects.requireNonNull(componentType); + requires(componentType, "componentType"); if(iterable!=null && (iterable instanceof Collection)) { return toArray((Collection<? extends T>) iterable, componentType); } diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Collections.java b/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Collections.java index 1324d11..ea42a3e 100644 --- a/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Collections.java +++ b/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Collections.java @@ -19,6 +19,8 @@ package org.apache.isis.commons.internal.collections; +import static org.apache.isis.commons.internal.base._With.requires; + import java.lang.reflect.Field; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; @@ -29,7 +31,6 @@ import java.util.Comparator; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; -import java.util.Objects; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -203,7 +204,7 @@ public final class _Collections { */ public static <T> Collector<T, ?, ? extends Collection<T>> toUnmodifiableOfType(Class<?> typeOfCollection) { - Objects.requireNonNull(typeOfCollection); + requires(typeOfCollection, "typeOfCollection"); if(SortedSet.class.equals(typeOfCollection)) { return toUnmodifiableSortedSet(); diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Collections_Collector.java b/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Collections_Collector.java index 7c81d65..9eaf4cf 100644 --- a/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Collections_Collector.java +++ b/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Collections_Collector.java @@ -19,9 +19,10 @@ package org.apache.isis.commons.internal.collections; +import static org.apache.isis.commons.internal.base._With.requires; + import java.util.Collection; import java.util.Collections; -import java.util.Objects; import java.util.Set; import java.util.function.BiConsumer; import java.util.function.BinaryOperator; @@ -42,8 +43,8 @@ class _Collections_Collector<T, C extends Collection<T>> implements Collector<T, private final Function<C, C> finisher; _Collections_Collector(Supplier<C> supplier, Function<C, C> finisher) { - this.supplier = Objects.requireNonNull(supplier); - this.finisher = Objects.requireNonNull(finisher); + this.supplier = requires(supplier, "supplier"); + this.finisher = requires(finisher, "finisher"); } @Override diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Lists.java b/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Lists.java index ac50103..5b163ae 100644 --- a/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Lists.java +++ b/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Lists.java @@ -19,13 +19,14 @@ package org.apache.isis.commons.internal.collections; +import static org.apache.isis.commons.internal.base._With.requires; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.LinkedList; import java.util.List; -import java.util.Objects; import java.util.function.Function; import java.util.stream.Collectors; @@ -66,7 +67,7 @@ public final class _Lists { * @return non null */ public static <T> List<T> singleton(T element) { - Objects.requireNonNull(element); // don't accept null element + requires(element, "element"); // don't accept null element return Collections.singletonList(element); } @@ -87,7 +88,7 @@ public final class _Lists { */ @SafeVarargs public static <T> List<T> of(T ... elements) { - Objects.requireNonNull(elements); // don't accept null as argument + requires(elements, "elements"); // don't accept null as argument if(elements.length==0) { return Collections.emptyList(); } @@ -150,7 +151,7 @@ public final class _Lists { if(input==null) { return Collections.emptyList(); } - Objects.requireNonNull(mapper); + requires(mapper, "mapper"); return input.stream() .map(mapper) .collect(Collectors.toList()); diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Maps.java b/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Maps.java index da4ef63..32b409c 100644 --- a/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Maps.java +++ b/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Maps.java @@ -19,12 +19,13 @@ package org.apache.isis.commons.internal.collections; +import static org.apache.isis.commons.internal.base._With.requires; + import java.util.AbstractMap; import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; -import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Stream; @@ -78,7 +79,7 @@ public final class _Maps { @SafeVarargs public static <K, V> Map<K, V> unmodifiableEntries(Map.Entry<? extends K,? extends V>... entries) { - Objects.requireNonNull(entries); // don't accept null elements + requires(entries, "entries"); // don't accept null elements if(entries.length==0) { return Collections.emptyMap(); } diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Multimaps.java b/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Multimaps.java index de966bf..7d4f291 100644 --- a/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Multimaps.java +++ b/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Multimaps.java @@ -19,13 +19,14 @@ package org.apache.isis.commons.internal.collections; +import static org.apache.isis.commons.internal.base._With.requires; + import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Set; import java.util.function.Supplier; @@ -102,8 +103,8 @@ public class _Multimaps { public static <K, V> ListMultimap<K, V> newListMultimap( final Supplier<Map<K, List<V>>> mapFactory, final Supplier<List<V>> elementCollectionFactory){ - Objects.requireNonNull(mapFactory); - Objects.requireNonNull(elementCollectionFactory); + requires(mapFactory, "mapFactory"); + requires(elementCollectionFactory, "elementCollectionFactory"); return new ListMultimap<K, V>() { @@ -134,8 +135,8 @@ public class _Multimaps { public static <K, V> SetMultimap<K, V> newSetMultimap( final Supplier<Map<K, Set<V>>> mapFactory, final Supplier<Set<V>> elementCollectionFactory){ - Objects.requireNonNull(mapFactory); - Objects.requireNonNull(elementCollectionFactory); + requires(mapFactory, "mapFactory"); + requires(elementCollectionFactory, "elementCollectionFactory"); return new SetMultimap<K, V>() { @@ -166,8 +167,8 @@ public class _Multimaps { public static <K1, K2, V> MapMultimap<K1, K2, V> newMapMultimap( final Supplier<Map<K1, Map<K2, V>>> mapFactory, final Supplier<Map<K2, V>> elementMapFactory){ - Objects.requireNonNull(mapFactory); - Objects.requireNonNull(elementMapFactory); + requires(mapFactory, "mapFactory"); + requires(elementMapFactory, "elementMapFactory"); return new MapMultimap<K1, K2, V>() { diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Sets.java b/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Sets.java index 90f1f42..9d1d08e 100644 --- a/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Sets.java +++ b/core/commons/src/main/java/org/apache/isis/commons/internal/collections/_Sets.java @@ -19,12 +19,13 @@ package org.apache.isis.commons.internal.collections; +import static org.apache.isis.commons.internal.base._With.requires; + import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.LinkedHashSet; -import java.util.Objects; import java.util.Set; import java.util.TreeSet; import java.util.concurrent.ConcurrentHashMap; @@ -60,7 +61,7 @@ public final class _Sets { * @return non null */ public static <T> Set<T> singleton(T element) { - Objects.requireNonNull(element); // don't accept null element + requires(element, "element"); // don't accept null element return Collections.singleton(element); } @@ -81,7 +82,7 @@ public final class _Sets { */ @SafeVarargs public static <T> Set<T> of(T ... elements) { - Objects.requireNonNull(elements); // don't accept null as argument + requires(elements, "elements");// don't accept null as argument if(elements.length==0) { return Collections.emptySet(); } diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/context/_Context.java b/core/commons/src/main/java/org/apache/isis/commons/internal/context/_Context.java index 4699d6e..62244fb 100644 --- a/core/commons/src/main/java/org/apache/isis/commons/internal/context/_Context.java +++ b/core/commons/src/main/java/org/apache/isis/commons/internal/context/_Context.java @@ -26,7 +26,6 @@ import static org.apache.isis.commons.internal.base._With.requires; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.function.Function; import java.util.function.Supplier; @@ -209,7 +208,7 @@ public final class _Context { if(!alreadyRegistered || override) { // let writes to the map be atomic synchronized (singletonMap) { - singletonMap.put(toKey(ClassLoader.class), Objects.requireNonNull(classLoader, "classLoader required")); + singletonMap.put(toKey(ClassLoader.class), requires(classLoader, "classLoader")); } } } diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/context/_Plugin.java b/core/commons/src/main/java/org/apache/isis/commons/internal/context/_Plugin.java index afe9fa4..278b7b4 100644 --- a/core/commons/src/main/java/org/apache/isis/commons/internal/context/_Plugin.java +++ b/core/commons/src/main/java/org/apache/isis/commons/internal/context/_Plugin.java @@ -19,22 +19,24 @@ package org.apache.isis.commons.internal.context; +import static org.apache.isis.commons.internal.base._With.requires; + import java.io.File; import java.net.URL; import java.net.URLClassLoader; -import java.util.Objects; import java.util.ServiceLoader; import java.util.Set; import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import org.apache.isis.commons.internal.base._Casts; import org.apache.isis.commons.internal.base._NullSafe; import org.apache.isis.commons.internal.collections._Sets; import org.apache.isis.core.plugins.PluginResolveException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * <h1>- internal use only -</h1> @@ -68,7 +70,7 @@ public final class _Plugin { * @return non null */ public static <S> Set<S> loadAll(Class<S> service){ - Objects.requireNonNull(service); + requires(service, "service"); ServiceLoader<S> loader = ServiceLoader.load(service, _Context.getDefaultClassLoader()); diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/exceptions/_Exceptions.java b/core/commons/src/main/java/org/apache/isis/commons/internal/exceptions/_Exceptions.java index 1e5dd08..6f7cca2 100644 --- a/core/commons/src/main/java/org/apache/isis/commons/internal/exceptions/_Exceptions.java +++ b/core/commons/src/main/java/org/apache/isis/commons/internal/exceptions/_Exceptions.java @@ -23,7 +23,6 @@ import static org.apache.isis.commons.internal.base._With.requires; import java.util.Collections; import java.util.List; -import java.util.Objects; import java.util.Optional; import java.util.function.Consumer; import java.util.function.Function; @@ -70,7 +69,7 @@ public final class _Exceptions { * @return */ public static final IllegalArgumentException unmatchedCase(String format, @Nullable Object _case) { - Objects.requireNonNull(format); + requires(format, "format"); return new IllegalArgumentException(String.format(format, _case)); } @@ -97,9 +96,8 @@ public final class _Exceptions { * return 0; *}</pre> * - * @return */ - public static IllegalStateException throwNotImplemented() { + public static void throwNotImplemented() { throw notImplemented(); } diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/memento/_Mementos_MementoDefault.java b/core/commons/src/main/java/org/apache/isis/commons/internal/memento/_Mementos_MementoDefault.java index 60e5734..7857743 100644 --- a/core/commons/src/main/java/org/apache/isis/commons/internal/memento/_Mementos_MementoDefault.java +++ b/core/commons/src/main/java/org/apache/isis/commons/internal/memento/_Mementos_MementoDefault.java @@ -19,6 +19,8 @@ package org.apache.isis.commons.internal.memento; +import static org.apache.isis.commons.internal.base._With.requires; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -27,7 +29,6 @@ import java.io.ObjectOutputStream; import java.io.ObjectStreamClass; import java.io.Serializable; import java.util.Map; -import java.util.Objects; import java.util.Set; import javax.annotation.Nullable; @@ -64,9 +65,9 @@ class _Mementos_MementoDefault implements _Mementos.Memento { SerializingAdapter serializer, Map<String, Serializable> valuesByKey) { - this.codec = Objects.requireNonNull(codec); - this.serializer = Objects.requireNonNull(serializer); - this.valuesByKey = Objects.requireNonNull(valuesByKey); + this.codec = requires(codec, "codec"); + this.serializer = requires(serializer, "serializer"); + this.valuesByKey = requires(valuesByKey, "valuesByKey"); } @Override @@ -74,7 +75,7 @@ class _Mementos_MementoDefault implements _Mementos.Memento { if(value==null) { return this; //no-op, there is no point in storing null values } - Objects.requireNonNull(name); + requires(name, "name"); valuesByKey.put(name, serializer.write(value)); return this; } @@ -107,12 +108,12 @@ class _Mementos_MementoDefault implements _Mementos.Memento { // -- PARSER static Memento parse(EncoderDecoder codec, SerializingAdapter serializer, @Nullable String str) { - Objects.requireNonNull(codec); + requires(codec, "codec"); if(_NullSafe.isEmpty(str)) { return null; } try(ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(codec.decode(str))) { - //override ObjectInputStream's classloading + //override ObjectInputStream's class-loading @Override protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/resources/_Resource.java b/core/commons/src/main/java/org/apache/isis/commons/internal/resources/_Resource.java index e941ba7..32be534 100644 --- a/core/commons/src/main/java/org/apache/isis/commons/internal/resources/_Resource.java +++ b/core/commons/src/main/java/org/apache/isis/commons/internal/resources/_Resource.java @@ -44,6 +44,12 @@ public final class _Resource { // -- CLASS PATH RESOURCE LOADING + /** + * Returns the resource with path {@code resourceName} relative to {@code contextClass} as an InputStream. + * @param contextClass + * @param resourceName + * @return An input stream for reading the resource, or null if the resource could not be found. + */ public static InputStream load(Class<?> contextClass, String resourceName) { requires(contextClass, "contextClass"); @@ -55,6 +61,15 @@ public final class _Resource { .getResourceAsStream(absoluteResourceName); } + /** + * Returns the resource with path {@code resourceName} relative to {@code contextClass} as a String + * conforming to the given {@code charset}. + * @param contextClass + * @param resourceName + * @param charset + * @return The resource as a String, or null if the resource could not be found. + * @throws IOException + */ public static String loadAsString(Class<?> contextClass, String resourceName, Charset charset) throws IOException { final InputStream is = load(contextClass, resourceName); return _Strings.ofBytes(_Bytes.of(is), charset); diff --git a/core/commons/src/main/java/org/apache/isis/core/plugins/classdiscovery/ClassDiscovery.java b/core/commons/src/main/java/org/apache/isis/core/plugins/classdiscovery/ClassDiscovery.java index 92c128d..b42ae0d 100644 --- a/core/commons/src/main/java/org/apache/isis/core/plugins/classdiscovery/ClassDiscovery.java +++ b/core/commons/src/main/java/org/apache/isis/core/plugins/classdiscovery/ClassDiscovery.java @@ -30,12 +30,23 @@ import java.util.Set; */ public interface ClassDiscovery { - //TODO missing java-doc + /** + * Searches this application's class path for any classes that are annotated with {@code annotation}. + * @param annotation + * @return non-null set of discovered classes + */ public Set<Class<?>> getTypesAnnotatedWith(Class<? extends Annotation> annotation); - //TODO missing java-doc + /** + * Searches this application's class path for any classes that are subclass to {@code type}. + * @param type + * @return non-null set of discovered classes + */ public <T> Set<Class<? extends T>> getSubTypesOf(Class<T> type); + /** + * @return an instance of {@code ClassDiscovery} that always returns empty search result + */ public static ClassDiscovery empty() { return new ClassDiscovery() {