From 91437c20f7bff1436c4d4374869a4a524f5a2cb6 Mon Sep 17 00:00:00 2001 From: Oryan Date: Fri, 23 Oct 2026 15:32:59 -0400 Subject: [PATCH] Remove BiMap and SchemaParserDictionary.getDictionary --- .../kickstart/tools/SchemaParserDictionary.kt | 10 -- .../graphql/kickstart/tools/util/BiMap.java | 145 ------------------ .../tools/SchemaParserDictionaryTest.kt | 14 -- .../graphql/kickstart/tools/util/BiMapTest.kt | 87 ----------- 4 files changed, 256 deletions(-) delete mode 100644 src/main/kotlin/graphql/kickstart/tools/util/BiMap.java delete mode 100644 src/test/kotlin/graphql/kickstart/tools/util/BiMapTest.kt diff --git a/src/main/kotlin/graphql/kickstart/tools/SchemaParserDictionary.kt b/src/main/kotlin/graphql/kickstart/tools/SchemaParserDictionary.kt index 1012dc0e..75e98e2f 100644 --- a/src/main/kotlin/graphql/kickstart/tools/SchemaParserDictionary.kt +++ b/src/main/kotlin/graphql/kickstart/tools/SchemaParserDictionary.kt @@ -11,16 +11,6 @@ class SchemaParserDictionary { */ fun toMap(): Map> = dictionary.toMap() - // TODO remove in 15.0.0 (#900) - /** - * Returns a copy of the entries added so far. If several types share a class, the inverse of the copy only maps that class - * back to the first of them. - */ - @Deprecated("Use toMap() instead", ReplaceWith("toMap()")) - @Suppress("DEPRECATION") - fun getDictionary(): graphql.kickstart.tools.util.BiMap> = - graphql.kickstart.tools.util.BiMap.unmodifiableCopyOf(dictionary) - /** * Add arbitrary classes to the parser's dictionary, overriding the generated type name. */ diff --git a/src/main/kotlin/graphql/kickstart/tools/util/BiMap.java b/src/main/kotlin/graphql/kickstart/tools/util/BiMap.java deleted file mode 100644 index 70343ba7..00000000 --- a/src/main/kotlin/graphql/kickstart/tools/util/BiMap.java +++ /dev/null @@ -1,145 +0,0 @@ -package graphql.kickstart.tools.util; - -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Set; - -import static java.util.Collections.unmodifiableMap; - -// TODO remove in 15.0.0 (#900) -/** - * @deprecated Use a plain {@link java.util.Map}. - */ -@Deprecated -@SuppressWarnings("SuspiciousMethodCalls") -public class BiMap implements Map { - - private final Map delegate; - private final Map inverse; - - public static BiMap create() { - return new BiMap<>(new HashMap<>(), new HashMap<>()); - } - - public static BiMap unmodifiableBiMap(BiMap biMap) { - return new BiMap<>(unmodifiableMap(biMap.delegate), unmodifiableMap(biMap.inverse)); - } - - /** - * Returns an unmodifiable bimap with the entries of the given map. Unlike {@link #put(Object, Object)}, several keys may - * have the same value. The inverse only maps such a value back to the first of its keys, so the inverse and - * {@link #values()} can have fewer entries than the bimap. - */ - public static BiMap unmodifiableCopyOf(Map map) { - Map inverse = new HashMap<>(); - map.forEach((key, value) -> inverse.putIfAbsent(value, key)); - return new BiMap<>(unmodifiableMap(new LinkedHashMap<>(map)), unmodifiableMap(inverse)); - } - - private BiMap(Map delegate, Map inverse) { - this.delegate = delegate; - this.inverse = inverse; - } - - public BiMap inverse() { - return new BiMap<>(inverse, delegate); - } - - @Override - public void clear() { - delegate.clear(); - inverse.clear(); - } - - @Override - public boolean containsKey(Object key) { - return delegate.containsKey(key); - } - - @Override - public boolean containsValue(Object value) { - return inverse.containsKey(value); - } - - @Override - public Set> entrySet() { - return delegate.entrySet(); - } - - @Override - public V get(Object key) { - return delegate.get(key); - } - - @Override - public boolean isEmpty() { - return delegate.isEmpty(); - } - - @Override - public Set keySet() { - return delegate.keySet(); - } - - /** - * {@inheritDoc} - * - * @throws IllegalArgumentException if the given value is already bound to a different key in this bimap. - */ - @Override - public V put(K key, V value) { - // if the key already exists, and the value is the same as the old, then nothing to do - boolean containedKey = containsKey(key); - if (containedKey && Objects.equals(value, get(key))) { - return value; - } - - // if the value already exists, then it's not ok - if (containsValue(value)) { - throw new IllegalArgumentException("value already present: " + value); - } - - // put the value; if the key already exists, it replaces an existing value, and we have to remove it from the inverse as well - V oldValue = delegate.put(key, value); - if (containedKey) { - inverse.remove(oldValue); - } - inverse.put(value, key); - - return oldValue; - } - - /** - * {@inheritDoc} - * - * @throws IllegalArgumentException if an attempt to {@code put} any entry fails. - */ - @Override - public void putAll(Map m) { - for (Entry entry : m.entrySet()) { - put(entry.getKey(), entry.getValue()); - } - } - - @Override - public V remove(Object key) { - if (!containsKey(key)) { - return null; - } - - inverse.remove(delegate.get(key)); - return delegate.remove(key); - } - - @Override - public int size() { - return delegate.size(); - } - - @Override - public Set values() { - return inverse.keySet(); - } -} diff --git a/src/test/kotlin/graphql/kickstart/tools/SchemaParserDictionaryTest.kt b/src/test/kotlin/graphql/kickstart/tools/SchemaParserDictionaryTest.kt index 69e66021..8660bca4 100644 --- a/src/test/kotlin/graphql/kickstart/tools/SchemaParserDictionaryTest.kt +++ b/src/test/kotlin/graphql/kickstart/tools/SchemaParserDictionaryTest.kt @@ -110,20 +110,6 @@ class SchemaParserDictionaryTest { assertEquals(dictionary.toMap().entries.map { it.key to it.value }, listOf("B" to Map::class.java, "A" to String::class.java, "C" to Map::class.java)) } - @Test - @Suppress("DEPRECATION") - fun `getDictionary keeps working and only maps a shared class back to its first name`() { - val dictionary = SchemaParserDictionary() - .add("B", Map::class) - .add("A", String::class) - .add("C", Map::class) - - val deprecated = dictionary.getDictionary() - - assertEquals(deprecated.toMap(), dictionary.toMap()) - assertEquals(deprecated.inverse().toMap(), mapOf, String>(Map::class.java to "B", String::class.java to "A")) - } - @Test fun `input type and object type can share a dictionary class`() { val schema = SchemaParser.newParser() diff --git a/src/test/kotlin/graphql/kickstart/tools/util/BiMapTest.kt b/src/test/kotlin/graphql/kickstart/tools/util/BiMapTest.kt deleted file mode 100644 index 8cbd3fe4..00000000 --- a/src/test/kotlin/graphql/kickstart/tools/util/BiMapTest.kt +++ /dev/null @@ -1,87 +0,0 @@ -@file:Suppress("DEPRECATION") - -package graphql.kickstart.tools.util - -import graphql.kickstart.tools.assertEquals -import org.junit.Assert.assertTrue -import org.junit.Before -import org.junit.Test -import java.util.* - -class BiMapTest { - - lateinit var bimap: BiMap - - @Before - fun setup() { - bimap = BiMap.create() - } - - @Test(expected = IllegalArgumentException::class) - fun `should not permit duplicate values`() { - bimap["foo"] = 1 - bimap["bar"] = 1 - } - - @Test - fun `should allow same key same value`() { - bimap["foo"] = 1 - - // should not fail - bimap["foo"] = 1 - } - - @Test - fun `should allow same key new value`() { - bimap["foo"] = 1 - bimap["bar"] = 2 - val old = bimap.put("bar", 3)!! - - // old value should have been returned - assertEquals(2, old.toLong()) - - // inverse should have correct keys - val expected: Set = HashSet(Arrays.asList(1, 3)) - assertEquals(expected, bimap.values) - assertEquals(expected, bimap.inverse().keys) - } - - @Test - fun `should provide inverse view`() { - bimap["foo"] = 1 - bimap["bar"] = 2 - bimap["baz"] = 3 - val inverse = bimap.inverse() - assertTrue(inverse.containsKey(1)) - assertTrue(inverse.containsKey(2)) - assertTrue(inverse.containsKey(3)) - assertEquals(inverse[1], "foo") - assertEquals(inverse[2], "bar") - assertEquals(inverse[3], "baz") - } - - @Test - fun `should return correct values`() { - bimap["foo"] = 1 - bimap["bar"] = 2 - bimap["baz"] = 3 - val values = bimap.values - val expected = setOf(1, 2, 3) - assertEquals(expected, values) - } - - @Test - fun `unmodifiable copy should keep keys with the same value`() { - val copy = BiMap.unmodifiableCopyOf(linkedMapOf("foo" to 1, "bar" to 2, "baz" to 1)) - - assertEquals(mapOf("foo" to 1, "bar" to 2, "baz" to 1), copy.toMap()) - assertEquals(listOf("foo", "bar", "baz"), copy.keys.toList()) - assertEquals(setOf(1, 2), copy.values) - assertEquals(mapOf(1 to "foo", 2 to "bar"), copy.inverse().toMap()) - } - - @Test(expected = UnsupportedOperationException::class) - fun `unmodifiable copy should not permit changes`() { - BiMap.unmodifiableCopyOf(mapOf("foo" to 1))["bar"] = 2 - } -}