aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store
diff options
context:
space:
mode:
authorLibravatar OszkarSemerath <semerath@mit.bme.hu>2023-02-13 01:15:44 +0100
committerLibravatar OszkarSemerath <semerath@mit.bme.hu>2023-02-13 01:15:44 +0100
commit1543e42dd5b63af6f4228ec545d4f2666ff73274 (patch)
treef6c6f7bbd9e5c306cfd0aa1bd55a2b6f4dd42be9 /subprojects/store
parentMoved test parametrization to FuzzTestCollections.java (diff)
downloadrefinery-1543e42dd5b63af6f4228ec545d4f2666ff73274.tar.gz
refinery-1543e42dd5b63af6f4228ec545d4f2666ff73274.tar.zst
refinery-1543e42dd5b63af6f4228ec545d4f2666ff73274.zip
VersionedMapStoreBuilder returns builder state.
Diffstat (limited to 'subprojects/store')
-rw-r--r--subprojects/store/src/main/java/tools/refinery/store/map/VersionedMapStoreBuilder.java85
1 files changed, 67 insertions, 18 deletions
diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/VersionedMapStoreBuilder.java b/subprojects/store/src/main/java/tools/refinery/store/map/VersionedMapStoreBuilder.java
index 7e413a86..1a9aa0b3 100644
--- a/subprojects/store/src/main/java/tools/refinery/store/map/VersionedMapStoreBuilder.java
+++ b/subprojects/store/src/main/java/tools/refinery/store/map/VersionedMapStoreBuilder.java
@@ -2,7 +2,6 @@ package tools.refinery.store.map;
2 2
3import java.util.ArrayList; 3import java.util.ArrayList;
4import java.util.List; 4import java.util.List;
5import java.util.Optional;
6 5
7public class VersionedMapStoreBuilder<K, V> { 6public class VersionedMapStoreBuilder<K, V> {
8 public enum StoreStrategy { 7 public enum StoreStrategy {
@@ -17,41 +16,76 @@ public class VersionedMapStoreBuilder<K, V> {
17 NO_NODE_CACHE, SHARED_NODE_CACHE, SHARED_NODE_CACHE_IN_GROUP 16 NO_NODE_CACHE, SHARED_NODE_CACHE, SHARED_NODE_CACHE_IN_GROUP
18 } 17 }
19 18
20 protected Optional<V> defaultValue = Optional.empty(); 19 public static <K, V> VersionedMapStoreBuilder<K, V> builder() {
20 return new VersionedMapStoreBuilder<>();
21 }
22 protected VersionedMapStoreBuilder() {
23 }
24 protected VersionedMapStoreBuilder(VersionedMapStoreBuilder<K, V> other) {
25 this.defaultValue = other.defaultValue;
26 this.defaultSet = other.defaultSet;
27 this.strategy = other.strategy;
28 this.stateBasedImmutableWhenCommitting = other.stateBasedImmutableWhenCommitting;
29 this.stateBasedNodeSharingStrategy = other.stateBasedNodeSharingStrategy;
30 this.hashProvider = other.hashProvider;
31 this.deltaStorageStrategy = other.deltaStorageStrategy;
32 }
33 protected boolean defaultSet = false;
34 protected V defaultValue = null;
21 protected StoreStrategy strategy = StoreStrategy.DELTA; 35 protected StoreStrategy strategy = StoreStrategy.DELTA;
22 protected Boolean stateBasedImmutableWhenCommitting = false; 36 protected Boolean stateBasedImmutableWhenCommitting = false;
23 protected StateStorageStrategy stateBasedNodeSharingStrategy = StateStorageStrategy.SHARED_NODE_CACHE_IN_GROUP; 37 protected StateStorageStrategy stateBasedNodeSharingStrategy = StateStorageStrategy.SHARED_NODE_CACHE_IN_GROUP;
24 protected Optional<ContinousHashProvider<K>> hashProvider = Optional.empty(); 38 protected ContinousHashProvider<K> hashProvider = null;
25 protected DeltaStorageStrategy deltaStorageStrategy = DeltaStorageStrategy.LIST; 39 protected DeltaStorageStrategy deltaStorageStrategy = DeltaStorageStrategy.LIST;
26 40
27 public void setDefaultValue(V defaultValue) { 41 public VersionedMapStoreBuilder<K, V> setDefaultValue(V defaultValue) {
28 this.defaultValue = Optional.of(defaultValue); 42 var result = new VersionedMapStoreBuilder<>(this);
43 result.defaultValue = defaultValue;
44 result.defaultSet = true;
45 return result;
46 }
47
48 public VersionedMapStoreBuilder<K, V> setStrategy(StoreStrategy strategy) {
49 var result = new VersionedMapStoreBuilder<>(this);
50 result.strategy = strategy;
51 return result;
29 } 52 }
30 53
31 public void setStrategy(StoreStrategy strategy) { 54 public VersionedMapStoreBuilder<K, V> setHashProvider(ContinousHashProvider<K> hashProvider) {
32 this.strategy = strategy; 55 var result = new VersionedMapStoreBuilder<>(this);
56 result.hashProvider = hashProvider;
57 return result;
33 } 58 }
34 59
35 public void setHashProvider(ContinousHashProvider<K> hashProvider) { 60 public VersionedMapStoreBuilder<K, V> setStateBasedImmutableWhenCommitting(boolean toImmutableWhenCommitting) {
36 this.hashProvider = Optional.of(hashProvider); 61 var result = new VersionedMapStoreBuilder<>(this);
62 result.stateBasedImmutableWhenCommitting = toImmutableWhenCommitting;
63 return result;
37 } 64 }
38 65
39 public void setStateBasedImmutableWhenCommitting(boolean toImmutableWhenCommitting) { 66 public VersionedMapStoreBuilder<K, V> setStateBasedNodeSharingStrategy(StateStorageStrategy strategy) {
40 this.stateBasedImmutableWhenCommitting = toImmutableWhenCommitting; 67 var result = new VersionedMapStoreBuilder<>(this);
68 result.stateBasedNodeSharingStrategy = strategy;
69 return result;
41 } 70 }
42 71
43 public void setStateBasedNodeSharingStrategy(StateStorageStrategy strategy) { 72 public VersionedMapStoreBuilder<K, V> setDeltaStorageStrategy(DeltaStorageStrategy deltaStorageStrategy) {
44 this.stateBasedNodeSharingStrategy = strategy; 73 var result = new VersionedMapStoreBuilder<>(this);
74 result.deltaStorageStrategy = deltaStorageStrategy;
75 return result;
45 } 76 }
46 77
47 public VersionedMapStore<K, V> buildOne() { 78 public VersionedMapStore<K, V> buildOne() {
79 if(!defaultSet) {
80 throw new IllegalStateException("Default value is missing!");
81 }
48 return switch (strategy) { 82 return switch (strategy) {
49 case DELTA -> new VersionedMapStoreDeltaImpl<>( 83 case DELTA -> new VersionedMapStoreDeltaImpl<>(
50 this.deltaStorageStrategy == DeltaStorageStrategy.SET, 84 this.deltaStorageStrategy == DeltaStorageStrategy.SET,
51 this.defaultValue.orElseThrow()); 85 this.defaultValue);
52 case STATE -> new VersionedMapStoreImpl<>( 86 case STATE -> new VersionedMapStoreImpl<>(
53 this.hashProvider.orElseThrow(), 87 this.hashProvider,
54 this.defaultValue.orElseThrow(), 88 this.defaultValue,
55 new VersionedMapStoreConfiguration( 89 new VersionedMapStoreConfiguration(
56 this.stateBasedImmutableWhenCommitting, 90 this.stateBasedImmutableWhenCommitting,
57 this.stateBasedNodeSharingStrategy != StateStorageStrategy.NO_NODE_CACHE, 91 this.stateBasedNodeSharingStrategy != StateStorageStrategy.NO_NODE_CACHE,
@@ -60,12 +94,15 @@ public class VersionedMapStoreBuilder<K, V> {
60 } 94 }
61 95
62 public List<VersionedMapStore<K, V>> buildGroup(int amount) { 96 public List<VersionedMapStore<K, V>> buildGroup(int amount) {
97 if(!defaultSet) {
98 throw new IllegalStateException("Default value is missing!");
99 }
63 if (this.strategy == StoreStrategy.STATE && 100 if (this.strategy == StoreStrategy.STATE &&
64 this.stateBasedNodeSharingStrategy == StateStorageStrategy.SHARED_NODE_CACHE_IN_GROUP) { 101 this.stateBasedNodeSharingStrategy == StateStorageStrategy.SHARED_NODE_CACHE_IN_GROUP) {
65 return VersionedMapStoreImpl.createSharedVersionedMapStores( 102 return VersionedMapStoreImpl.createSharedVersionedMapStores(
66 amount, 103 amount,
67 this.hashProvider.orElseThrow(), 104 this.hashProvider,
68 this.defaultValue.orElseThrow(), 105 this.defaultValue,
69 new VersionedMapStoreConfiguration( 106 new VersionedMapStoreConfiguration(
70 this.stateBasedImmutableWhenCommitting, 107 this.stateBasedImmutableWhenCommitting,
71 true, 108 true,
@@ -78,4 +115,16 @@ public class VersionedMapStoreBuilder<K, V> {
78 return result; 115 return result;
79 } 116 }
80 } 117 }
118
119 @Override
120 public String toString() {
121 return "VersionedMapStoreBuilder{" +
122 "defaultValue=" + defaultValue +
123 ", strategy=" + strategy +
124 ", stateBasedImmutableWhenCommitting=" + stateBasedImmutableWhenCommitting +
125 ", stateBasedNodeSharingStrategy=" + stateBasedNodeSharingStrategy +
126 ", hashProvider=" + hashProvider +
127 ", deltaStorageStrategy=" + deltaStorageStrategy +
128 '}';
129 }
81} 130}