introduced a new custom file format used for backup and ingestion
The new file format reduces repetition, is easy to parse, easy to generate in any language and is human readable.
This commit is contained in:
@@ -7,6 +7,7 @@ import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.lucares.collections.IntList;
|
||||
import org.lucares.collections.LongList;
|
||||
@@ -198,6 +199,28 @@ public class Tags implements Comparable<Tags> {
|
||||
return String.valueOf(tags);
|
||||
}
|
||||
|
||||
public String toCsv() {
|
||||
final List<String> tagsAsStrings = new ArrayList<>();
|
||||
for (final Tag tag : tags) {
|
||||
tagsAsStrings.add(tag.getKeyAsString() + "=" + tag.getValueAsString());
|
||||
}
|
||||
|
||||
return String.join(",", tagsAsStrings);
|
||||
}
|
||||
|
||||
public static Tags fromCsv(final String line) {
|
||||
|
||||
final TagsBuilder tagsBuilder = new TagsBuilder();
|
||||
final String[] tagsAsString = line.split(Pattern.quote(","));
|
||||
|
||||
for (final String tagAsString : tagsAsString) {
|
||||
final String[] keyValue = tagAsString.split(Pattern.quote("="));
|
||||
tagsBuilder.add(keyValue[0], keyValue[1]);
|
||||
}
|
||||
|
||||
return tagsBuilder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
|
||||
Reference in New Issue
Block a user