<commit_before>/*
 * Copyright 2009-2016 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 eu.qualimaster.adaptation;

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

import eu.qualimaster.adaptation.events.AlgorithmConfigurationAdaptationEvent;
import eu.qualimaster.adaptation.events.CheckBeforeStartupAdaptationEvent;
import eu.qualimaster.adaptation.events.ParameterConfigurationAdaptationEvent;
import eu.qualimaster.adaptation.events.ReplayAdaptationEvent;
import eu.qualimaster.adaptation.events.SourceVolumeAdaptationEvent;
import eu.qualimaster.adaptation.events.StartupAdaptationEvent;
import eu.qualimaster.adaptation.external.InformationMessage;
import eu.qualimaster.events.IEvent;
import eu.qualimaster.monitoring.events.ConstraintViolationAdaptationEvent;
import eu.qualimaster.monitoring.events.ViolatingClause;

/**
 * Turns adaptation events into information messages.
 * 
 * @author <NAME>
 */
public class AdaptationEventInformationMessageConverter {
    
    /**
     * A message converter.
     * 
     * @param <E> the event type
     * @author <NAME>
     */
    public abstract static class MessageConverter <E extends IEvent> {
        
        private Class<E> eventClass;
        
        /**
         * Creates a message converter.
         * 
         * @param cls event class
         */
        protected MessageConverter(Class<E> cls) {
            this.eventClass = cls;
        }

        /**
         * Returns the event class.
         * 
         * @return the event class
         */
        public Class<E> eventClass() {
            return eventClass;
        }

        /**
         * Converts the event.
         * 
         * @param event the event
         * @return the message, may be <b>null</b> for no conversion
         */
        InformationMessage toMessage(IEvent event) {
            InformationMessage result = null;
            if (eventClass.isInstance(event)) {
                result = convert(eventClass.cast(event));
            }
            return result;
        }
        
        /**
         * Converts the event.
         * 
         * @param event the event
         * @return the message, may be <b>null</b> for no conversion
         */
        protected abstract InformationMessage convert(E event);
        
    }
    
    private static final MessageConverter<SourceVolumeAdaptationEvent> SOURCE_VOLUME_CONVERTER 
        = new MessageConverter<SourceVolumeAdaptationEvent>(SourceVolumeAdaptationEvent.class) {

            @Override
            protected InformationMessage convert(SourceVolumeAdaptationEvent event) {
                return new InformationMessage(event.getPipeline(), event.getSource(), 
                     "source volume findings: " + event.getNormalizedFindings());
            }
            
        };

    private static final MessageConverter<CheckBeforeStartupAdaptationEvent> CHECK_STARTUP_CONVERTER 
        = new MessageConverter<CheckBeforeStartupAdaptationEvent>(CheckBeforeStartupAdaptationEvent.class) {

            @Override
            protected InformationMessage convert(CheckBeforeStartupAdaptationEvent event) {<commit_msg>extended message converter for source volume<commit_after>/*
 * Copyright 2009-2016 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 eu.qualimaster.adaptation;

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

import eu.qualimaster.adaptation.events.AlgorithmConfigurationAdaptationEvent;
import eu.qualimaster.adaptation.events.CheckBeforeStartupAdaptationEvent;
import eu.qualimaster.adaptation.events.ParameterConfigurationAdaptationEvent;
import eu.qualimaster.adaptation.events.ReplayAdaptationEvent;
import eu.qualimaster.adaptation.events.SourceVolumeAdaptationEvent;
import eu.qualimaster.adaptation.events.StartupAdaptationEvent;
import eu.qualimaster.adaptation.external.InformationMessage;
import eu.qualimaster.events.IEvent;
import eu.qualimaster.monitoring.events.ConstraintViolationAdaptationEvent;
import eu.qualimaster.monitoring.events.ViolatingClause;

/**
 * Turns adaptation events into information messages.
 * 
 * @author <NAME>
 */
public class AdaptationEventInformationMessageConverter {
    
    /**
     * A message converter.
     * 
     * @param <E> the event type
     * @author <NAME>
     */
    public abstract static class MessageConverter <E extends IEvent> {
        
        private Class<E> eventClass;
        
        /**
         * Creates a message converter.
         * 
         * @param cls event class
         */
        protected MessageConverter(Class<E> cls) {
            this.eventClass = cls;
        }

        /**
         * Returns the event class.
         * 
         * @return the event class
         */
        public Class<E> eventClass() {
            return eventClass;
        }

        /**
         * Converts the event.
         * 
         * @param event the event
         * @return the message, may be <b>null</b> for no conversion
         */
        InformationMessage toMessage(IEvent event) {
            InformationMessage result = null;
            if (eventClass.isInstance(event)) {
                result = convert(eventClass.cast(event));
            }
            return result;
        }
        
        /**
         * Converts the event.
         * 
         * @param event the event
         * @return the message, may be <b>null</b> for no conversion
         */
        protected abstract InformationMessage convert(E event);
        
    }
    
    private static final MessageConverter<SourceVolumeAdaptationEvent> SOURCE_VOLUME_CONVERTER 
        = new MessageConverter<SourceVolumeAdaptationEvent>(SourceVolumeAdaptationEvent.class) {

            @Override
            protected InformationMessage convert(SourceVolumeAdaptationEvent event) {
                return new InformationMessage(event.getPipeline(), event.getSource(), 
                     "source volume, normalized findings: " + event.getNormalizedFindings() + " findings: " 
                     + event.getFindings() + " volumes: " + event.getVolumes() + " predictions: " 
                     + event.getPredictions() + " thresholds: " + event.getThresholds());
            }
            
        };

    private static final MessageConverter<CheckBeforeStartupAdaptationEvent> CHECK_STARTUP_CONVERTER 
        = new MessageConverter<CheckBeforeStartupAdaptationEvent>(CheckBeforeStartupAdaptationEvent.class) {

            @Override
            protected InformationMessage convert(CheckBeforeStartupAdaptationEvent event) {
{'fraction_non_alphanumeric': 0.07802527028787287, 'fraction_numerical': 0.0031262211801484957, 'mean_word_length': 2.626830420406235, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, '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': '6444931', 'n_tokens_mistral': 1993, 'n_tokens_neox': 1921, 'n_words': 518}