Skip to content

Commit 5aa6f02

Browse files
committed
MNEMONIC-280 Add overload methods to handle optional paramters
1 parent 8c40920 commit 5aa6f02

File tree

12 files changed

+370
-2
lines changed

12 files changed

+370
-2
lines changed

mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashMapImpl.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.mnemonic.RestoreDurableEntityError;
2828
import org.apache.mnemonic.RetrieveDurableEntityError;
2929
import org.apache.mnemonic.Utils;
30+
import org.apache.mnemonic.ParameterHolder;
3031

3132
import org.apache.commons.lang3.tuple.Pair;
3233
import org.apache.commons.lang3.ArrayUtils;
@@ -478,12 +479,25 @@ public <A extends RestorableAllocator<A>> MapEntry<K, V> restore(
478479
return MapEntryFactory.restore(allocator, dpt.getRight(), dpt.getLeft(), phandler, autoreclaim);
479480
}
480481
@Override
482+
public <A extends RestorableAllocator<A>> MapEntry<K, V> restore(ParameterHolder<A> ph) {
483+
Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(ph.getGenericTypes(),
484+
ph.getEntityFactoryProxies(), 1);
485+
return MapEntryFactory.restore(ph.getAllocator(),
486+
dpt.getRight(), dpt.getLeft(), ph.getHandler(), ph.getAutoReclaim());
487+
}
488+
@Override
481489
public <A extends RestorableAllocator<A>> MapEntry<K, V> create(
482490
A allocator, EntityFactoryProxy[] factoryproxys,
483491
DurableType[] gfields, boolean autoreclaim) {
484492
Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(gfields, factoryproxys, 1);
485493
return MapEntryFactory.create(allocator, dpt.getRight(), dpt.getLeft(), autoreclaim);
486494
}
495+
@Override
496+
public <A extends RestorableAllocator<A>> MapEntry<K, V> create(ParameterHolder<A> ph) {
497+
Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(ph.getGenericTypes(),
498+
ph.getEntityFactoryProxies(), 1);
499+
return MapEntryFactory.create(ph.getAllocator(), dpt.getRight(), dpt.getLeft(), ph.getAutoReclaim());
500+
}
487501
}
488502
};
489503
this.listefproxies = ArrayUtils.addAll(efproxies, factoryProxy);

mnemonic-collections/src/test/java/org/apache/mnemonic/collections/DurableArrayNGTest.java

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.mnemonic.Durable;
3636
import org.apache.mnemonic.EntityFactoryProxy;
3737
import org.apache.mnemonic.Reclaim;
38+
import org.apache.mnemonic.ParameterHolder;
3839
import org.apache.commons.lang3.RandomUtils;
3940
import org.testng.annotations.AfterClass;
4041
import org.testng.annotations.BeforeClass;
@@ -308,12 +309,23 @@ public <A extends RestorableAllocator<A>> Person<Long> restore(
308309
return PersonFactory.restore(allocator, factoryproxys, gfields, phandler, autoreclaim);
309310
}
310311
@Override
312+
public <A extends RestorableAllocator<A>> Person<Long> restore(ParameterHolder<A> ph) {
313+
return PersonFactory.restore(ph.getAllocator(),
314+
ph.getEntityFactoryProxies(), ph.getGenericTypes(), ph.getHandler(), ph.getAutoReclaim());
315+
}
316+
@Override
311317
public <A extends RestorableAllocator<A>> Person<Long> create(
312318
A allocator, EntityFactoryProxy[] factoryproxys,
313319
DurableType[] gfields, boolean autoreclaim) {
314320
return PersonFactory.create(allocator, factoryproxys, gfields, autoreclaim);
315321
}
316-
} };
322+
@Override
323+
public <A extends RestorableAllocator<A>> Person<Long> create(ParameterHolder<A> ph) {
324+
return PersonFactory.create(ph.getAllocator(),
325+
ph.getEntityFactoryProxies(), ph.getGenericTypes(), ph.getAutoReclaim());
326+
}
327+
}
328+
};
317329

318330
Person<Long> person = (Person<Long>) efproxies[0].create(m_act, null, null, false);
319331
person.setName("Alice", false);
@@ -355,12 +367,26 @@ public <A extends RestorableAllocator<A>> Durable restore(A allocator, EntityFac
355367
return DurableSinglyLinkedListFactory.restore(allocator, dpt.getRight(), dpt.getLeft(), phandler, autoreclaim);
356368
}
357369
@Override
370+
public <A extends RestorableAllocator<A>> Durable restore(ParameterHolder<A> ph) {
371+
Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(ph.getGenericTypes(),
372+
ph.getEntityFactoryProxies(), 1);
373+
return DurableSinglyLinkedListFactory.restore(ph.getAllocator(),
374+
dpt.getRight(), dpt.getLeft(), ph.getHandler(), ph.getAutoReclaim());
375+
}
376+
@Override
358377
public <A extends RestorableAllocator<A>> Durable create(
359378
A allocator, EntityFactoryProxy[] factoryproxys,
360379
DurableType[] gfields, boolean autoreclaim) {
361380
Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(gfields, factoryproxys, 1);
362381
return DurableSinglyLinkedListFactory.create(allocator, dpt.getRight(), dpt.getLeft(), autoreclaim);
363382
}
383+
@Override
384+
public <A extends RestorableAllocator<A>> Durable create(ParameterHolder<A> ph) {
385+
Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(ph.getGenericTypes(),
386+
ph.getEntityFactoryProxies(), 1);
387+
return DurableSinglyLinkedListFactory.create(ph.getAllocator(),
388+
dpt.getRight(), dpt.getLeft(), ph.getAutoReclaim());
389+
}
364390
}
365391
};
366392
DurableArray<DurableSinglyLinkedList<Integer>> array = DurableArrayFactory.create(m_act, arrayproxies,
@@ -388,11 +414,21 @@ public <A extends RestorableAllocator<A>> Person<Long> restore(
388414
return PersonFactory.restore(allocator, factoryproxys, gfields, phandler, autoreclaim);
389415
}
390416
@Override
417+
public <A extends RestorableAllocator<A>> Person<Long> restore(ParameterHolder<A> ph) {
418+
return PersonFactory.restore(ph.getAllocator(),
419+
ph.getEntityFactoryProxies(), ph.getGenericTypes(), ph.getHandler(), ph.getAutoReclaim());
420+
}
421+
@Override
391422
public <A extends RestorableAllocator<A>> Person<Long> create(
392423
A allocator, EntityFactoryProxy[] factoryproxys,
393424
DurableType[] gfields, boolean autoreclaim) {
394425
return PersonFactory.create(allocator, factoryproxys, gfields, autoreclaim);
395426
}
427+
@Override
428+
public <A extends RestorableAllocator<A>> Person<Long> create(ParameterHolder<A> ph) {
429+
return PersonFactory.create(ph.getAllocator(),
430+
ph.getEntityFactoryProxies(), ph.getGenericTypes(), ph.getAutoReclaim());
431+
}
396432
}
397433
};
398434
Person<Long> person = (Person<Long>) efproxies[1].create(m_act, null, null, false);
@@ -420,12 +456,26 @@ public <A extends RestorableAllocator<A>> DurableHashMap<String, Person<Long>> r
420456
return DurableHashMapFactory.restore(allocator, dpt.getRight(), dpt.getLeft(), phandler, autoreclaim);
421457
}
422458
@Override
459+
public <A extends RestorableAllocator<A>> DurableHashMap<String, Person<Long>> restore(ParameterHolder<A> ph) {
460+
Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(ph.getGenericTypes(),
461+
ph.getEntityFactoryProxies(), 1);
462+
return DurableHashMapFactory.restore(ph.getAllocator(),
463+
dpt.getRight(), dpt.getLeft(), ph.getHandler(), ph.getAutoReclaim());
464+
}
465+
@Override
423466
public <A extends RestorableAllocator<A>> DurableHashMap<String, Person<Long>> create(
424467
A allocator, EntityFactoryProxy[] factoryproxys,
425468
DurableType[] gfields, boolean autoreclaim) {
426469
Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(gfields, factoryproxys, 1);
427470
return DurableHashMapFactory.create(allocator, dpt.getRight(), dpt.getLeft(), 10, autoreclaim);
428471
}
472+
@Override
473+
public <A extends RestorableAllocator<A>> DurableHashMap<String, Person<Long>> create(ParameterHolder<A> ph) {
474+
Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(ph.getGenericTypes(),
475+
ph.getEntityFactoryProxies(), 1);
476+
return DurableHashMapFactory.create(ph.getAllocator(),
477+
dpt.getRight(), dpt.getLeft(), 10, ph.getAutoReclaim());
478+
}
429479
}
430480
};
431481
arrayproxies = ArrayUtils.addAll(arrayproxies, efproxies);

