This is an automated email from the ASF dual-hosted git repository.

bchapuis pushed a commit to branch sonar
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git

commit 8ea75940042101887118c82a3bfa8b00cb23d80a
Author: Bertil Chapuis <[email protected]>
AuthorDate: Tue Jun 11 23:19:06 2024 +0200

    Fix some of the issues reported by sonar
---
 .../org/apache/baremaps/cli/BaremapsException.java |  39 ++++++
 .../main/java/org/apache/baremaps/cli/map/Dev.java |   6 +-
 .../org/apache/baremaps/database/DiffService.java  |   7 +-
 .../apache/baremaps/database/copy/CopyWriter.java  | 143 +++++++++------------
 4 files changed, 108 insertions(+), 87 deletions(-)

diff --git 
a/baremaps-cli/src/main/java/org/apache/baremaps/cli/BaremapsException.java 
b/baremaps-cli/src/main/java/org/apache/baremaps/cli/BaremapsException.java
new file mode 100644
index 00000000..f76c3b70
--- /dev/null
+++ b/baremaps-cli/src/main/java/org/apache/baremaps/cli/BaremapsException.java
@@ -0,0 +1,39 @@
+package org.apache.baremaps.cli;
+
+import org.apache.baremaps.data.storage.DataStore;
+import org.apache.baremaps.data.storage.DataStoreException;
+
+/** Signals that an exception occurred in the {@link Baremaps} CLI. */
+public class BaremapsException extends RuntimeException {
+
+    /** Constructs a {@link BaremapsException} with {@code null} as its error 
detail message. */
+    public BaremapsException() {}
+
+    /**
+     * Constructs an {@link BaremapsException} with the specified detail 
message.
+     *
+     * @param message the message
+     */
+    public BaremapsException(String message) {
+        super(message);
+    }
+
+    /**
+     * Constructs a {@link BaremapsException} with the specified cause.
+     *
+     * @param cause the cause
+     */
+    public BaremapsException(Throwable cause) {
+        super(cause);
+    }
+
+    /**
+     * Constructs a {@link BaremapsException} with the specified detail 
message and cause.
+     *
+     * @param message the message
+     * @param cause the cause
+     */
+    public BaremapsException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}
diff --git a/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Dev.java 
b/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Dev.java
index b3794699..af84ec42 100644
--- a/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Dev.java
+++ b/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Dev.java
@@ -30,6 +30,8 @@ import java.io.IOException;
 import java.nio.file.Path;
 import java.util.concurrent.Callable;
 import java.util.function.Supplier;
+
+import org.apache.baremaps.cli.BaremapsException;
 import org.apache.baremaps.cli.Options;
 import org.apache.baremaps.config.ConfigReader;
 import org.apache.baremaps.maplibre.style.Style;
@@ -88,7 +90,7 @@ public class Dev implements Callable<Integer> {
         var config = configReader.read(tilesetPath);
         return objectMapper.readValue(config, Tileset.class);
       } catch (IOException e) {
-        throw new RuntimeException(e);
+        throw new BaremapsException(e);
       }
     };
 
@@ -102,7 +104,7 @@ public class Dev implements Callable<Integer> {
         var config = configReader.read(stylePath);
         return objectMapper.readValue(config, Style.class);
       } catch (IOException e) {
-        throw new RuntimeException(e);
+        throw new BaremapsException(e);
       }
     };
 
diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/database/DiffService.java 
b/baremaps-core/src/main/java/org/apache/baremaps/database/DiffService.java
index 49c51d4f..07a7b890 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/database/DiffService.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/database/DiffService.java
@@ -58,8 +58,11 @@ public class DiffService implements 
Callable<List<TileCoord>> {
   public DiffService(
       Map<Long, Coordinate> coordinateMap,
       Map<Long, List<Long>> referenceMap,
-      HeaderRepository headerRepository, Repository<Long, Node> nodeRepository,
-      Repository<Long, Way> wayRepository, Repository<Long, Relation> 
relationRepository, int srid,
+      HeaderRepository headerRepository,
+      Repository<Long, Node> nodeRepository,
+      Repository<Long, Way> wayRepository,
+      Repository<Long, Relation> relationRepository,
+      int srid,
       int zoom) {
     this.coordinateMap = coordinateMap;
     this.referenceMap = referenceMap;
diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/database/copy/CopyWriter.java 
b/baremaps-core/src/main/java/org/apache/baremaps/database/copy/CopyWriter.java
index c71b752f..134706d2 100644
--- 
a/baremaps-core/src/main/java/org/apache/baremaps/database/copy/CopyWriter.java
+++ 
b/baremaps-core/src/main/java/org/apache/baremaps/database/copy/CopyWriter.java
@@ -144,12 +144,13 @@ public class CopyWriter implements AutoCloseable {
   }
 
   /**
-   * Writes a null value.
+   * Writes the number of columns affected by the query.
    *
+   * @param columns
    * @throws IOException
    */
-  public void writeNull() throws IOException {
-    data.writeInt(-1);
+  public void startRow(int columns) throws IOException {
+    data.writeShort(columns);
   }
 
   /**
@@ -157,261 +158,237 @@ public class CopyWriter implements AutoCloseable {
    *
    * @throws IOException
    */
-  public <T> void write(BaseValueHandler<T> handler, T value) throws 
IOException {
-    handler.handle(data, value);
+  public void writeNull() throws IOException {
+    data.writeInt(-1);
   }
 
   /**
-   * Writes the number of columns affected by the query.
+   * Writes a null value.
    *
-   * @param columns
-   * @throws IOException
+   * @param handler the value handler
+   * @param value the value
    */
-  public void startRow(int columns) throws IOException {
-    data.writeShort(columns);
+  public <T> void write(BaseValueHandler<T> handler, T value) {
+    handler.handle(data, value);
   }
 
   /**
    * Writes a string value.
    *
-   * @param value
-   * @throws IOException
+   * @param value the value
    */
-  public void write(String value) throws IOException {
+  public void write(String value) {
     STRING_HANDLER.handle(data, value);
   }
 
   /**
    * Writes a list of string values.
    *
-   * @param value
-   * @throws IOException
+   * @param value the value
    */
-  public void write(List<String> value) throws IOException {
+  public void write(List<String> value) {
     STRING_COLLECTION_HANDLER.handle(data, value);
   }
 
   /**
    * Writes a boolean value.
    *
-   * @param value
-   * @throws IOException
+   * @param value the value
    */
-  public void writeBoolean(Boolean value) throws IOException {
+  public void writeBoolean(Boolean value) {
     BOOLEAN_HANDLER.handle(data, value);
   }
 
   /**
    * Writes a list of boolean values.
    *
-   * @param value
-   * @throws IOException
+   * @param value the value
    */
-  public void writeBooleanList(List<Boolean> value) throws IOException {
+  public void writeBooleanList(List<Boolean> value) {
     BOOLEAN_COLLECTION_HANDLER.handle(data, value);
   }
 
   /**
    * Writes a byte value.
    *
-   * @param value
-   * @throws IOException
+   * @param value the value
    */
-  public void writeByte(Byte value) throws IOException {
+  public void writeByte(Byte value) {
     BYTE_HANDLER.handle(data, value);
   }
 
   /**
    * Writes a byte array value.
    *
-   * @param value
-   * @throws IOException
+   * @param value the value
    */
-  public void writeByteArray(byte[] value) throws IOException {
+  public void writeByteArray(byte[] value) {
     BYTE_ARRAY_HANDLER.handle(data, value);
   }
 
   /**
    * Writes a short value.
    *
-   * @param value
-   * @throws IOException
+   * @param value the value
    */
-  public void writeShort(Short value) throws IOException {
+  public void writeShort(Short value) {
     SHORT_HANDLER.handle(data, value);
   }
 
   /**
    * Writes a list of short values.
    *
-   * @param value
-   * @throws IOException
+   * @param value the value
    */
-  public void writeShortList(List<Short> value) throws IOException {
+  public void writeShortList(List<Short> value) {
     SHORT_COLLECTION_HANDLER.handle(data, value);
   }
 
   /**
    * Writes an integer value.
    *
-   * @param value
-   * @throws IOException
+   * @param value the value
    */
-  public void writeInteger(Integer value) throws IOException {
+  public void writeInteger(Integer value) {
     INTEGER_HANDLER.handle(data, value);
   }
 
   /**
    * Writes a list of integer values.
    *
-   * @param value
-   * @throws IOException
+   * @param value the value
    */
-  public void writeIntegerList(List<Integer> value) throws IOException {
+  public void writeIntegerList(List<Integer> value) {
     INTEGER_COLLECTION_HANDLER.handle(data, value);
   }
 
   /**
    * Writes a long value.
    *
-   * @param value
-   * @throws IOException
+   * @param value the value
    */
-  public void writeLong(Long value) throws IOException {
+  public void writeLong(Long value) {
     LONG_HANDLER.handle(data, value);
   }
 
   /**
    * Writes a list of long values.
    *
-   * @param value
-   * @throws IOException
+   * @param value the value
    */
-  public void writeLongList(List<Long> value) throws IOException {
+  public void writeLongList(List<Long> value) {
     LONG_COLLECTION_HANDLER.handle(data, value);
   }
 
   /**
    * Writes a float value.
    *
-   * @param value
-   * @throws IOException
+   * @param value the value
    */
-  public void writeFloat(Float value) throws IOException {
+  public void writeFloat(Float value) {
     FLOAT_HANDLER.handle(data, value);
   }
 
   /**
    * Writes a list of float values.
    *
-   * @param value
-   * @throws IOException
+   * @param value the value
    */
-  public void writeFloatList(List<Float> value) throws IOException {
+  public void writeFloatList(List<Float> value) {
     FLOAT_COLLECTION_HANDLER.handle(data, value);
   }
 
   /**
    * Writes a double value.
    *
-   * @param value
-   * @throws IOException
+   * @param value the value
    */
-  public void writeDouble(Double value) throws IOException {
+  public void writeDouble(Double value) {
     DOUBLE_HANDLER.handle(data, value);
   }
 
   /**
    * Writes a list of double values.
    *
-   * @param value
-   * @throws IOException
+   * @param value the value
    */
-  public void writeDoubleArray(List<Double> value) throws IOException {
+  public void writeDoubleArray(List<Double> value) {
     DOUBLE_COLLECTION_HANDLER.handle(data, value);
   }
 
   /**
    * Writes a date value.
    *
-   * @param value
-   * @throws IOException
+   * @param value the value
    */
-  public void writeLocalDate(LocalDate value) throws IOException {
+  public void writeLocalDate(LocalDate value) {
     LOCAL_DATE_HANDLER.handle(data, value);
   }
 
   /**
    * Writes a list of date values.
    *
-   * @param value
-   * @throws IOException
+   * @param value the value
    */
-  public void writeLocalDateTime(LocalDateTime value) throws IOException {
+  public void writeLocalDateTime(LocalDateTime value) {
     LOCAL_DATE_TIME_HANDLER.handle(data, value);
   }
 
   /**
    * Writes an inet adress value.
    *
-   * @param value
-   * @throws IOException
+   * @param value the value
    */
-  public void writeInet4Adress(Inet4Address value) throws IOException {
+  public void writeInet4Adress(Inet4Address value) {
     INET_4_ADDRESS_HANDLER.handle(data, value);
   }
 
   /**
    * Writes a list of inet adress values.
    *
-   * @param value
-   * @throws IOException
+   * @param value the value
    */
-  public void writeInet6Adress(Inet6Address value) throws IOException {
+  public void writeInet6Adress(Inet6Address value) {
     INET_6_ADDRESS_HANDLER.handle(data, value);
   }
 
   /**
    * Writes a map value.
    *
-   * @param value
-   * @throws IOException
+   * @param value the value
    */
-  public void writeHstore(Map<String, String> value) throws IOException {
+  public void writeHstore(Map<String, String> value) {
     HSTORE_HANDLER.handle(data, value);
   }
 
   /**
    * Writes a jsonb array
    *
-   * @param value
-   * @throws IOException
+   * @param value the value
    */
-  public void writeJsonb(String value) throws IOException {
+  public void writeJsonb(String value) {
     JSONB_HANDLER.handle(data, value);
   }
 
   /**
    * Writes a geometry value.
    *
-   * @param value
-   * @throws IOException
+   * @param value the value
    */
-  public void writeGeometry(Geometry value) throws IOException {
+  public void writeGeometry(Geometry value) {
     GEOMETRY_HANDLER.handle(data, value);
   }
 
   /**
    * Writes an envelope value.
    *
-   * @param value
-   * @throws IOException
+   * @param value the value
    */
-  public void writeEnvelope(Envelope value) throws IOException {
+  public void writeEnvelope(Envelope value) {
     ENVELOPE_HANDLER.handle(data, value);
   }
 
-  /** Close the writer. */
+  /** @inheritDoc */
   @Override
   public void close() throws IOException {
     data.writeShort(-1);

Reply via email to