rename put method to help IDEs find references

This commit is contained in:
2021-10-16 18:33:20 +02:00
parent 393de7ffec
commit d7cd4a94a5
2 changed files with 9 additions and 8 deletions

View File

@@ -165,7 +165,7 @@ public class UniqueStringIntegerPairs {
intToString.set(value, string); 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)) { if (stringToInt.containsKey(string) || (intToString.size() > integer && intToString.get(integer) != null)) {
throw new IllegalArgumentException("Unique key constraint violation for (" + string + ", " + integer + ")"); throw new IllegalArgumentException("Unique key constraint violation for (" + string + ", " + integer + ")");
@@ -197,7 +197,7 @@ public class UniqueStringIntegerPairs {
synchronized (stringToInt) { synchronized (stringToInt) {
if (!stringToInt.containsKey(string)) { if (!stringToInt.containsKey(string)) {
final Integer second = mappingFunction.apply(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(); 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 bytesToInt.put(byteArray, integer); // also add the original String to bytesToInt, because it is
// used as cache // used as cache
} }

View File

@@ -5,9 +5,9 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import org.lucares.utils.file.FileUtils; import org.lucares.utils.file.FileUtils;
public class UniqueStringIntegerPairsTest { public class UniqueStringIntegerPairsTest {
@@ -33,7 +33,7 @@ public class UniqueStringIntegerPairsTest {
{ {
final UniqueStringIntegerPairs usip = new UniqueStringIntegerPairs(database); final UniqueStringIntegerPairs usip = new UniqueStringIntegerPairs(database);
usip.put(first, second); usip.putStringAndInteger(first, second);
Assertions.assertEquals(second, usip.get(first)); Assertions.assertEquals(second, usip.get(first));
Assertions.assertEquals(first, usip.getKey(second)); Assertions.assertEquals(first, usip.getKey(second));
} }
@@ -53,11 +53,11 @@ public class UniqueStringIntegerPairsTest {
final Integer second = 1; final Integer second = 1;
final UniqueStringIntegerPairs usip = new UniqueStringIntegerPairs(database); final UniqueStringIntegerPairs usip = new UniqueStringIntegerPairs(database);
usip.put(first, second); usip.putStringAndInteger(first, second);
try { try {
// cannot add another pair with the first key // cannot add another pair with the first key
final int another = second + 1; final int another = second + 1;
usip.put(first, another); usip.putStringAndInteger(first, another);
Assertions.fail("expected an IllegalArgumentException"); Assertions.fail("expected an IllegalArgumentException");
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
// expected // expected
@@ -66,7 +66,7 @@ public class UniqueStringIntegerPairsTest {
try { try {
// cannot add another pair with the same second value // cannot add another pair with the same second value
final String another = first + 1; final String another = first + 1;
usip.put(another, second); usip.putStringAndInteger(another, second);
Assertions.fail("expected an IllegalArgumentException"); Assertions.fail("expected an IllegalArgumentException");
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
// expected // expected