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

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

commit cecde9386700def2b266d6f11038a0935a50f82f
Author: Bertil Chapuis <[email protected]>
AuthorDate: Sat Apr 5 12:38:25 2025 +0200

    Use the builder pattern for the IndexedDataMap
---
 .../baremaps/tasks/ImportUpdateSampleTest.java       | 20 ++++++++++++--------
 .../baremaps/data/collection/IndexedDataMap.java     | 17 ++++-------------
 .../java/org/apache/baremaps/data/DataMapTest.java   |  7 ++++---
 .../baremaps/data/collection/IndexedDataMapTest.java |  8 +++++---
 4 files changed, 25 insertions(+), 27 deletions(-)

diff --git 
a/baremaps-core/src/test/java/org/apache/baremaps/tasks/ImportUpdateSampleTest.java
 
b/baremaps-core/src/test/java/org/apache/baremaps/tasks/ImportUpdateSampleTest.java
index f75e52376..1926f4059 100644
--- 
a/baremaps-core/src/test/java/org/apache/baremaps/tasks/ImportUpdateSampleTest.java
+++ 
b/baremaps-core/src/test/java/org/apache/baremaps/tasks/ImportUpdateSampleTest.java
@@ -55,15 +55,19 @@ class ImportUpdateSampleTest extends PostgresRepositoryTest 
{
 
     // Initialize the data maps
     Map<Long, Coordinate> coordinateMap = DataConversions.asMap(
-        new IndexedDataMap<>(AppendOnlyLog.<Coordinate>builder()
-            .dataType(new CoordinateDataType())
-            .memory(new OnHeapMemory())
-            .build()));
+        IndexedDataMap.<Coordinate>builder()
+            .values(AppendOnlyLog.<Coordinate>builder()
+                .dataType(new CoordinateDataType())
+                .memory(new OnHeapMemory())
+                .build())
+            .build());
     Map<Long, List<Long>> referenceMap = DataConversions.asMap(
-        new IndexedDataMap<>(AppendOnlyLog.<List<Long>>builder()
-            .dataType(new LongListDataType())
-            .memory(new OnHeapMemory())
-            .build()));
+        IndexedDataMap.<List<Long>>builder()
+            .values(AppendOnlyLog.<List<Long>>builder()
+                .dataType(new LongListDataType())
+                .memory(new OnHeapMemory())
+                .build())
+            .build());
 
     // Import the sample data
     ImportOsmPbf.execute(TestFiles.SAMPLE_OSM_PBF, coordinateMap, 
referenceMap, headerRepository,
diff --git 
a/baremaps-data/src/main/java/org/apache/baremaps/data/collection/IndexedDataMap.java
 
b/baremaps-data/src/main/java/org/apache/baremaps/data/collection/IndexedDataMap.java
index 5e2fad6a0..25bd3d33c 100644
--- 
a/baremaps-data/src/main/java/org/apache/baremaps/data/collection/IndexedDataMap.java
+++ 
b/baremaps-data/src/main/java/org/apache/baremaps/data/collection/IndexedDataMap.java
@@ -90,20 +90,11 @@ public class IndexedDataMap<E> implements DataMap<Long, E> {
       }
 
       if (index == null) {
-        return new IndexedDataMap<>(values);
-      } else {
-        return new IndexedDataMap<>(index, values);
+        index = new HashMap<>();
       }
-    }
-  }
 
-  /**
-   * Constructs a {@link IndexedDataMap}.
-   *
-   * @param values the values
-   */
-  public IndexedDataMap(AppendOnlyLog<E> values) {
-    this(new HashMap<>(), values);
+      return new IndexedDataMap<>(index, values);
+    }
   }
 
   /**
@@ -112,7 +103,7 @@ public class IndexedDataMap<E> implements DataMap<Long, E> {
    * @param index the index
    * @param values the values
    */
-  public IndexedDataMap(Map<Long, Long> index, AppendOnlyLog<E> values) {
+  private IndexedDataMap(Map<Long, Long> index, AppendOnlyLog<E> values) {
     this.index = index;
     this.values = values;
   }
diff --git 
a/baremaps-data/src/test/java/org/apache/baremaps/data/DataMapTest.java 
b/baremaps-data/src/test/java/org/apache/baremaps/data/DataMapTest.java
index ea05e9902..9529af8e7 100644
--- a/baremaps-data/src/test/java/org/apache/baremaps/data/DataMapTest.java
+++ b/baremaps-data/src/test/java/org/apache/baremaps/data/DataMapTest.java
@@ -165,11 +165,12 @@ class DataMapTest {
     return Stream
         .of(
             Arguments.of(
-                new IndexedDataMap<>(
-                    AppendOnlyLog.<Long>builder()
+                IndexedDataMap.<Long>builder()
+                    .values(AppendOnlyLog.<Long>builder()
                         .dataType(new LongDataType())
                         .memory(new OffHeapMemory())
-                        .build())),
+                        .build())
+                    .build()),
             Arguments.of(new MonotonicFixedSizeDataMap<>(
                 new MemoryAlignedDataList<>(new LongDataType(), new 
OffHeapMemory()))),
             Arguments.of(new MonotonicDataMap<>(
diff --git 
a/baremaps-data/src/test/java/org/apache/baremaps/data/collection/IndexedDataMapTest.java
 
b/baremaps-data/src/test/java/org/apache/baremaps/data/collection/IndexedDataMapTest.java
index 09d56905f..666172923 100644
--- 
a/baremaps-data/src/test/java/org/apache/baremaps/data/collection/IndexedDataMapTest.java
+++ 
b/baremaps-data/src/test/java/org/apache/baremaps/data/collection/IndexedDataMapTest.java
@@ -37,9 +37,11 @@ class IndexedDataMapTest {
 
   @BeforeEach
   void setUp() {
-    map = new IndexedDataMap<>(AppendOnlyLog.<Integer>builder()
-        .dataType(new IntegerDataType())
-        .build());
+    map = IndexedDataMap.<Integer>builder()
+        .values(AppendOnlyLog.<Integer>builder()
+            .dataType(new IntegerDataType())
+            .build())
+        .build();
   }
 
   @AfterEach

Reply via email to