<commit_before>/*
 * Copyright 2009-2015 University of Hildesheim, Software Systems Engineering
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.uni_hildesheim.sse.model.varModel.values;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import de.uni_hildesheim.sse.model.cst.ConstraintSyntaxTree;
import de.uni_hildesheim.sse.model.varModel.AttributeAssignment;
import de.uni_hildesheim.sse.model.varModel.DecisionVariableDeclaration;
import de.uni_hildesheim.sse.model.varModel.IDecisionVariableContainer;
import de.uni_hildesheim.sse.model.varModel.datatypes.Compound;
import de.uni_hildesheim.sse.model.varModel.datatypes.IDatatype;

/**
 * CompoundValue class.
 * @author <NAME>
 * @author El-Sharkawy
 * @author <NAME>
 */
public class CompoundValue extends StructuredValue implements Cloneable {

    /**
     * Denotes an internal compound slot name during initialization which 
     * specifies the actual type of the compound (in case of container initializations
     * defined on a refined compound).
     */
    public static final String SPECIAL_SLOT_NAME_TYPE = ".";
    
    private HashMap<String, Value> nestedElements;
    
    /**
     * Constructor for a new CompoundValue.
     * @param compound compound which extends this CompoundValue
     * @throws ValueDoesNotMatchTypeException if one of the default values do not comply
     *   to the respective types
     */
    CompoundValue(Compound compound) throws ValueDoesNotMatchTypeException {
        this(compound, (Object[]) null);        
    }

    /**
     * Constructor for a new CompoundValue.
     * @param compound compound which extends this CompoundValue
     * @param value initial value(s), two entries for each compound given as name and value
     * @throws ValueDoesNotMatchTypeException if one of the default values do not comply
     *   to the respective types
     */
    CompoundValue(Compound compound, Object... value) throws ValueDoesNotMatchTypeException {
        super(compound);
        nestedElements = new HashMap<String, Value>();
        if (null != value && value.length % 2 != 0) {
            throw new ValueDoesNotMatchTypeException("amount of slot names and values does not match", 
                this, ValueDoesNotMatchTypeException.SLOT_MISMATCH);
        }
        Map<String, Object> initialValues = new HashMap<String, Object>();
        if (null != value) {
            for (int v = 0; v < value.length; v += 2) {
                String slotName = value[v].toString();
                if (!slotName.equals(SPECIAL_SLOT_NAME_TYPE)) {
                    initialValues.put(slotName, value[v + 1]);
                }
            }
        }
        initialize(compound, initialValues);
        for (int a = 0; a < compound.getAssignmentCount(); a++) {
            initializeAttributeAssignment(compound.getAssignment(a), initialValues);
        }
    }

    /**
     * Creates a new compound value by copying the values from <code>source</code>.
     * <commit_msg>fixing compound value incompatibility message <commit_after>/*
 * Copyright 2009-2015 University of Hildesheim, Software Systems Engineering
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.uni_hildesheim.sse.model.varModel.values;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import de.uni_hildesheim.sse.model.cst.ConstraintSyntaxTree;
import de.uni_hildesheim.sse.model.varModel.AttributeAssignment;
import de.uni_hildesheim.sse.model.varModel.DecisionVariableDeclaration;
import de.uni_hildesheim.sse.model.varModel.IDecisionVariableContainer;
import de.uni_hildesheim.sse.model.varModel.datatypes.Compound;
import de.uni_hildesheim.sse.model.varModel.datatypes.IDatatype;

/**
 * CompoundValue class.
 * @author <NAME>
 * @author El-Sharkawy
 * @author <NAME>
 */
public class CompoundValue extends StructuredValue implements Cloneable {

    /**
     * Denotes an internal compound slot name during initialization which 
     * specifies the actual type of the compound (in case of container initializations
     * defined on a refined compound).
     */
    public static final String SPECIAL_SLOT_NAME_TYPE = ".";
    
    private HashMap<String, Value> nestedElements;
    
    /**
     * Constructor for a new CompoundValue.
     * @param compound compound which extends this CompoundValue
     * @throws ValueDoesNotMatchTypeException if one of the default values do not comply
     *   to the respective types
     */
    CompoundValue(Compound compound) throws ValueDoesNotMatchTypeException {
        this(compound, (Object[]) null);        
    }

    /**
     * Constructor for a new CompoundValue.
     * @param compound compound which extends this CompoundValue
     * @param value initial value(s), two entries for each compound given as name and value
     * @throws ValueDoesNotMatchTypeException if one of the default values do not comply
     *   to the respective types
     */
    CompoundValue(Compound compound, Object... value) throws ValueDoesNotMatchTypeException {
        super(compound);
        nestedElements = new HashMap<String, Value>();
        if (null != value && value.length % 2 != 0) {
            throw new ValueDoesNotMatchTypeException("amount of slot names and values does not match for type" 
                + compound.getType().getName(), ValueDoesNotMatchTypeException.SLOT_MISMATCH);
        }
        Map<String, Object> initialValues = new HashMap<String, Object>();
        if (null != value) {
            for (int v = 0; v < value.length; v += 2) {
                String slotName = value[v].toString();
                if (!slotName.equals(SPECIAL_SLOT_NAME_TYPE)) {
                    initialValues.put(slotName, value[v + 1]);
                }
            }
        }
        initialize(compound, initialValues);
        for (int a = 0; a < compound.getAssignmentCount(); a++) {
            initializeAttributeAssignment(compound.getAssignment(a), initialValues);
        }
    }

    /**
     * Creates a new compound value by copying the values from <code>source</code>.
     * 
{'fraction_non_alphanumeric': 0.08556599803619021, 'fraction_numerical': 0.005049796605414504, 'mean_word_length': 3.1000575043128236, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7325352', 'n_tokens_mistral': 1950, 'n_tokens_neox': 1892, 'n_words': 625}