<commit_before>/* Copyright 2002-2021 CS GROUP
 * Licensed to CS GROUP (CS) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * CS licenses this file to You 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 org.orekit.files.ccsds.utils.generation;

import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Locale;

import org.orekit.errors.OrekitException;
import org.orekit.errors.OrekitMessages;
import org.orekit.files.ccsds.ndm.adm.aem.AEMFile;
import org.orekit.files.ccsds.section.CommentsContainer;
import org.orekit.files.ccsds.utils.lexical.FileFormat;

/** Generator for Key-Value Notation CCSDS messages.
 * @author <NAME>
 * @since 11.0
 */
public class KVNGenerator implements Generator {

    /**
     * Standardized locale to use, to ensure files can be exchanged without
     * internationalization issues.
     */
    private static final Locale STANDARDIZED_LOCALE = Locale.US;

    /** String format used for all key/value pair lines. **/
    private static final String KV_FORMAT = "%s = %s%n";

    /** String format used for all comment lines. **/
    private static final String COMMENT_FORMAT = "COMMENT %s%n";

    /** Start suffix for sections. */
    private static final String START = "_START";

    /** Stop suffix for sections. */
    private static final String STOP = "_STOP";

    /** New line separator for output file. */
    private static final char NEW_LINE = '\n';

    /** Destination of generated output. */
    private final Appendable output;

    /** File name for error messages. */
    private final String fileName;

    /** Sections stack. */
    private final Deque<String> sections;

    /** Simple constructor.
     * @param output destination of generated output
     * @param fileName file name for error messages
     */
    public KVNGenerator(final Appendable output, final String fileName) {
        this.output   = output;
        this.fileName = fileName;
        this.sections = new ArrayDeque<>();
    }

    /** {@inheritDoc} */
    @Override
    public FileFormat getFormat() {
        return FileFormat.KVN;
    }

    /** {@inheritDoc} */
    @Override
    public void startMessage(final String messageTypeKey, final double version) throws IOException {
        writeEntry(AEMFile.FORMAT_VERSION_KEY, String.format(STANDARDIZED_LOCALE, "%.1f", version), true);
    }

    /** {@inheritDoc} */
    @Override
    public void close() throws IOException {
        // nothing to do
    }

    /** {@inheritDoc} */
    @Override
    public void writeComments(final CommentsContainer comments) throws IOException {
        for (final String comment : comments.getComments()) {
            output.append(String.format(STANDARDIZED_LOCALE, COMMENT_FORMAT, comment));
        }
    }

    /** {@inheritDoc} */
    @Override
    public void writeEntry(final String key, final String value, final boolean mandatory) throws IOException {<commit_msg>Fixed key name error.<commit_after>/* Copyright 2002-2021 CS GROUP
 * Licensed to CS GROUP (CS) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * CS licenses this file to You 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 org.orekit.files.ccsds.utils.generation;

import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Locale;

import org.orekit.errors.OrekitException;
import org.orekit.errors.OrekitMessages;
import org.orekit.files.ccsds.section.CommentsContainer;
import org.orekit.files.ccsds.utils.lexical.FileFormat;

/** Generator for Key-Value Notation CCSDS messages.
 * @author <NAME>
 * @since 11.0
 */
public class KVNGenerator implements Generator {

    /**
     * Standardized locale to use, to ensure files can be exchanged without
     * internationalization issues.
     */
    private static final Locale STANDARDIZED_LOCALE = Locale.US;

    /** String format used for all key/value pair lines. **/
    private static final String KV_FORMAT = "%s = %s%n";

    /** String format used for all comment lines. **/
    private static final String COMMENT_FORMAT = "COMMENT %s%n";

    /** Start suffix for sections. */
    private static final String START = "_START";

    /** Stop suffix for sections. */
    private static final String STOP = "_STOP";

    /** New line separator for output file. */
    private static final char NEW_LINE = '\n';

    /** Destination of generated output. */
    private final Appendable output;

    /** File name for error messages. */
    private final String fileName;

    /** Sections stack. */
    private final Deque<String> sections;

    /** Simple constructor.
     * @param output destination of generated output
     * @param fileName file name for error messages
     */
    public KVNGenerator(final Appendable output, final String fileName) {
        this.output   = output;
        this.fileName = fileName;
        this.sections = new ArrayDeque<>();
    }

    /** {@inheritDoc} */
    @Override
    public FileFormat getFormat() {
        return FileFormat.KVN;
    }

    /** {@inheritDoc} */
    @Override
    public void startMessage(final String messageTypeKey, final double version) throws IOException {
        writeEntry(messageTypeKey, String.format(STANDARDIZED_LOCALE, "%.1f", version), true);
    }

    /** {@inheritDoc} */
    @Override
    public void close() throws IOException {
        // nothing to do
    }

    /** {@inheritDoc} */
    @Override
    public void writeComments(final CommentsContainer comments) throws IOException {
        for (final String comment : comments.getComments()) {
            output.append(String.format(STANDARDIZED_LOCALE, COMMENT_FORMAT, comment));
        }
    }

    /** {@inheritDoc} */
    @Override
    public void writeEntry(final String key, final String value, final boolean mandatory) throws IOException {
{'fraction_non_alphanumeric': 0.09455060155697098, 'fraction_numerical': 0.004529370134465676, 'mean_word_length': 3.183540556542333, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6001612', 'n_tokens_mistral': 1932, 'n_tokens_neox': 1854, 'n_words': 695}