move StringCompressor initialization to StringCompressor
This commit is contained in:
@@ -8,8 +8,13 @@ import java.util.function.Function;
|
||||
*/
|
||||
public class StringCompressor {
|
||||
|
||||
public static final String ALL_DOCS_KEY = "\ue001allDocs"; // \ue001 is the second character in the private use
|
||||
// area
|
||||
|
||||
private static final String DEFAULT_GROUP = "<none>";
|
||||
|
||||
public static Tag TAG_ALL_DOCS;
|
||||
|
||||
private final UniqueStringIntegerPairs usip;
|
||||
|
||||
public StringCompressor(final UniqueStringIntegerPairs usip) throws RuntimeIOException {
|
||||
@@ -18,7 +23,13 @@ public class StringCompressor {
|
||||
|
||||
public static StringCompressor create(final Path path) {
|
||||
final UniqueStringIntegerPairs mapsi = new UniqueStringIntegerPairs(path);
|
||||
return new StringCompressor(mapsi);
|
||||
final StringCompressor result = new StringCompressor(mapsi);
|
||||
|
||||
result.put(ALL_DOCS_KEY);
|
||||
result.put("");
|
||||
TAG_ALL_DOCS = result.createTag(ALL_DOCS_KEY, "");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public int put(final String string) {
|
||||
@@ -53,8 +64,8 @@ public class StringCompressor {
|
||||
* @param value the value
|
||||
*/
|
||||
public Tag createTag(final String field, final String value) {
|
||||
final int f = field != null ? Tags.STRING_COMPRESSOR.getIfPresent(field) : -1;
|
||||
final int v = value != null ? Tags.STRING_COMPRESSOR.getIfPresent(value) : -1;
|
||||
final int f = field != null ? getIfPresent(field) : -1;
|
||||
final int v = value != null ? getIfPresent(value) : -1;
|
||||
return new Tag(f, v);
|
||||
}
|
||||
|
||||
@@ -126,12 +137,13 @@ public class StringCompressor {
|
||||
if (tags.isEmpty()) {
|
||||
result.append(DEFAULT_GROUP);
|
||||
} else {
|
||||
tags.forEach((k, v) -> {
|
||||
for (final Tag tag : tags.toTags()) {
|
||||
final String value = get(tag.getValue());
|
||||
if (result.length() > 0) {
|
||||
result.append(" / ");
|
||||
}
|
||||
result.append(v);
|
||||
});
|
||||
result.append(value);
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public class Tag implements Comparable<Tag> {
|
||||
|
||||
/**
|
||||
* Create a new tag with field and value specified as int. See
|
||||
* {@link Tags#STRING_COMPRESSOR} for the mapping between Strings and ints.
|
||||
* {@link StringCompressor} for the mapping between Strings and ints.
|
||||
*
|
||||
* @param field the field as int
|
||||
* @param value the value as int
|
||||
|
||||
@@ -7,7 +7,6 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.lucares.collections.IntList;
|
||||
@@ -233,16 +232,4 @@ public class Tags implements Comparable<Tags> {
|
||||
public boolean isEmpty() {
|
||||
return tags.isEmpty();
|
||||
}
|
||||
|
||||
// TODO move
|
||||
// to StringCompressor
|
||||
|
||||
public void forEach(final BiConsumer<String, String> keyValueConsumer) {
|
||||
|
||||
for (final Tag tag : tags) {
|
||||
final String key = STRING_COMPRESSOR.get(tag.getKey());
|
||||
final String value = STRING_COMPRESSOR.get(tag.getValue());
|
||||
keyValueConsumer.accept(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user