diff --git a/pdb-api/src/main/java/org/lucares/pdb/api/UniqueStringIntegerPairs.java b/pdb-api/src/main/java/org/lucares/pdb/api/UniqueStringIntegerPairs.java index 007a514..3cd73e1 100644 --- a/pdb-api/src/main/java/org/lucares/pdb/api/UniqueStringIntegerPairs.java +++ b/pdb-api/src/main/java/org/lucares/pdb/api/UniqueStringIntegerPairs.java @@ -165,7 +165,7 @@ public class UniqueStringIntegerPairs { intToString.set(value, string); } - void put(final String string, final int integer) { + void putStringAndInteger(final String string, final int integer) { if (stringToInt.containsKey(string) || (intToString.size() > integer && intToString.get(integer) != null)) { throw new IllegalArgumentException("Unique key constraint violation for (" + string + ", " + integer + ")"); @@ -197,7 +197,7 @@ public class UniqueStringIntegerPairs { synchronized (stringToInt) { if (!stringToInt.containsKey(string)) { final Integer second = mappingFunction.apply(string); - put(string, second); + putStringAndInteger(string, second); } } } @@ -231,7 +231,8 @@ public class UniqueStringIntegerPairs { } final Integer integer = intToString.size(); - put(normalizedString, integer); // adds the normalized String to stringToInt and bytesToInt + putStringAndInteger(normalizedString, integer); // adds the normalized String to stringToInt and + // bytesToInt bytesToInt.put(byteArray, integer); // also add the original String to bytesToInt, because it is // used as cache } diff --git a/pdb-api/src/test/java/org/lucares/pdb/api/UniqueStringIntegerPairsTest.java b/pdb-api/src/test/java/org/lucares/pdb/api/UniqueStringIntegerPairsTest.java index cd60616..1e8dd3d 100644 --- a/pdb-api/src/test/java/org/lucares/pdb/api/UniqueStringIntegerPairsTest.java +++ b/pdb-api/src/test/java/org/lucares/pdb/api/UniqueStringIntegerPairsTest.java @@ -5,9 +5,9 @@ import java.nio.file.Files; import java.nio.file.Path; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.Assertions; import org.lucares.utils.file.FileUtils; public class UniqueStringIntegerPairsTest { @@ -33,7 +33,7 @@ public class UniqueStringIntegerPairsTest { { final UniqueStringIntegerPairs usip = new UniqueStringIntegerPairs(database); - usip.put(first, second); + usip.putStringAndInteger(first, second); Assertions.assertEquals(second, usip.get(first)); Assertions.assertEquals(first, usip.getKey(second)); } @@ -53,11 +53,11 @@ public class UniqueStringIntegerPairsTest { final Integer second = 1; final UniqueStringIntegerPairs usip = new UniqueStringIntegerPairs(database); - usip.put(first, second); + usip.putStringAndInteger(first, second); try { // cannot add another pair with the first key final int another = second + 1; - usip.put(first, another); + usip.putStringAndInteger(first, another); Assertions.fail("expected an IllegalArgumentException"); } catch (final IllegalArgumentException e) { // expected @@ -66,7 +66,7 @@ public class UniqueStringIntegerPairsTest { try { // cannot add another pair with the same second value final String another = first + 1; - usip.put(another, second); + usip.putStringAndInteger(another, second); Assertions.fail("expected an IllegalArgumentException"); } catch (final IllegalArgumentException e) { // expected