PersistentMap now requires only a path instead of a DiskStorage

This makes the PersistentMap easier to use.
This commit is contained in:
2018-11-10 10:08:21 +01:00
parent e90506c1b0
commit 3ccf526608
2 changed files with 29 additions and 34 deletions

View File

@@ -3,6 +3,7 @@ package org.lucares.pdb.map;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@@ -16,7 +17,7 @@ import org.lucares.utils.Preconditions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class PersistentMap<K, V> {
public class PersistentMap<K, V> implements AutoCloseable{
private static final Logger LOGGER = LoggerFactory.getLogger(PersistentMap.class);
@@ -81,13 +82,18 @@ public class PersistentMap<K, V> {
private final EncoderDecoder<V> valueEncoder;
public PersistentMap(final DiskStorage diskStore, final EncoderDecoder<K> keyEncoder,
public PersistentMap(final Path path, final EncoderDecoder<K> keyEncoder,
final EncoderDecoder<V> valueEncoder) throws IOException {
this.diskStore = diskStore;
this.diskStore = new DiskStorage(path);
this.keyEncoder = keyEncoder;
this.valueEncoder = valueEncoder;
initIfNew();
}
@Override
public void close() throws IOException {
diskStore.close();
}
public void setMaxEntriesInNode(final int maxEntriesInNode) {
this.maxEntriesInNode = maxEntriesInNode;