mnemonic-collections/src/test/java/org/apache/mnemonic/collections/DurableHashMapNGTest.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.apache.mnemonic.DurableChunk;
3434
import org.apache.mnemonic.Reclaim;
3535
import org.apache.mnemonic.Durable;
36+
import org.apache.mnemonic.ParameterHolder;
3637
import org.apache.commons.lang3.tuple.Pair;
3738
import org.apache.commons.lang3.RandomUtils;
3839
import org.testng.annotations.AfterClass;
@@ -202,11 +203,21 @@ public <A extends RestorableAllocator<A>> Person<Long> restore(
202203
return PersonFactory.restore(allocator, factoryproxys, gfields, phandler, autoreclaim);
203204
}
204205
@Override
206+
public <A extends RestorableAllocator<A>> Person<Long> restore(ParameterHolder<A> ph) {
207+
return PersonFactory.restore(ph.getAllocator(),
208+
ph.getEntityFactoryProxies(), ph.getGenericTypes(), ph.getHandler(), ph.getAutoReclaim());
209+
}
210+
@Override
205211
public <A extends RestorableAllocator<A>> Person<Long> create(
206212
A allocator, EntityFactoryProxy[] factoryproxys,
207213
DurableType[] gfields, boolean autoreclaim) {
208214
return PersonFactory.create(allocator, factoryproxys, gfields, autoreclaim);
209215
}
216+
@Override
217+
public <A extends RestorableAllocator<A>> Person<Long> create(ParameterHolder<A> ph) {
218+
return PersonFactory.create(ph.getAllocator(),
219+
ph.getEntityFactoryProxies(), ph.getGenericTypes(), ph.getAutoReclaim());
220+
}
210221
} };
211222

212223
Person<Long> person = (Person<Long>) efproxies[0].create(m_act, null, null, false);
@@ -257,11 +268,21 @@ public <A extends RestorableAllocator<A>> Person<Long> restore(
257268
return PersonFactory.restore(allocator, factoryproxys, gfields, phandler, autoreclaim);
258269
}
259270
@Override
271+
public <A extends RestorableAllocator<A>> Person<Long> restore(ParameterHolder<A> ph) {
272+
return PersonFactory.restore(ph.getAllocator(),
273+
ph.getEntityFactoryProxies(), ph.getGenericTypes(), ph.getHandler(), ph.getAutoReclaim());
274+
}
275+
@Override
260276
public <A extends RestorableAllocator<A>> Person<Long> create(
261277
A allocator, EntityFactoryProxy[] factoryproxys,
262278
DurableType[] gfields, boolean autoreclaim) {
263279
return PersonFactory.create(allocator, factoryproxys, gfields, autoreclaim);
264280
}
281+
@Override
282+
public <A extends RestorableAllocator<A>> Person<Long> create(ParameterHolder<A> ph) {
283+
return PersonFactory.create(ph.getAllocator(),
284+
ph.getEntityFactoryProxies(), ph.getGenericTypes(), ph.getAutoReclaim());
285+
}
265286
} };
266287

267288
Person<Long> person = (Person<Long>) efproxies[1].create(m_act, null, null, false);
@@ -304,11 +325,21 @@ public <A extends RestorableAllocator<A>> Person<Long> restore(
304325
return PersonFactory.restore(allocator, factoryproxys, gfields, phandler, autoreclaim);
305326
}
306327
@Override
328+
public <A extends RestorableAllocator<A>> Person<Long> restore(ParameterHolder<A> ph) {
329+
return PersonFactory.restore(ph.getAllocator(),
330+
ph.getEntityFactoryProxies(), ph.getGenericTypes(), ph.getHandler(), ph.getAutoReclaim());
331+
}
332+
@Override
307333
public <A extends RestorableAllocator<A>> Person<Long> create(
308334
A allocator, EntityFactoryProxy[] factoryproxys,
309335
DurableType[] gfields, boolean autoreclaim) {
310336
return PersonFactory.create(allocator, factoryproxys, gfields, autoreclaim);
311337
}
338+
@Override
339+
public <A extends RestorableAllocator<A>> Person<Long> create(ParameterHolder<A> ph) {
340+
return PersonFactory.create(ph.getAllocator(),
341+
ph.getEntityFactoryProxies(), ph.getGenericTypes(), ph.getAutoReclaim());
342+
}
312343
}, new EntityFactoryProxy() {
313344
@Override
314345
public <A extends RestorableAllocator<A>> Person<Long> restore(
@@ -317,11 +348,21 @@ public <A extends RestorableAllocator<A>> Person<Long> restore(
317348
return PersonFactory.restore(allocator, factoryproxys, gfields, phandler, autoreclaim);
318349
}
319350
@Override
351+
public <A extends RestorableAllocator<A>> Person<Long> restore(ParameterHolder<A> ph) {
352+
return PersonFactory.restore(ph.getAllocator(),
353+
ph.getEntityFactoryProxies(), ph.getGenericTypes(), ph.getHandler(), ph.getAutoReclaim());
354+
}
355+
@Override
320356
public <A extends RestorableAllocator<A>> Person<Long> create(
321357
A allocator, EntityFactoryProxy[] factoryproxys,
322358
DurableType[] gfields, boolean autoreclaim) {
323359
return PersonFactory.create(allocator, factoryproxys, gfields, autoreclaim);
324360
}
361+
@Override
362+
public <A extends RestorableAllocator<A>> Person<Long> create(ParameterHolder<A> ph) {
363+
return PersonFactory.create(ph.getAllocator(),
364+
ph.getEntityFactoryProxies(), ph.getGenericTypes(), ph.getAutoReclaim());
365+
}
325366
} };
326367

327368
Person<Long> person = (Person<Long>) efproxies[0].create(m_act, null, null, false);
@@ -355,11 +396,21 @@ public <A extends RestorableAllocator<A>> Person<Long> restore(
355396
return PersonFactory.restore(allocator, factoryproxys, gfields, phandler, autoreclaim);
356397
}
357398
@Override
399+
public <A extends RestorableAllocator<A>> Person<Long> restore(ParameterHolder<A> ph) {
400+
return PersonFactory.restore(ph.getAllocator(),
401+
ph.getEntityFactoryProxies(), ph.getGenericTypes(), ph.getHandler(), ph.getAutoReclaim());
402+
}
403+
@Override
358404
public <A extends RestorableAllocator<A>> Person<Long> create(
359405
A allocator, EntityFactoryProxy[] factoryproxys,
360406
DurableType[] gfields, boolean autoreclaim) {
361407
return PersonFactory.create(allocator, factoryproxys, gfields, autoreclaim);
362408
}
409+
@Override
410+
public <A extends RestorableAllocator<A>> Person<Long> create(ParameterHolder<A> ph) {
411+
return PersonFactory.create(ph.getAllocator(),
412+
ph.getEntityFactoryProxies(), ph.getGenericTypes(), ph.getAutoReclaim());
413+
}
363414
} };
364415
DurableType mapgtypes[] = {DurableType.STRING, DurableType.DURABLE, DurableType.STRING, DurableType.DURABLE};
365416
EntityFactoryProxy mapefproxies[] = {null, new EntityFactoryProxy() {
@@ -371,12 +422,26 @@ public <A extends RestorableAllocator<A>> Durable restore(
371422
return DurableHashMapFactory.restore(allocator, dpt.getRight(), dpt.getLeft(), phandler, autoreclaim);
372423
}
373424
@Override
425+
public <A extends RestorableAllocator<A>> Durable restore(ParameterHolder<A> ph) {
426+
Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(ph.getGenericTypes(),
427+
ph.getEntityFactoryProxies(), 2);
428+
return DurableHashMapFactory.restore(ph.getAllocator(),
429+
dpt.getRight(), dpt.getLeft(), ph.getHandler(), ph.getAutoReclaim());
430+
}
431+
@Override
374432
public <A extends RestorableAllocator<A>> Durable create(
375433
A allocator, EntityFactoryProxy[] factoryproxys,
376434
DurableType[] gfields, boolean autoreclaim) {
377435
Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(gfields, factoryproxys, 2);
378436
return DurableHashMapFactory.create(allocator, dpt.getRight(), dpt.getLeft(), mInitialCapacity, autoreclaim);
379437
}
438+
@Override
439+
public <A extends RestorableAllocator<A>> Durable create(ParameterHolder<A> ph) {
440+
Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(ph.getGenericTypes(),
441+
ph.getEntityFactoryProxies(), 2);
442+
return DurableHashMapFactory.create(ph.getAllocator(),
443+
dpt.getRight(), dpt.getLeft(), mInitialCapacity, ph.getAutoReclaim());
444+
}
380445
}, null, new EntityFactoryProxy() {
381446
@Override
382447
public <A extends RestorableAllocator<A>> Person<Long> restore(
@@ -385,11 +450,21 @@ public <A extends RestorableAllocator<A>> Person<Long> restore(
385450
return PersonFactory.restore(allocator, factoryproxys, gfields, phandler, autoreclaim);
386451
}
387452
@Override
453+
public <A extends RestorableAllocator<A>> Person<Long> restore(ParameterHolder<A> ph) {
454+
return PersonFactory.restore(ph.getAllocator(),
455+
ph.getEntityFactoryProxies(), ph.getGenericTypes(), ph.getHandler(), ph.getAutoReclaim());
456+
}
457+
@Override
388458
public <A extends RestorableAllocator<A>> Person<Long> create(
389459
A allocator, EntityFactoryProxy[] factoryproxys,
390460
DurableType[] gfields, boolean autoreclaim) {
391461
return PersonFactory.create(allocator, factoryproxys, gfields, autoreclaim);
392462
}
463+
@Override
464+
public <A extends RestorableAllocator<A>> Person<Long> create(ParameterHolder<A> ph) {
465+
return PersonFactory.create(ph.getAllocator(),
466+
ph.getEntityFactoryProxies(), ph.getGenericTypes(), ph.getAutoReclaim());
467+
}
393468
} };
394469

395470
Person<Long> person = PersonFactory.create(m_act, null, null, false);

0 commit comments

Comments
 (0)