Refactor: move initUsed(true) inside ChainingInterface.getContext()

This commit is contained in:
leventov
2015-10-06 18:59:54 +03:00
parent b967ad14d4
commit 70fb0dd2fa
4 changed files with 18 additions and 26 deletions
@@ -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);
}