All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.perfana.event.PerfanaEventProperties Maven / Gradle / Ivy

There is a newer version: 3.0.1
Show newest version
package io.perfana.event;

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

/**
 * Store event properties per PerfanaTestEvent implementation class.
 * Uses getClass().getCanonicalName() so innerclasses will use . instead of $ as name separator.
 * $ can not be used in most situation, like in xml element name (e.g. maven pom.xml).
 */
public class PerfanaEventProperties {
    private Map> eventProperties = new HashMap<>();

    public Map get(PerfanaTestEvent event) {
        return eventProperties.getOrDefault(event.getClass().getCanonicalName(), Collections.emptyMap());
    }

    public PerfanaEventProperties put(PerfanaTestEvent event, String name, String value) {
        String classImplName = event.getClass().getCanonicalName();
        put(classImplName, name, value);
        return this;
    }

    public PerfanaEventProperties put(String eventClassImplName, String name, String value) {
        if (eventProperties.containsKey(eventClassImplName)) {
            eventProperties.get(eventClassImplName).put(name, value);
        }
        else {
            Map properties = new HashMap<>();
            properties.put(name, value);
            eventProperties.put(eventClassImplName, properties);
        }
        return this;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy