All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.somda.sdc.biceps.provider.preprocessing.DuplicateChecker Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 5.1.1
Show newest version
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();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy