diff --git a/block-storage/src/main/java/org/lucares/pdb/map/PersistentMap.java b/block-storage/src/main/java/org/lucares/pdb/map/PersistentMap.java index f029036..b567964 100644 --- a/block-storage/src/main/java/org/lucares/pdb/map/PersistentMap.java +++ b/block-storage/src/main/java/org/lucares/pdb/map/PersistentMap.java @@ -7,10 +7,10 @@ import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.function.Function; import java.util.Objects; import java.util.Stack; import java.util.UUID; +import java.util.function.Function; import org.lucares.collections.LongList; import org.lucares.pdb.diskstorage.DiskBlock; @@ -40,12 +40,12 @@ public class PersistentMap implements AutoCloseable { public byte[] encode(O object); public O decode(byte[] bytes); - + public default Function asDecoder() { return bytes -> this.decode(bytes); } - - public default Function asEncoder() { + + public default Function asEncoder() { return plain -> this.encode(plain); } @@ -63,9 +63,10 @@ public class PersistentMap implements AutoCloseable { public String decode(final byte[] bytes) { return bytes == null ? null : new String(bytes, StandardCharsets.UTF_8); } - + + @Override public byte[] getEmptyValue() { - return new byte[] {0}; + return new byte[] { 0 }; } } @@ -80,9 +81,10 @@ public class PersistentMap implements AutoCloseable { public Long decode(final byte[] bytes) { return bytes == null ? null : VariableByteEncoder.decodeFirstValue(bytes); } - + + @Override public byte[] getEmptyValue() { - return new byte[] {0}; + return new byte[] { 0 }; } } @@ -104,9 +106,10 @@ public class PersistentMap implements AutoCloseable { return new UUID(mostSignificantBits, leastSignificantBits); } - + + @Override public byte[] getEmptyValue() { - return new byte[] {0}; + return new byte[] { 0 }; } } @@ -121,12 +124,12 @@ public class PersistentMap implements AutoCloseable { @Override public Empty decode(final byte[] bytes) { - - Preconditions.checkEqual(bytes.length, 0, ""); + Preconditions.checkTrue(bytes.length == 0, ""); return Empty.INSTANCE; } - + + @Override public byte[] getEmptyValue() { return new byte[] {}; } @@ -152,7 +155,8 @@ public class PersistentMap implements AutoCloseable { private final LRUCache valueCache = new LRUCache<>(1_000); - public PersistentMap(final Path path, final Path storageBasePath, final EncoderDecoder keyEncoder, final EncoderDecoder valueEncoder) { + public PersistentMap(final Path path, final Path storageBasePath, final EncoderDecoder keyEncoder, + final EncoderDecoder valueEncoder) { this.diskStore = new DiskStorage(path, storageBasePath); this.keyEncoder = keyEncoder; this.valueEncoder = valueEncoder; diff --git a/build.gradle b/build.gradle index c30a9db..08df106 100644 --- a/build.gradle +++ b/build.gradle @@ -26,7 +26,6 @@ ext { lib_commons_collections4 = 'org.apache.commons:commons-collections4:4.4' 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_log4j2_api = "org.apache.logging.log4j:log4j-api:${version_log4j2}" diff --git a/data-store/build.gradle b/data-store/build.gradle index 12afc00..aa3c471 100644 --- a/data-store/build.gradle +++ b/data-store/build.gradle @@ -9,7 +9,6 @@ dependencies { compile lib_primitive_collections compile lib_commons_lang3 - compile lib_guava compile lib_log4j2_core compile lib_log4j2_slf4j_impl diff --git a/pdb-plotting/build.gradle b/pdb-plotting/build.gradle index 8b3a3db..27bdf73 100644 --- a/pdb-plotting/build.gradle +++ b/pdb-plotting/build.gradle @@ -3,6 +3,5 @@ dependencies { compile project(':performanceDb') compile lib_primitive_collections compile lib_jackson_databind - compile lib_guava } diff --git a/pdb-plotting/src/main/java/org/lucares/pdb/plot/api/PlotSettings.java b/pdb-plotting/src/main/java/org/lucares/pdb/plot/api/PlotSettings.java index 646ed79..fc20dd0 100644 --- a/pdb-plotting/src/main/java/org/lucares/pdb/plot/api/PlotSettings.java +++ b/pdb-plotting/src/main/java/org/lucares/pdb/plot/api/PlotSettings.java @@ -8,8 +8,7 @@ import java.util.List; import java.util.regex.Pattern; import org.lucares.pdb.api.DateTimeRange; - -import com.google.common.base.Preconditions; +import org.lucares.utils.Preconditions; public class PlotSettings { @@ -120,7 +119,7 @@ public class PlotSettings { public DateTimeRange dateRange() { 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 endDate = LocalDateTime.parse(startEnd[1], DATE_FORMAT).atOffset(ZoneOffset.UTC); diff --git a/pdb-plotting/src/main/java/org/lucares/recommind/logs/Gnuplot.java b/pdb-plotting/src/main/java/org/lucares/recommind/logs/Gnuplot.java index 43c2040..331bf70 100644 --- a/pdb-plotting/src/main/java/org/lucares/recommind/logs/Gnuplot.java +++ b/pdb-plotting/src/main/java/org/lucares/recommind/logs/Gnuplot.java @@ -7,6 +7,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.lang.ProcessBuilder.Redirect; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.nio.file.Path; import java.util.Collection; import java.util.concurrent.ExecutorService; @@ -15,8 +16,6 @@ import java.util.concurrent.Executors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.io.Files; - public class Gnuplot { private static final Logger LOGGER = LoggerFactory.getLogger(Gnuplot.class); @@ -25,8 +24,9 @@ public class Gnuplot { private static final String ENV_GNUPLOT_HOME = "GNUPLOT_HOME"; private static final String PROPERTY_GNUPLOT_HOME = "gnuplot.home"; 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. private static final ExecutorService POOL = Executors.newCachedThreadPool(); @@ -43,15 +43,15 @@ public class Gnuplot { LOGGER.debug(gnuplotFileContent); 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(); try { final ProcessBuilder processBuilder = new ProcessBuilder(gnuplotBinary(), gnuplotFile.getAbsolutePath())// - .redirectOutput(Redirect.PIPE)// - .redirectError(Redirect.PIPE); - + .redirectOutput(Redirect.PIPE)// + .redirectError(Redirect.PIPE); + final Process process = processBuilder.start(); logOutput("stderr", process.getErrorStream()); logOutput("stdout", process.getInputStream()); @@ -69,18 +69,17 @@ public class Gnuplot { METRICS_LOGGER.debug("gnuplot: {}ms", (System.nanoTime() - start) / 1_000_000.0); } - private void logOutput(final String humanReadableType, final InputStream stream) throws IOException { - - POOL.submit(()->{ - try{ + private void logOutput(final String humanReadableType, final InputStream stream) throws IOException { + + POOL.submit(() -> { + try { final BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)); String line; - while(( line = reader.readLine()) != null){ + while ((line = reader.readLine()) != null) { LOGGER.info("gnuplot {}: {}", humanReadableType, line); } - } - catch (Exception e){ - LOGGER.warn("Exception while reading "+ humanReadableType+ " of gnuplot command", e); + } catch (final Exception e) { + LOGGER.warn("Exception while reading " + humanReadableType + " of gnuplot command", e); } }); }