From 7c7dbace613afa2e6e68f7a94929832fee77cc4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Prante?= Date: Sat, 23 Mar 2024 21:58:08 +0100 Subject: [PATCH] remove config logger loading in ConfigLoader --- config/src/main/java/module-info.java | 3 +-- .../java/org/xbib/config/ConfigLoader.java | 14 +------------- .../datastructures/api/SortedSetMultimap.java | 8 +------- .../common/AbstractMultiMap.java | 2 +- .../immutable/order/Ordering.java | 13 +++++-------- .../datastructures/tiny/TinyMultiMap.java | 6 ++++++ .../datastructures/tiny/TinyMultiMapTest.java | 19 ++++++++++++++++++- gradle.properties | 2 +- settings.gradle | 5 ++--- 9 files changed, 36 insertions(+), 36 deletions(-) diff --git a/config/src/main/java/module-info.java b/config/src/main/java/module-info.java index d365de4..cdb8691 100644 --- a/config/src/main/java/module-info.java +++ b/config/src/main/java/module-info.java @@ -4,10 +4,9 @@ import org.xbib.config.SystemConfigLogger; import org.xbib.settings.SettingsLoader; module org.xbib.config { + requires transitive org.xbib.settings.datastructures; exports org.xbib.config; uses ConfigLogger; uses SettingsLoader; provides ConfigLogger with NullConfigLogger, SystemConfigLogger; - requires org.xbib.settings.api; - requires transitive org.xbib.settings.datastructures; } diff --git a/config/src/main/java/org/xbib/config/ConfigLoader.java b/config/src/main/java/org/xbib/config/ConfigLoader.java index 6505a07..854dfb4 100644 --- a/config/src/main/java/org/xbib/config/ConfigLoader.java +++ b/config/src/main/java/org/xbib/config/ConfigLoader.java @@ -16,8 +16,6 @@ import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Optional; -import java.util.ServiceLoader; import java.util.stream.Collectors; import org.xbib.settings.Settings; import org.xbib.settings.SettingsBuilder; @@ -36,18 +34,8 @@ public class ConfigLoader { private ConfigLoader() { } - private static class Holder { - private static ConfigLogger createConfigLogger() { - ServiceLoader serviceLoader = ServiceLoader.load(ConfigLogger.class); - Optional optionalConfigLogger = serviceLoader.findFirst(); - return optionalConfigLogger.orElse(new NullConfigLogger()); - } - - private static final ConfigLoader configLoader = new ConfigLoader().withLogger(createConfigLogger()); - } - public static ConfigLoader getInstance() { - return Holder.configLoader; + return new ConfigLoader(); } public ConfigLoader withLogger(ConfigLogger logger) { diff --git a/datastructures-api/src/main/java/org/xbib/datastructures/api/SortedSetMultimap.java b/datastructures-api/src/main/java/org/xbib/datastructures/api/SortedSetMultimap.java index 44c8499..86d6d2d 100644 --- a/datastructures-api/src/main/java/org/xbib/datastructures/api/SortedSetMultimap.java +++ b/datastructures-api/src/main/java/org/xbib/datastructures/api/SortedSetMultimap.java @@ -71,13 +71,7 @@ public interface SortedSetMultimap * behavior as {@link #get}, returning a live collection. When passed a key that is not present, * however, {@code asMap().get(Object)} returns {@code null} instead of an empty collection. * - *

Note: The returned map's values are guaranteed to be of type {@link SortedSet}. To - * obtain this map with the more specific generic type {@code Map>}, call {@link - * Multimaps#asMap(SortedSetMultimap)} instead. However, the returned map itself is - * not necessarily a {@link SortedMap}: A {@code SortedSetMultimap} must expose the values - * for a given key in sorted order, but it need not expose the keys in sorted order. - * Individual {@code SortedSetMultimap} implementations, like those built with {@link - * MultimapBuilder#treeKeys()}, may make additional guarantees. + *

Note: The returned map's values are guaranteed to be of type {@link SortedSet}. */ @Override Map> asMap(); diff --git a/datastructures-common/src/main/java/org/xbib/datastructures/common/AbstractMultiMap.java b/datastructures-common/src/main/java/org/xbib/datastructures/common/AbstractMultiMap.java index d93438d..37d67fe 100644 --- a/datastructures-common/src/main/java/org/xbib/datastructures/common/AbstractMultiMap.java +++ b/datastructures-common/src/main/java/org/xbib/datastructures/common/AbstractMultiMap.java @@ -15,7 +15,7 @@ import java.util.Set; */ public abstract class AbstractMultiMap implements MultiMap { - private final Map> map; + protected final Map> map; public AbstractMultiMap() { this(null); diff --git a/datastructures-immutable/src/main/java/org/xbib/datastructures/immutable/order/Ordering.java b/datastructures-immutable/src/main/java/org/xbib/datastructures/immutable/order/Ordering.java index 93e2f3a..2f0d518 100644 --- a/datastructures-immutable/src/main/java/org/xbib/datastructures/immutable/order/Ordering.java +++ b/datastructures-immutable/src/main/java/org/xbib/datastructures/immutable/order/Ordering.java @@ -95,8 +95,7 @@ import static org.xbib.datastructures.immutable.ImmutableMap.checkNonnegative; *

For Java 8 users

* *

If you are using Java 8, this class is now obsolete. Most of its functionality is now provided - * by {@link java.util.stream.Stream Stream} and by {@link Comparator} itself, and the rest can now - * be found as static methods in our new {@link Comparators} class. See each method below for + * by {@link java.util.stream.Stream Stream} and by {@link Comparator} itself. See each method below for * further instructions. Whenever possible, you should change any references of type {@code * Ordering} to be of type {@code Comparator} instead. However, at this time we have no plan to * deprecate this class. @@ -393,8 +392,6 @@ public abstract class Ordering implements Comparator { *

Note that {@code ordering.lexicographical().reverse()} is not equivalent to {@code * ordering.reverse().lexicographical()} (consider how each would order {@code [1]} and {@code [1, * 1]}). - * - *

Java 8 users: Use {@link Comparators#lexicographical(Comparator)} instead. */ // type parameter lets us avoid the extra in statements like: // Ordering> o = @@ -698,7 +695,7 @@ public abstract class Ordering implements Comparator { * only when the resulting list may need further modification, or may contain {@code null}. The * input is not modified. The returned list has random access. * - *

Unlike {@link Sets#newTreeSet(Iterable)}, this method does not discard elements that are + *

Unlike {@link java.util.Sets#newTreeSet(Iterable)}, this method does not discard elements that are * duplicates according to the comparator. The sort performed is stable, meaning that such * elements will appear in the returned list in the same order they appeared in {@code elements}. * @@ -719,7 +716,7 @@ public abstract class Ordering implements Comparator { * Returns an immutable list containing {@code elements} sorted by this ordering. The input * is not modified. * - *

Unlike {@link Sets#newTreeSet(Iterable)}, this method does not discard elements that are + *

Unlike {@link java.util.Sets#newTreeSet(Iterable)}, this method does not discard elements that are * duplicates according to the comparator. The sort performed is stable, meaning that such * elements will appear in the returned list in the same order they appeared in {@code elements}. * @@ -739,7 +736,7 @@ public abstract class Ordering implements Comparator { * equal to the element that preceded it, according to this ordering. Note that this is always * true when the iterable has fewer than two elements. * - *

Java 8 users: Use the equivalent {@link Comparators#isInOrder(Iterable, Comparator)} + *

Java 8 users: Use the equivalent {@link java.util.Comparators#isInOrder(Iterable, Comparator)} * instead, since the rest of {@code Ordering} is mostly obsolete (as explained in the class * documentation). */ @@ -763,7 +760,7 @@ public abstract class Ordering implements Comparator { * greater than the element that preceded it, according to this ordering. Note that this is always * true when the iterable has fewer than two elements. * - *

Java 8 users: Use the equivalent {@link Comparators#isInStrictOrder(Iterable, + *

Java 8 users: Use the equivalent {@link java.util.Comparators#isInStrictOrder(Iterable, * Comparator)} instead, since the rest of {@code Ordering} is mostly obsolete (as explained in * the class documentation). */ diff --git a/datastructures-tiny/src/main/java/org/xbib/datastructures/tiny/TinyMultiMap.java b/datastructures-tiny/src/main/java/org/xbib/datastructures/tiny/TinyMultiMap.java index b31dc2d..59ea831 100644 --- a/datastructures-tiny/src/main/java/org/xbib/datastructures/tiny/TinyMultiMap.java +++ b/datastructures-tiny/src/main/java/org/xbib/datastructures/tiny/TinyMultiMap.java @@ -30,4 +30,10 @@ public class TinyMultiMap extends AbstractMultiMap { protected Map> newMap() { return TinyMap.builder(); } + + @SuppressWarnings("unchecked") + @Override + public Map> asMap() { + return ((TinyMap.Builder>) map).build(); + } } diff --git a/datastructures-tiny/src/test/java/org/xbib/datastructures/tiny/TinyMultiMapTest.java b/datastructures-tiny/src/test/java/org/xbib/datastructures/tiny/TinyMultiMapTest.java index fe296c4..a41bda8 100644 --- a/datastructures-tiny/src/test/java/org/xbib/datastructures/tiny/TinyMultiMapTest.java +++ b/datastructures-tiny/src/test/java/org/xbib/datastructures/tiny/TinyMultiMapTest.java @@ -1,13 +1,16 @@ package org.xbib.datastructures.tiny; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import java.util.Collection; +import java.util.Map; import org.junit.jupiter.api.Test; import org.xbib.datastructures.common.MultiMap; public class TinyMultiMapTest { @Test - public void testMultiMap() { + public void testMultiMapPut() { MultiMap multiMap = new TinyMultiMap<>(); multiMap.put("a", "a"); multiMap.put("a", "b"); @@ -17,4 +20,18 @@ public class TinyMultiMapTest { multiMap.put("b", "f"); assertEquals("{a=[a, b, c], b=[d, e, f]}", multiMap.asMap().toString()); } + + @Test + public void testMultiMapValuesAreCollections() { + MultiMap multiMap = new TinyMultiMap<>(); + multiMap.put("a", "a"); + multiMap.put("a", "b"); + multiMap.put("a", "c"); + multiMap.put("b", "d"); + multiMap.put("b", "e"); + multiMap.put("b", "f"); + Map> map = multiMap.asMap(); + assertInstanceOf(Collection.class, map.get("a")); + assertInstanceOf(Collection.class, map.get("b")); + } } diff --git a/gradle.properties b/gradle.properties index db35e29..19ae290 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ group = org.xbib name = datastructures -version = 5.0.6 +version = 5.0.7 diff --git a/settings.gradle b/settings.gradle index 2b0edcb..800537f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -15,7 +15,6 @@ pluginManagement { dependencyResolutionManagement { versionCatalogs { libs { - version('gradle', '8.4') version('gradle', '8.5') library('chronicle-core', 'net.openhft', 'chronicle-core').version('2.21ea14') library('affinity', 'net.openhft', 'affinity').version('3.21ea0') @@ -23,7 +22,7 @@ dependencyResolutionManagement { library('orgjson', 'org.json', 'json').version('20210307') } testLibs { - version('junit', '5.10.0') + version('junit', '5.10.2') version('jackson', '2.15.2') library('junit-jupiter-api', 'org.junit.jupiter', 'junit-jupiter-api').versionRef('junit') library('junit-jupiter-params', 'org.junit.jupiter', 'junit-jupiter-params').versionRef('junit') @@ -64,7 +63,7 @@ include 'datastructures-json-minimal' include 'datastructures-json-noggit' include 'datastructures-json-simple' include 'datastructures-json-tiny' -include 'datastructures-multi' +//include 'datastructures-multi' include 'datastructures-queue-tape' include 'datastructures-raml' include 'datastructures-tiny'