Search in sources :

Example 1 with AbstractMapDecorator

use of org.apache.commons.collections.map.AbstractMapDecorator in project configuration-as-code-plugin by jenkinsci.

the class ModelConstructor method constructMapping2ndStep.

/**
 * Enforce Map keys are only Scalars and can be used as {@link String} keys in {@link Mapping}
 */
@Override
protected void constructMapping2ndStep(MappingNode node, final Map mapping) {
    ((Mapping) mapping).setSource(getSource(node));
    super.constructMapping2ndStep(node, new AbstractMapDecorator(mapping) {

        @Override
        public Object put(Object key, Object value) {
            if (!(key instanceof Scalar))
                throw new IllegalStateException("We only support scalar map keys");
            Object scalar = ObjectUtils.clone(value);
            if (scalar instanceof Number)
                scalar = new Scalar(scalar.toString());
            else if (scalar instanceof Boolean)
                scalar = new Scalar(scalar.toString());
            return mapping.put(key.toString(), scalar);
        }
    });
}
Also used : AbstractMapDecorator(org.apache.commons.collections.map.AbstractMapDecorator) Mapping(io.jenkins.plugins.casc.model.Mapping) Scalar(io.jenkins.plugins.casc.model.Scalar)

Aggregations

Mapping (io.jenkins.plugins.casc.model.Mapping)1 Scalar (io.jenkins.plugins.casc.model.Scalar)1 AbstractMapDecorator (org.apache.commons.collections.map.AbstractMapDecorator)1