<commit_before>package com.ubiquity.core.datastore;

import com.ubiquity.core.datastore.IFieldDefinition.Type;

import java.util.Collection;
import java.util.Map;

public class Entry {

    private final Object fields[];

    public Entry(IDataDefinition dataDefinition, Map<String, Object> values) {
        assert dataDefinition != null;
        assert values != null;

        Collection<IFieldDefinition> fieldDefinitions = dataDefinition.getFieldDefinitions();
        this.fields = new Object[fieldDefinitions.size()];
        populateFields(fieldDefinitions, values);
    }


    private void populateFields(Collection<IFieldDefinition> fieldDefinitions, Map<String, Object> values) {
        int index = 0;

        for (IFieldDefinition fieldDefinition : fieldDefinitions) {
            populateField(fieldDefinition, index++, values);
        }
    }


    private void populateField(IFieldDefinition fieldDefinition, int index, Map<String, Object> values) {

        if (isFieldMandatoryAndMissing(fieldDefinition, values)) {
            /// TODO: throw
        }
        else {
            fields[index] = fieldValue(fieldDefinition, values);
        }
    }

    private Object fieldValue(IFieldDefinition fieldDefinition, Map<String, Object> values) {
        String fieldName = fieldDefinition.getName();
        Type fieldType = fieldDefinition.getType();
        Object fieldValue = values.get(fieldName);

        if (fieldType != Type.OBJECT) {
            fieldValue = checkAndCloneValue(fieldName, fieldType, fieldValue);
        }

        return fieldValue;
    }


    private boolean isFieldMandatoryAndMissing(IFieldDefinition fieldDefinition, Map<String, Object> values) {
        return fieldDefinition.isMandatory() && !values.containsKey(fieldDefinition.getName());
    }


    private Object checkAndCloneValue(String fieldName, Type type, Object fieldValue) {
        Object result = null;

        switch (type) {<commit_msg>manage missing mandatory field in class Entry<commit_after>package com.ubiquity.core.datastore;

import com.ubiquity.core.datastore.IFieldDefinition.Type;

import java.util.Collection;
import java.util.Map;

public class Entry {

    private final Object fields[];

    public Entry(IDataDefinition dataDefinition, Map<String, Object> values) {
        assert dataDefinition != null;
        assert values != null;

        Collection<IFieldDefinition> fieldDefinitions = dataDefinition.getFieldDefinitions();
        this.fields = new Object[fieldDefinitions.size()];
        populateFields(fieldDefinitions, values);
    }


    private void populateFields(Collection<IFieldDefinition> fieldDefinitions, Map<String, Object> values) {
        int index = 0;

        for (IFieldDefinition fieldDefinition : fieldDefinitions) {
            populateField(fieldDefinition, index++, values);
        }
    }


    private void populateField(IFieldDefinition fieldDefinition, int index, Map<String, Object> values) {

        if (isFieldMandatoryAndMissing(fieldDefinition, values)) {
            throw new IllegalArgumentException("field \"" + fieldDefinition.getName() + "\" is mandatory but is missing");
        }
        else {
            fields[index] = fieldValue(fieldDefinition, values);
        }
    }

    private Object fieldValue(IFieldDefinition fieldDefinition, Map<String, Object> values) {
        String fieldName = fieldDefinition.getName();
        Type fieldType = fieldDefinition.getType();
        Object fieldValue = values.get(fieldName);

        if (fieldType != Type.OBJECT) {
            fieldValue = checkAndCloneValue(fieldName, fieldType, fieldValue);
        }

        return fieldValue;
    }


    private boolean isFieldMandatoryAndMissing(IFieldDefinition fieldDefinition, Map<String, Object> values) {
        return fieldDefinition.isMandatory() && !values.containsKey(fieldDefinition.getName());
    }


    private Object checkAndCloneValue(String fieldName, Type type, Object fieldValue) {
        Object result = null;

        switch (type) {
{'fraction_non_alphanumeric': 0.09052683650754391, 'fraction_numerical': 0.0004946821667078902, 'mean_word_length': 3.2975557917109457, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3230549', 'n_tokens_mistral': 1049, 'n_tokens_neox': 997, 'n_words': 249}