<commit_before>package org.csstudio.trends.databrowser.sampleview;

import java.util.ArrayList;

import org.csstudio.platform.data.ITimestamp;
import org.csstudio.swt.chart.ChartSampleSearch;
import org.csstudio.trends.databrowser.model.IModelItem;
import org.csstudio.trends.databrowser.model.IModelSamples;
import org.csstudio.trends.databrowser.model.Model;
import org.csstudio.trends.databrowser.model.ModelSample;

/** Model of the sample table.
 *  <p>
 *  Keeps a copy of the <u>visible</u> samples in the data browser model.
 *  <p>
 *  Alternatively, it could keep a reference to the model and its
 *  first/last visible sample index, then use a model listener to
 *  re-evalutate the visible range on model changes, and even
 *  update the table.
 *  But table updates are surprisingly expensive, and keeping an array
 *  of value references (not whole value copies) looked acceptable for now.
 *  
 *  @author <NAME>
 */
public class TableModel
{
    /** Name of the PV that provided the data. */
    final private String name;
    
    /** References to all the visible model samples. */
    final private ArrayList<ModelSample> samples =
        new ArrayList<ModelSample>();

    /** Constructor */
    TableModel(Model model, IModelItem item)
    {
        name = item.getName();
        final IModelSamples all_samples = item.getSamples();
        synchronized (all_samples)
        {
            final ITimestamp start = model.getStartTime();
            final ITimestamp end = model.getEndTime();
            
            final int start_index =
                ChartSampleSearch.findClosestSample(all_samples, start.toDouble());
            final int end_index =
                ChartSampleSearch.findClosestSample(all_samples, end.toDouble());
            if (start_index >= 0  &&  end_index >= 0)
                for (int i=start_index; i<=end_index; ++i)
                    samples.add(all_samples.get(i));
        }
    }
    
    /** @return Name of the PV */
    String getName()
    {   return name; }
    
    /** @return The number of samples in the table. */
    int size()
    {   return samples.size();   }

    /** @return Sample in given row. */
    @SuppressWarnings("nls")
    ModelSample getSample(final int row)
    {
        return samples.get(row);
    }
    
    /** @return TableItem for given row. */
    @SuppressWarnings("nls")
    TableItem getTableItem(int row)
    {
        return new TableItem(this, row);
    }
}
<commit_msg>comments<commit_after>package org.csstudio.trends.databrowser.sampleview;

import java.util.ArrayList;

import org.csstudio.platform.data.ITimestamp;
import org.csstudio.swt.chart.ChartSampleSearch;
import org.csstudio.trends.databrowser.model.IModelItem;
import org.csstudio.trends.databrowser.model.IModelSamples;
import org.csstudio.trends.databrowser.model.Model;
import org.csstudio.trends.databrowser.model.ModelSample;

/** Model of the sample table.
 *  <p>
 *  Keeps a copy of the <u>visible</u> samples in the data browser model.
 *  <p>
 *  Alternatively, it could keep a reference to the model and its
 *  first/last visible sample index, then use a model listener to
 *  re-evalutate the visible range on model changes, and even
 *  update the table.
 *  But table updates are surprisingly expensive, and keeping an array
 *  of value references (not whole value copies) looked acceptable for now.
 *  
 *  @author <NAME>
 */
public class TableModel
{
    /** Name of the PV that provided the data. */
    final private String name;
    
    /** References to all the visible model samples. */
    final private ArrayList<ModelSample> samples =
        new ArrayList<ModelSample>();

    /** Constructor */
    TableModel(final Model model, final IModelItem item)
    {
        name = item.getName();
        final IModelSamples all_samples = item.getSamples();
        synchronized (all_samples)
        {
        	// Determine visible start/end range
            final ITimestamp start = model.getStartTime();
            final ITimestamp end = model.getEndTime();
            final int start_index =
                ChartSampleSearch.findClosestSample(all_samples, start.toDouble());
            final int end_index =
                ChartSampleSearch.findClosestSample(all_samples, end.toDouble());
            // Get array of all those references
            if (start_index >= 0  &&  end_index >= 0)
            {
            	samples.ensureCapacity(end_index - start_index + 1);
            	for (int i=start_index; i<=end_index; ++i)
                    samples.add(all_samples.get(i));
            }
        }
    }
    
    /** @return Name of the PV */
    String getName()
    {   return name; }
    
    /** @return The number of samples in the table. */
    int size()
    {   return samples.size();   }

    /** @return Sample in given row. */
    @SuppressWarnings("nls")
    ModelSample getSample(final int row)
    {
        return samples.get(row);
    }
    
    /** @return TableItem for given row. */
    @SuppressWarnings("nls")
    TableItem getTableItem(int row)
    {
        return new TableItem(this, row);
    }
}

{'fraction_non_alphanumeric': 0.09996102883865939, 'fraction_numerical': 0.0009742790335151987, 'mean_word_length': 2.5375603032391454, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2568068', 'n_tokens_mistral': 1510, 'n_tokens_neox': 1470, 'n_words': 429}