remove dependency to Guava

This commit is contained in:
2019-09-01 15:44:36 +02:00
parent 8579974051
commit 0e9e2cd53a
6 changed files with 35 additions and 36 deletions

View File

@@ -7,10 +7,10 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.function.Function;
import java.util.Objects; import java.util.Objects;
import java.util.Stack; import java.util.Stack;
import java.util.UUID; import java.util.UUID;
import java.util.function.Function;
import org.lucares.collections.LongList; import org.lucares.collections.LongList;
import org.lucares.pdb.diskstorage.DiskBlock; import org.lucares.pdb.diskstorage.DiskBlock;
@@ -45,7 +45,7 @@ public class PersistentMap<K, V> implements AutoCloseable {
return bytes -> this.decode(bytes); return bytes -> this.decode(bytes);
} }
public default Function<O,byte[]> asEncoder() { public default Function<O, byte[]> asEncoder() {
return plain -> this.encode(plain); return plain -> this.encode(plain);
} }
@@ -64,8 +64,9 @@ public class PersistentMap<K, V> implements AutoCloseable {
return bytes == null ? null : new String(bytes, StandardCharsets.UTF_8); return bytes == null ? null : new String(bytes, StandardCharsets.UTF_8);
} }
@Override
public byte[] getEmptyValue() { public byte[] getEmptyValue() {
return new byte[] {0}; return new byte[] { 0 };
} }
} }
@@ -81,8 +82,9 @@ public class PersistentMap<K, V> implements AutoCloseable {
return bytes == null ? null : VariableByteEncoder.decodeFirstValue(bytes); return bytes == null ? null : VariableByteEncoder.decodeFirstValue(bytes);
} }
@Override
public byte[] getEmptyValue() { public byte[] getEmptyValue() {
return new byte[] {0}; return new byte[] { 0 };
} }
} }
@@ -105,8 +107,9 @@ public class PersistentMap<K, V> implements AutoCloseable {
return new UUID(mostSignificantBits, leastSignificantBits); return new UUID(mostSignificantBits, leastSignificantBits);
} }
@Override
public byte[] getEmptyValue() { public byte[] getEmptyValue() {
return new byte[] {0}; return new byte[] { 0 };
} }
} }
@@ -121,12 +124,12 @@ public class PersistentMap<K, V> implements AutoCloseable {
@Override @Override
public Empty decode(final byte[] bytes) { public Empty decode(final byte[] bytes) {
Preconditions.checkTrue(bytes.length == 0, "");
Preconditions.checkEqual(bytes.length, 0, "");
return Empty.INSTANCE; return Empty.INSTANCE;
} }
@Override
public byte[] getEmptyValue() { public byte[] getEmptyValue() {
return new byte[] {}; return new byte[] {};
} }
@@ -152,7 +155,8 @@ public class PersistentMap<K, V> implements AutoCloseable {
private final LRUCache<K, V> valueCache = new LRUCache<>(1_000); private final LRUCache<K, V> valueCache = new LRUCache<>(1_000);
public PersistentMap(final Path path, final Path storageBasePath, final EncoderDecoder<K> keyEncoder, final EncoderDecoder<V> valueEncoder) { public PersistentMap(final Path path, final Path storageBasePath, final EncoderDecoder<K> keyEncoder,
final EncoderDecoder<V> valueEncoder) {
this.diskStore = new DiskStorage(path, storageBasePath); this.diskStore = new DiskStorage(path, storageBasePath);
this.keyEncoder = keyEncoder; this.keyEncoder = keyEncoder;
this.valueEncoder = valueEncoder; this.valueEncoder = valueEncoder;

View File

@@ -26,7 +26,6 @@ ext {
lib_commons_collections4 = 'org.apache.commons:commons-collections4:4.4' lib_commons_collections4 = 'org.apache.commons:commons-collections4:4.4'
lib_commons_lang3 = 'org.apache.commons:commons-lang3:3.9' lib_commons_lang3 = 'org.apache.commons:commons-lang3:3.9'
lib_guava = 'com.google.guava:guava:28.0-jre'
lib_jackson_databind = 'com.fasterxml.jackson.core:jackson-databind:2.9.9.1' lib_jackson_databind = 'com.fasterxml.jackson.core:jackson-databind:2.9.9.1'
lib_log4j2_api = "org.apache.logging.log4j:log4j-api:${version_log4j2}" lib_log4j2_api = "org.apache.logging.log4j:log4j-api:${version_log4j2}"

View File

@@ -9,7 +9,6 @@ dependencies {
compile lib_primitive_collections compile lib_primitive_collections
compile lib_commons_lang3 compile lib_commons_lang3
compile lib_guava
compile lib_log4j2_core compile lib_log4j2_core
compile lib_log4j2_slf4j_impl compile lib_log4j2_slf4j_impl

View File

@@ -3,6 +3,5 @@ dependencies {
compile project(':performanceDb') compile project(':performanceDb')
compile lib_primitive_collections compile lib_primitive_collections
compile lib_jackson_databind compile lib_jackson_databind
compile lib_guava
} }

View File

@@ -8,8 +8,7 @@ import java.util.List;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.lucares.pdb.api.DateTimeRange; import org.lucares.pdb.api.DateTimeRange;
import org.lucares.utils.Preconditions;
import com.google.common.base.Preconditions;
public class PlotSettings { public class PlotSettings {
@@ -120,7 +119,7 @@ public class PlotSettings {
public DateTimeRange dateRange() { public DateTimeRange dateRange() {
final String[] startEnd = dateRangeAsString.split(Pattern.quote(" - ")); final String[] startEnd = dateRangeAsString.split(Pattern.quote(" - "));
Preconditions.checkArgument(startEnd.length == 2, "invalid date range"); Preconditions.checkEqual(startEnd, 2, "invalid date range: ''{0}''", dateRangeAsString);
final OffsetDateTime startDate = LocalDateTime.parse(startEnd[0], DATE_FORMAT).atOffset(ZoneOffset.UTC); final OffsetDateTime startDate = LocalDateTime.parse(startEnd[0], DATE_FORMAT).atOffset(ZoneOffset.UTC);
final OffsetDateTime endDate = LocalDateTime.parse(startEnd[1], DATE_FORMAT).atOffset(ZoneOffset.UTC); final OffsetDateTime endDate = LocalDateTime.parse(startEnd[1], DATE_FORMAT).atOffset(ZoneOffset.UTC);

View File

@@ -7,6 +7,7 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.lang.ProcessBuilder.Redirect; import java.lang.ProcessBuilder.Redirect;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Collection; import java.util.Collection;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
@@ -15,8 +16,6 @@ import java.util.concurrent.Executors;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.google.common.io.Files;
public class Gnuplot { public class Gnuplot {
private static final Logger LOGGER = LoggerFactory.getLogger(Gnuplot.class); private static final Logger LOGGER = LoggerFactory.getLogger(Gnuplot.class);
@@ -26,7 +25,8 @@ public class Gnuplot {
private static final String PROPERTY_GNUPLOT_HOME = "gnuplot.home"; private static final String PROPERTY_GNUPLOT_HOME = "gnuplot.home";
private final Path tmpDirectory; private final Path tmpDirectory;
// This would be bad style if this code was executed in a web-container, because it would cause a memory leak. // This would be bad style if this code was executed in a web-container, because
// it would cause a memory leak.
// But this code is only (and will only) be executed as standalone application. // But this code is only (and will only) be executed as standalone application.
private static final ExecutorService POOL = Executors.newCachedThreadPool(); private static final ExecutorService POOL = Executors.newCachedThreadPool();
@@ -43,14 +43,14 @@ public class Gnuplot {
LOGGER.debug(gnuplotFileContent); LOGGER.debug(gnuplotFileContent);
final File gnuplotFile = File.createTempFile("gnuplot", ".dem", tmpDirectory.toFile()); final File gnuplotFile = File.createTempFile("gnuplot", ".dem", tmpDirectory.toFile());
Files.asCharSink(gnuplotFile, StandardCharsets.UTF_8).write(gnuplotFileContent); Files.writeString(gnuplotFile.toPath(), gnuplotFileContent, StandardCharsets.UTF_8);
final long start = System.nanoTime(); final long start = System.nanoTime();
try { try {
final ProcessBuilder processBuilder = new ProcessBuilder(gnuplotBinary(), gnuplotFile.getAbsolutePath())// final ProcessBuilder processBuilder = new ProcessBuilder(gnuplotBinary(), gnuplotFile.getAbsolutePath())//
.redirectOutput(Redirect.PIPE)// .redirectOutput(Redirect.PIPE)//
.redirectError(Redirect.PIPE); .redirectError(Redirect.PIPE);
final Process process = processBuilder.start(); final Process process = processBuilder.start();
logOutput("stderr", process.getErrorStream()); logOutput("stderr", process.getErrorStream());
@@ -69,18 +69,17 @@ public class Gnuplot {
METRICS_LOGGER.debug("gnuplot: {}ms", (System.nanoTime() - start) / 1_000_000.0); METRICS_LOGGER.debug("gnuplot: {}ms", (System.nanoTime() - start) / 1_000_000.0);
} }
private void logOutput(final String humanReadableType, final InputStream stream) throws IOException { private void logOutput(final String humanReadableType, final InputStream stream) throws IOException {
POOL.submit(()->{ POOL.submit(() -> {
try{ try {
final BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)); final BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8));
String line; String line;
while(( line = reader.readLine()) != null){ while ((line = reader.readLine()) != null) {
LOGGER.info("gnuplot {}: {}", humanReadableType, line); LOGGER.info("gnuplot {}: {}", humanReadableType, line);
} }
} } catch (final Exception e) {
catch (Exception e){ LOGGER.warn("Exception while reading " + humanReadableType + " of gnuplot command", e);
LOGGER.warn("Exception while reading "+ humanReadableType+ " of gnuplot command", e);
} }
}); });
} }