
org.simpleflatmapper.map.context.impl.BreakDetectorMappingContext Maven / Gradle / Ivy
package org.simpleflatmapper.map.context.impl;
import org.simpleflatmapper.map.MappingContext;
import org.simpleflatmapper.map.context.KeyDefinition;
public class BreakDetectorMappingContext extends MappingContext {
private final BreakDetector rootDetector;
private final MappingContext delegateContext;
private final BreakDetector[] breakDetectors;
public BreakDetectorMappingContext(KeyDefinition rootKeyDefinition,
MappingContext delegateContext,
KeyDefinition[] keyDefinitions) {
this.delegateContext = delegateContext;
this.breakDetectors = toBreakDetectors(keyDefinitions);
this.rootDetector = breakDetectors[rootKeyDefinition.getIndex()];
}
@SuppressWarnings("unchecked")
private static BreakDetector[] toBreakDetectors(KeyDefinition[] definitions) {
BreakDetector[] breakDetectors = new BreakDetector[definitions.length];
for (int i = 0; i < definitions.length; i++) {
KeyDefinition definition = definitions[i];
breakDetectors[i] = new BreakDetector(definition);
}
return breakDetectors;
}
@Override
public boolean broke(S source) {
boolean b = rootDetector.broke(source);
if (b) {
for(BreakDetector breakDetector : breakDetectors) {
if (breakDetector != rootDetector) {
breakDetector.markRootAsBroken();
}
}
}
for(BreakDetector breakDetector : breakDetectors) {
if (breakDetector != rootDetector) {
breakDetector.handleSource(source);
}
}
return b;
}
@Override
public void markAsBroken() {
for(BreakDetector breakDetector : breakDetectors) {
breakDetector.markRootAsBroken();
}
}
@Override
public T context(int i) {
return delegateContext.context(i);
}
@Override
public void setCurrentValue(int i, Object value) {
this.breakDetectors[i].setValue(value);
}
@Override
public Object getCurrentValue(int i) {
return breakDetectors[i].getValue();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy