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

kg.apc.jmeter.vizualizers.CompositeModel Maven / Gradle / Ivy

There is a newer version: 0.7
Show newest version
package kg.apc.jmeter.vizualizers;

import java.io.Serializable;
import java.util.Iterator;
import java.util.concurrent.ConcurrentSkipListMap;
import kg.apc.charting.AbstractGraphRow;
import kg.apc.jmeter.graphs.CompositeNotifierInterface;

public class CompositeModel implements Serializable {

    private ConcurrentSkipListMap> models = null;
    private Iterator emptyIterator = null;
    private CompositeNotifierInterface notifier = null;

    public CompositeModel() {
        models = new ConcurrentSkipListMap<>();
    }

    //needed to refresh tree if row model changed
    public void setNotifier(CompositeNotifierInterface notifier) {
        this.notifier = notifier;
    }

    public void clear() {
        models.clear();
    }

    private synchronized ConcurrentSkipListMap getRowsMap(String vizualizerName) {
        ConcurrentSkipListMap rows = models.get(vizualizerName);
        if (rows == null) {
            rows = new ConcurrentSkipListMap<>();
            models.put(vizualizerName, rows);
        }
        return rows;
    }

    public void addRow(String vizualizerName, AbstractGraphRow row) {
        ConcurrentSkipListMap rows = models.get(vizualizerName);
        if (rows == null) {
            rows = getRowsMap(vizualizerName);
        }
        rows.put(row.getLabel(), row);
        notifier.refresh();
    }

    public void clearRows(String vizualizerName) {
        models.remove(vizualizerName);
        notifier.refresh();
    }

    public boolean containsVisualizer(String vizualizerName) {
        return models.containsKey(vizualizerName);
    }

    public Iterator getVizualizerNamesIterator() {
        return models.keySet().iterator();
    }

    public Iterator getRowsIterator(String vizualizerName) {
        ConcurrentSkipListMap rows = models.get(vizualizerName);
        if (rows != null) {
            return rows.values().iterator();
        } else {
            if (emptyIterator == null) {
                emptyIterator = new ConcurrentSkipListMap().values().iterator();
            }
            return emptyIterator;
        }
    }

    public AbstractGraphRow getRow(String testName, String rowName) {
        ConcurrentSkipListMap rows = models.get(testName);
        if (rows != null) {
            return models.get(testName).get(rowName);
        } else {
            return null;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy