org.somda.sdc.biceps.provider.preprocessing.DuplicateChecker Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of biceps Show documentation
Show all versions of biceps Show documentation
SDCri is a set of Java libraries that implements a network communication framework conforming
with the IEEE 11073 SDC specifications. This project implements the functionality described in
IEEE 11073-10207.
package org.somda.sdc.biceps.provider.preprocessing;
import com.google.inject.Inject;
import org.somda.sdc.biceps.common.*;
import org.somda.sdc.biceps.common.storage.DescriptionPreprocessingSegment;
import org.somda.sdc.biceps.common.storage.MdibStorage;
import java.util.HashSet;
import java.util.Set;
/**
* Preprocessing segment that checks for handle duplicates on inserted entities during description modifications.
*/
public class DuplicateChecker implements DescriptionPreprocessingSegment {
private final Set handleCache;
@Inject
DuplicateChecker() {
handleCache = new HashSet<>();
}
@Override
public void beforeFirstModification(MdibDescriptionModifications modifications, MdibStorage mdibStorage) {
handleCache.clear();
}
@Override
public void process(MdibDescriptionModifications allModifications,
MdibDescriptionModification currentModification,
MdibStorage storage) throws Exception {
if (currentModification.getModificationType() == MdibDescriptionModification.Type.INSERT) {
if (storage.getEntity(currentModification.getHandle()).isPresent()) {
throw new HandleDuplicatedException(String.format("Inserted handle is a duplicate: %s",
currentModification.getHandle()));
}
}
}
@Override
public String toString() {
return getClass().getSimpleName();
}
}