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

com.nedap.archie.serializer.adl.constraints.CBooleanSerializer Maven / Gradle / Ivy

There is a newer version: 3.12.0
Show newest version
package com.nedap.archie.serializer.adl.constraints;

import com.google.common.base.Joiner;
import com.nedap.archie.aom.primitives.CBoolean;
import com.nedap.archie.serializer.adl.ADLDefinitionSerializer;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Marko Pipan
 */
public class CBooleanSerializer extends ConstraintSerializer {
    public CBooleanSerializer(ADLDefinitionSerializer serializer) {
        super(serializer);
    }

    public static String capitalize(String str) {
        if (str == null || str.length() == 0) {
            return str;
        }
        return Character.toString(Character.toUpperCase(str.charAt(0))) + str.substring(1);
    }

    @Override
    public void serialize(CBoolean cobj) {

        boolean constrained = false;

        List valids = new ArrayList<>();
        if (!cobj.getConstraint().isEmpty()) {
            valids.addAll(cobj.getConstraint().stream()
                    .map(aBoolean -> capitalize(aBoolean.toString().toLowerCase())).collect(Collectors.toList()));
        }


        if (!valids.isEmpty()) {
            builder.append(Joiner.on(", ").join(valids));
            constrained = true;
        }

        if (cobj.getAssumedValue() != null) {
            builder.append("; ").append(capitalize(cobj.getAssumedValue().toString()));
            constrained = true;
        }

        if (!constrained) {
            builder.append("*");
        }


    }

    @Override
    public boolean isEmpty(CBoolean cobj) {
        return cobj.getConstraint() == null || cobj.getConstraint().isEmpty();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy