<commit_before>/*******************************************************************************
 * Copyright (c) 2010 Oak Ridge National Laboratory.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 ******************************************************************************/
package org.csstudio.opibuilder.converter.model;

import java.util.Iterator;
import java.util.Vector;

/**
 * Generic data container for Edm object's properties and its values.
 * Base class for all specific Edm properties.
 *
 * @author Matevz
 *
 */
public class EdmAttribute {

    private Vector<String>    values;

    private boolean required;
    private boolean initialized;
    private boolean isExistInEDl;

    private void initDefaultValues() {
        values = new Vector<String>();
        required = true;
        initialized = false;
    }

    /**
     * Empty constructor. Does not assign any values.
     */
    public EdmAttribute() {
        initDefaultValues();
    }

    /**
     * Constructor, which appends one value.
     * @param firstValue Value to append.
     */
    public EdmAttribute(String firstValue) {
        initDefaultValues();
        appendValue(firstValue);
    }

    /**
     * Constructs an instance of EdmAttribute from data of another EdmAttribute instance.
     * @param genericAttribute EdmAttribute to copy.
     */
    public EdmAttribute(EdmAttribute genericAttribute) throws EdmException {

        if(genericAttribute!=null)
            isExistInEDl=true;
        // Multiple specializations test.
        if (genericAttribute != null && !genericAttribute.getClass().equals(EdmAttribute.class)) {
            throw new EdmException(EdmException.SPECIFIC_PARSING_ERROR,
            "Trying to initialize from an already specialized attribute.", null);
        }

        initDefaultValues();

        if (genericAttribute != null) {
            int valCount = genericAttribute.getValueCount();
            for (int i = 0; i < valCount; i++)
                appendValue(genericAttribute.getValue(i));
        }
    }

    /**
     * Returns the value of attribute at specified index.
     * @param index        Index of desired value.
     * @return            Value of attribute.
     */
    public String getValue(int index) {
        return values.get(index);
    }

    /**
     * Returns the number of values in attribute.
     * @return    The number of values.
     */
    public int getValueCount() {
        return values.size();
    }

    /**
     * Appends the value at the end of the attribute.
     * Omits all quotation marks and returns this value back
     * (used for logging).
     *
     * @param value    Value to append.
     * @return        Actual value appended (without quotations).
     */
    public String appendValue(String value) {
        if(value.startsWith("\"")&&value.endsWith("\"")){
            if(value.length() <3)
                System.out.println(value);
            value=value.substring(1, value.length()-1);
        }

        value = value.replaceAll("\\\\\"", "\"");
        values.add(value);
        return value;
    }

    public boolean isRequired() {
        return required;
    }

    public boolean isInitialized() {
        return initialized;
    }

    public boolean isExistInEDL(){
        return isExistInEDl;
    }

    @Override
    public String toString() {<commit_msg>o.c.o.converter: remove rogue print statement<commit_after>/*******************************************************************************
 * Copyright (c) 2010 Oak Ridge National Laboratory.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 ******************************************************************************/
package org.csstudio.opibuilder.converter.model;

import java.util.Iterator;
import java.util.Vector;

/**
 * Generic data container for Edm object's properties and its values.
 * Base class for all specific Edm properties.
 *
 * @author Matevz
 *
 */
public class EdmAttribute {

    private Vector<String>    values;

    private boolean required;
    private boolean initialized;
    private boolean isExistInEDl;

    private void initDefaultValues() {
        values = new Vector<String>();
        required = true;
        initialized = false;
    }

    /**
     * Empty constructor. Does not assign any values.
     */
    public EdmAttribute() {
        initDefaultValues();
    }

    /**
     * Constructor, which appends one value.
     * @param firstValue Value to append.
     */
    public EdmAttribute(String firstValue) {
        initDefaultValues();
        appendValue(firstValue);
    }

    /**
     * Constructs an instance of EdmAttribute from data of another EdmAttribute instance.
     * @param genericAttribute EdmAttribute to copy.
     */
    public EdmAttribute(EdmAttribute genericAttribute) throws EdmException {

        if(genericAttribute!=null)
            isExistInEDl=true;
        // Multiple specializations test.
        if (genericAttribute != null && !genericAttribute.getClass().equals(EdmAttribute.class)) {
            throw new EdmException(EdmException.SPECIFIC_PARSING_ERROR,
            "Trying to initialize from an already specialized attribute.", null);
        }

        initDefaultValues();

        if (genericAttribute != null) {
            int valCount = genericAttribute.getValueCount();
            for (int i = 0; i < valCount; i++)
                appendValue(genericAttribute.getValue(i));
        }
    }

    /**
     * Returns the value of attribute at specified index.
     * @param index        Index of desired value.
     * @return            Value of attribute.
     */
    public String getValue(int index) {
        return values.get(index);
    }

    /**
     * Returns the number of values in attribute.
     * @return    The number of values.
     */
    public int getValueCount() {
        return values.size();
    }

    /**
     * Appends the value at the end of the attribute.
     * Omits all quotation marks and returns this value back
     * (used for logging).
     *
     * @param value    Value to append.
     * @return        Actual value appended (without quotations).
     */
    public String appendValue(String value) {
        if(value.startsWith("\"")&&value.endsWith("\"")){
            value=value.substring(1, value.length()-1);
        }

        value = value.replaceAll("\\\\\"", "\"");
        values.add(value);
        return value;
    }

    public boolean isRequired() {
        return required;
    }

    public boolean isInitialized() {
        return initialized;
    }

    public boolean isExistInEDL(){
        return isExistInEDl;
    }

    @Override
    public String toString() {
{'fraction_non_alphanumeric': 0.13648553281580805, 'fraction_numerical': 0.0032462949894142556, 'mean_word_length': 2.4498539435248294, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 7, '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': '2504325', 'n_tokens_mistral': 1852, 'n_tokens_neox': 1775, 'n_words': 555}