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

selva.oss.ds.document.DocumentExistanceAndEqualityApi Maven / Gradle / Ivy

The newest version!
package selva.oss.ds.document;

import static selva.oss.lang.Commons.*;
import selva.oss.ds.document.datatype.DataTypeConfig;
import selva.oss.ds.document.datatype.TypedValue;

import java.util.*;

interface DocumentExistanceAndEqualityApi {

    default boolean isPresent(T field) {
        throw new HasNotBeenImplementedException();
    }

    default boolean isEqual(DocumentStore inData, T field) {
        throw new HasNotBeenImplementedException();
    }

    default boolean diffAndCheckIfEdited(DocumentStore inData, T field) {
        throw new HasNotBeenImplementedException();
    }

}

interface DocumentExistanceAndEqualityOps extends DocumentBaseApi, DocumentStore {

    default boolean isPresent(String field) {
        return containsValue(DocumentParamsStateValidator.createWithValidField(field));
    }

    default boolean isEqual(DocumentStore inData, String field) {
        validateNotNull(inData);
        validateNotNull(field);

        if (!isPresent(field) || !inData.isPresent(field)) {
            return false;
        }
        return getTypedValue(field).equals(inData.getTypedValue(field));
    }

    default boolean diffAndCheckIfEdited(DocumentStore inData, String field) {
        validateNotNull(inData);
        validateNotNull(field);

        return ((!isPresent(field) && inData.isPresent(field)) || (isPresent(field) && inData.isPresent(field) && !getTypedValue(field).equals(inData.getTypedValue(field))));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy