mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Refactor: move initUsed(true) inside ChainingInterface.getContext()
This commit is contained in:
@@ -57,7 +57,8 @@ public class Chaining implements ChainingInterface {
|
||||
public boolean usedInit() {
|
||||
return used;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initUsed(boolean used) {
|
||||
this.used = used;
|
||||
}
|
||||
@@ -67,10 +68,11 @@ public class Chaining implements ChainingInterface {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getContext(
|
||||
public <T extends ChainingInterface> T getContext(
|
||||
Class<? extends T> contextClass, Function<ChainingInterface, T> createChaining) {
|
||||
for (ChainingInterface context : contextChain) {
|
||||
if (context.getClass() == contextClass && !context.usedInit()) {
|
||||
context.initUsed(true);
|
||||
//noinspection unchecked
|
||||
return (T) context;
|
||||
}
|
||||
@@ -85,6 +87,8 @@ public class Chaining implements ChainingInterface {
|
||||
"stack trace on https://github.com/OpenHFT/Chronicle-Map/issues");
|
||||
}
|
||||
//noinspection unchecked
|
||||
return (T) createChaining.apply(this);
|
||||
T context = createChaining.apply(this);
|
||||
context.initUsed(true);
|
||||
return context;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,10 @@ public interface ChainingInterface {
|
||||
|
||||
List<ChainingInterface> getContextChain();
|
||||
|
||||
void initUsed(boolean used);
|
||||
|
||||
boolean usedInit();
|
||||
|
||||
<T> T getContext(
|
||||
<T extends ChainingInterface> T getContext(
|
||||
Class<? extends T> contextClass, Function<ChainingInterface, T> createChaining);
|
||||
}
|
||||
|
||||
@@ -459,12 +459,8 @@ public class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? sup
|
||||
|
||||
@Override
|
||||
public CompiledReplicatedMapQueryContext<K, KI, MKI, V, VI, MVI, R> mapContext() {
|
||||
CompiledReplicatedMapQueryContext<K, KI, MKI, V, VI, MVI, R> q =
|
||||
q().getContext(CompiledReplicatedMapQueryContext.class,
|
||||
ci -> new CompiledReplicatedMapQueryContext<>(ci,
|
||||
ReplicatedChronicleMap.this));
|
||||
q.initUsed(true);
|
||||
return q;
|
||||
return q().getContext(CompiledReplicatedMapQueryContext.class,
|
||||
ci -> new CompiledReplicatedMapQueryContext<>(ci, this));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -514,12 +510,8 @@ public class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? sup
|
||||
}
|
||||
|
||||
public CompiledReplicatedMapIterationContext<K, KI, MKI, V, VI, MVI, R> iterationContext() {
|
||||
CompiledReplicatedMapIterationContext<K, KI, MKI, V, VI, MVI, R> c =
|
||||
i().getContext(CompiledReplicatedMapIterationContext.class,
|
||||
ci -> new CompiledReplicatedMapIterationContext<>(ci,
|
||||
ReplicatedChronicleMap.this));
|
||||
c.initUsed(true);
|
||||
return c;
|
||||
return i().getContext(CompiledReplicatedMapIterationContext.class,
|
||||
ci -> new CompiledReplicatedMapIterationContext<>(ci, this));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -303,11 +303,8 @@ public class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super
|
||||
}
|
||||
|
||||
public QueryContextInterface<K, V, R> mapContext() {
|
||||
CompiledMapQueryContext<K, KI, MKI, V, VI, MVI, R> q =
|
||||
q().getContext(CompiledMapQueryContext.class,
|
||||
ci -> new CompiledMapQueryContext<>(ci, VanillaChronicleMap.this));
|
||||
q.initUsed(true);
|
||||
return q;
|
||||
return q().getContext(CompiledMapQueryContext.class,
|
||||
ci -> new CompiledMapQueryContext<>(ci, this));
|
||||
}
|
||||
|
||||
private ChainingInterface i() {
|
||||
@@ -321,11 +318,8 @@ public class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super
|
||||
}
|
||||
|
||||
public IterationContextInterface<K, V, ?> iterationContext() {
|
||||
CompiledMapIterationContext<K, KI, MKI, V, VI, MVI, R> c =
|
||||
i().getContext(CompiledMapIterationContext.class,
|
||||
ci -> new CompiledMapIterationContext<>(ci, VanillaChronicleMap.this));
|
||||
c.initUsed(true);
|
||||
return c;
|
||||
return i().getContext(CompiledMapIterationContext.class,
|
||||
ci -> new CompiledMapIterationContext<>(ci, this));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user