<commit_before>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF 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.apache.jmeter.visualizers;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Image;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;

import org.apache.jmeter.samplers.Clearable;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jmeter.visualizers.gui.AbstractVisualizer;

/**
 * This class implements the visualizer for displaying the distribution graph.
 * Distribution graphs are useful for standard benchmarks and viewing the
 * distribution of data points. Results tend to clump together.
 *
 * Created May 25, 2004
 */
public class DistributionGraphVisualizer extends AbstractVisualizer implements ImageVisualizer, GraphListener,
        Clearable {
    private static final long serialVersionUID = 240L;

    private SamplingStatCalculator model;

    private JPanel graphPanel = null;

    private DistributionGraph graph;

    private JTextField noteField;

    private int delay = 10;

    private int counter = 0;

    /**
     * Constructor for the GraphVisualizer object.
     */
    public DistributionGraphVisualizer() {
        model = new SamplingStatCalculator("Distribution");
        graph = new DistributionGraph(model);
        graph.setBackground(Color.white);
        init();
    }

    /**
     * Gets the Image attribute of the GraphVisualizer object.
     *
     * @return the Image value
     */
    public Image getImage() {
        Image result = graph.createImage(graph.getWidth(), graph.getHeight());

        graph.paintComponent(result.getGraphics());

        return result;
    }

    public synchronized void updateGui() {
        if (graph.getWidth() < 10) {
            graph.setPreferredSize(new Dimension(getWidth() - 40, getHeight() - 160));
        }
        graphPanel.updateUI();
        graph.repaint();
    }

    public synchronized void updateGui(Sample s) {
        // We have received one more sample
        if (delay == counter) {
            updateGui();
            counter = 0;
        } else {
            counter++;
        }
    }

    public void add(final SampleResult res) {
        JMeterUtils.runSafe(new Runnable() {
            public void run() {
                // made currentSample volatile
                model.addSample(res);
                updateGui(model.getCurrentSample());                
            }
        });
    }<commit_msg>Make fields final Make field constant<commit_after>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF 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.apache.jmeter.visualizers;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Image;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;

import org.apache.jmeter.samplers.Clearable;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jmeter.visualizers.gui.AbstractVisualizer;

/**
 * This class implements the visualizer for displaying the distribution graph.
 * Distribution graphs are useful for standard benchmarks and viewing the
 * distribution of data points. Results tend to clump together.
 *
 * Created May 25, 2004
 */
public class DistributionGraphVisualizer extends AbstractVisualizer implements ImageVisualizer, GraphListener,
        Clearable {
    private static final long serialVersionUID = 240L;

    private final SamplingStatCalculator model;

    private JPanel graphPanel = null;

    private final DistributionGraph graph;

    private JTextField noteField;

    private static final int DELAY = 10;

    private int counter = 0;

    /**
     * Constructor for the GraphVisualizer object.
     */
    public DistributionGraphVisualizer() {
        model = new SamplingStatCalculator("Distribution");
        graph = new DistributionGraph(model);
        graph.setBackground(Color.white);
        init();
    }

    /**
     * Gets the Image attribute of the GraphVisualizer object.
     *
     * @return the Image value
     */
    public Image getImage() {
        Image result = graph.createImage(graph.getWidth(), graph.getHeight());

        graph.paintComponent(result.getGraphics());

        return result;
    }

    public synchronized void updateGui() {
        if (graph.getWidth() < 10) {
            graph.setPreferredSize(new Dimension(getWidth() - 40, getHeight() - 160));
        }
        graphPanel.updateUI();
        graph.repaint();
    }

    public synchronized void updateGui(Sample s) {
        // We have received one more sample
        if (DELAY == counter) {
            updateGui();
            counter = 0;
        } else {
            counter++;
        }
    }

    public void add(final SampleResult res) {
        JMeterUtils.runSafe(new Runnable() {
            public void run() {
                // made currentSample volatile
                model.addSample(res);
                updateGui(model.getCurrentSample());                
            }
        });
    }
{'fraction_non_alphanumeric': 0.08310954063604241, 'fraction_numerical': 0.006784452296819788, 'mean_word_length': 2.9180509413067552, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2656459', 'n_tokens_mistral': 1879, 'n_tokens_neox': 1776, 'n_words': 619}