You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@baremaps.apache.org by bc...@apache.org on 2025/04/05 12:36:32 UTC
(incubator-baremaps) 17/21: Use the builder pattern for the MonotonicPairedDataMap
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 9c4a0deaaa4447cad7174e605556a2a6b54d81af
Author: Bertil Chapuis <bc...@gmail.com>
AuthorDate: Sat Apr 5 13:17:31 2025 +0200
Use the builder pattern for the MonotonicPairedDataMap
---
.../apache/baremaps/workflow/WorkflowContext.java | 7 ++++---
.../data/collection/MonotonicPairedDataMap.java | 22 +++++++---------------
.../java/org/apache/baremaps/data/DataMapTest.java | 7 ++++---
3 files changed, 15 insertions(+), 21 deletions(-)
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/workflow/WorkflowContext.java b/baremaps-core/src/main/java/org/apache/baremaps/workflow/WorkflowContext.java
index bfcbf7cc0..037b1c40a 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/workflow/WorkflowContext.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/workflow/WorkflowContext.java
@@ -104,11 +104,12 @@ public class WorkflowContext {
DataType<Coordinate> dataType)
throws IOException {
Path mapDir = Files.createDirectories(cacheDir.resolve(name));
- return new MonotonicPairedDataMap<>(
- MemoryAlignedDataList.<PairDataType.Pair<Long, Coordinate>>builder()
+ return MonotonicPairedDataMap.<Coordinate>builder()
+ .values(MemoryAlignedDataList.<PairDataType.Pair<Long, Coordinate>>builder()
.dataType(new PairDataType<>(new LongDataType(), new LonLatDataType()))
.memory(new MemoryMappedDirectory(Files.createDirectories(mapDir)))
- .build());
+ .build())
+ .build();
}
public void cleanCache() throws IOException {
diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/collection/MonotonicPairedDataMap.java b/baremaps-data/src/main/java/org/apache/baremaps/data/collection/MonotonicPairedDataMap.java
index 882c49903..07c285f9d 100644
--- a/baremaps-data/src/main/java/org/apache/baremaps/data/collection/MonotonicPairedDataMap.java
+++ b/baremaps-data/src/main/java/org/apache/baremaps/data/collection/MonotonicPairedDataMap.java
@@ -96,30 +96,22 @@ public class MonotonicPairedDataMap<E> implements DataMap<Long, E> {
}
if (offsets == null) {
- return new MonotonicPairedDataMap<>(values);
- } else {
- return new MonotonicPairedDataMap<>(offsets, values);
+ offsets = MemoryAlignedDataList.<Long>builder()
+ .dataType(new LongDataType())
+ .build();
}
+
+ return new MonotonicPairedDataMap<>(offsets, values);
}
}
/**
- * Constructs a {@link MonotonicPairedDataMap}.
- */
- public MonotonicPairedDataMap(MemoryAlignedDataList<Pair<Long, E>> values) {
- this(MemoryAlignedDataList.<Long>builder()
- .dataType(new LongDataType())
- .build(),
- values);
- }
-
- /**
- * Constructs a {@link MonotonicPairedDataMap}.
+ * Private constructor for {@link MonotonicPairedDataMap}.
*
* @param offsets the list of offsets
* @param values the buffer of values
*/
- public MonotonicPairedDataMap(DataList<Long> offsets,
+ private MonotonicPairedDataMap(DataList<Long> offsets,
MemoryAlignedDataList<Pair<Long, E>> values) {
this.offsets = offsets;
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 5755d0758..a66a16a67 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
@@ -187,10 +187,11 @@ class DataMapTest {
.memory(new OffHeapMemory())
.build())
.build()),
- Arguments.of(new MonotonicPairedDataMap<>(
- MemoryAlignedDataList.<PairDataType.Pair<Long, Long>>builder()
+ Arguments.of(MonotonicPairedDataMap.<Long>builder()
+ .values(MemoryAlignedDataList.<PairDataType.Pair<Long, Long>>builder()
.dataType(new PairDataType<>(new LongDataType(), new LongDataType()))
- .build())),
+ .build())
+ .build()),
Arguments.of(DirectHashDataMap.<Long>builder()
.keyType(new LongDataType())
.dataType(new LongDataType())