remove unnecessary method

This commit is contained in:
2021-10-16 18:55:27 +02:00
parent 7d3ae61656
commit fe26068400
2 changed files with 14 additions and 28 deletions

View File

@@ -44,7 +44,7 @@ public class StringCompressor {
public int putString(final String value, final Function<String, String> postProcess) {
final String processedValue = postProcess.apply(value);
return usip.computeIfAbsentWithPostprocess(processedValue, postProcess);
return usip.computeIfAbsent(processedValue);
}
public String get(final int integer) {

View File

@@ -205,6 +205,17 @@ public class UniqueStringIntegerPairs {
return stringToInt.get(string);
}
public Integer computeIfAbsent(final String string) {
if (!stringToInt.containsKey(string)) {
synchronized (stringToInt) {
final Integer integer = intToString.size();
putStringAndInteger(string, integer);
}
}
return stringToInt.get(string);
}
public Integer computeIfAbsent(final byte[] bytes, final int start, final int endExclusive,
final Function<String, String> postProcess) {
@@ -212,34 +223,9 @@ public class UniqueStringIntegerPairs {
Integer result = bytesToInt.get(byteArray);
if (result == null) {
final String string = new String(bytes, start, endExclusive - start, StandardCharsets.UTF_8);
result = computeIfAbsentWithPostprocess(string, postProcess);
final String postProcessed = postProcess.apply(string);
result = computeIfAbsent(postProcessed);
}
return result;
}
public Integer computeIfAbsentWithPostprocess(final String string, final Function<String, String> postProcess) {
final ByteArray byteArray = new ByteArray(string);
Integer result = bytesToInt.get(byteArray);
if (result == null) {
synchronized (stringToInt) {
if (!bytesToInt.containsKey(byteArray)) {
final String normalizedString = postProcess.apply(string);
result = get(normalizedString);
if (result != null) {
return result;
}
final Integer integer = intToString.size();
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
}
result = bytesToInt.get(byteArray);
}
}
return result;
}
}