<commit_before>package hudson.plugins.cobertura.targets;

import gnu.trove.iterator.TIntObjectIterator;
import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.hash.TIntObjectHashMap;
import hudson.plugins.cobertura.Ratio;

import java.io.Serializable;
import java.util.EnumMap;
import java.util.Map;

/**
 * Line-by-line coverage information.
 *
 * @author <NAME>
 * @since 29-Aug-2007 17:44:29
 */
public class CoveragePaint implements Serializable {
	
	/**
	 * Generated
	 */
	private static final long serialVersionUID = -6265259191856193735L;

    private static final CoveragePaintDetails[] EMPTY = new CoveragePaintDetails[0];

	private static class CoveragePaintDetails implements Serializable {
		/**
		 * Generated
		 */
		private static final long serialVersionUID = -9097537016381444671L;
		int hitCount=0;
		int branchCount=0;
		int branchCoverage=0;
		
		CoveragePaintDetails(int hitCount, int branchCount, int branchCoverage) {
			this.hitCount = hitCount;
			this.branchCount = branchCount;
			this.branchCoverage = branchCoverage;
		}
	}

	protected TIntObjectMap<CoveragePaintDetails> lines=new TIntObjectHashMap<CoveragePaintDetails>();
	
	public CoveragePaint(CoverageElement source) {
//		there were no getters against the source ...
//      this.source = source;
    }
    
    public void paint(int line, int hits) {
    	CoveragePaintDetails d=lines.get(line);    		
    	if (d==null){
    		d=new CoveragePaintDetails(0, 0, 0);
    		lines.put(line, d);
    	}
		d.hitCount+=hits;
    }

    public void paint(int line, int hits, int branchCover, int branchCount) {
    	CoveragePaintDetails d=lines.get(line);    		
    	if (d==null){
    		d=new CoveragePaintDetails(hits, branchCount, branchCover);
    		lines.put(line, d);
    	} else {    		
    		d.hitCount+=hits;
            if (d.branchCount == 0) {
                d.branchCount = branchCount;
                d.branchCoverage = branchCover;
            } else {
                // TODO find a better algorithm
                d.branchCount = Math.max(d.branchCount, branchCount);
                d.branchCoverage = Math.max(d.branchCoverage, branchCover);
            }
    	}
    }

    public void add(CoveragePaint child) {
        TIntObjectIterator<CoveragePaintDetails> it = child.lines.iterator();
        while (it.hasNext()) {
            it.advance();
			CoveragePaintDetails d=lines.get(it.key());
			if (d!=null){
				d.hitCount+=it.value().hitCount;
				d.branchCount=Math.max(d.branchCount, it.value().branchCount);
				if (d.branchCount!=0){
					d.branchCoverage=Math.max(d.branchCoverage, it.value().branchCoverage);
				}
			} else {
				CoveragePaintDetails dc=it.value();
				d=new CoveragePaintDetails(dc.hitCount, dc.branchCount, dc.branchCoverage);
				lines.put(it.key(), d);
			}    		
    	}
    }

    /**
     * Getter for property 'lineCoverage'.
     *
     * @return Value for property 'lineCoverage'.
     */
    public Ratio getLineCoverage() {
        int covered = 0;
        for (CoveragePaintDetails d: lines.values(EMPTY)) {
            if (d.hitCount > 0) {
                covered++;
            }        		
        }
        return Ratio.create(covered, lines.size());
    }

    /**
     * Getter for property 'conditionalCoverage'.
     *
     * @return Value for property 'conditionalCoverage'.
     */
    public Ratio getConditionalCoverage() {
        long maxTotal = 0;<commit_msg>CoveragePaintDetails is made immutable in preparation for the flyweight pattern<commit_after>package hudson.plugins.cobertura.targets;

import gnu.trove.iterator.TIntObjectIterator;
import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.hash.TIntObjectHashMap;
import hudson.plugins.cobertura.Ratio;

import java.io.Serializable;
import java.util.EnumMap;
import java.util.Map;

/**
 * Line-by-line coverage information.
 *
 * @author <NAME>
 * @since 29-Aug-2007 17:44:29
 */
public class CoveragePaint implements Serializable {
	
	/**
	 * Generated
	 */
	private static final long serialVersionUID = -6265259191856193735L;

    private static final CoveragePaintDetails[] EMPTY = new CoveragePaintDetails[0];

	private static class CoveragePaintDetails implements Serializable {
		/**
		 * Generated
		 */
		private static final long serialVersionUID = -9097537016381444671L;

		final int hitCount;
        final int branchCount;
        final int branchCoverage;

		CoveragePaintDetails(int hitCount, int branchCount, int branchCoverage) {
			this.hitCount = hitCount;
			this.branchCount = branchCount;
			this.branchCoverage = branchCoverage;
		}

        CoveragePaintDetails add(CoveragePaintDetails that) {
            return new CoveragePaintDetails(
                    this.hitCount+that.hitCount,
                    // TODO find a better algorithm
                    Math.max(this.branchCount,that.branchCount),
                    Math.max(this.branchCoverage,that.branchCoverage)
            );
        }
	}

	protected TIntObjectMap<CoveragePaintDetails> lines=new TIntObjectHashMap<CoveragePaintDetails>();
	
	public CoveragePaint(CoverageElement source) {
//		there were no getters against the source ...
//      this.source = source;
    }
    
    private void paint(int line, CoveragePaintDetails delta) {
        CoveragePaintDetails d = lines.get(line);
        if (d == null) {
            lines.put(line, delta);
        } else {
            lines.put(line, d.add(delta));
        }
    }

    public void paint(int line, int hits) {
        paint(line, new CoveragePaintDetails(hits, 0, 0));
    }

    public void paint(int line, int hits, int branchCover, int branchCount) {
        paint(line,new CoveragePaintDetails(hits, branchCount, branchCover));
    }

    public void add(CoveragePaint child) {
        TIntObjectIterator<CoveragePaintDetails> it = child.lines.iterator();
        while (it.hasNext()) {
            it.advance();
            paint(it.key(),it.value());
    	}
    }

    /**
     * Getter for property 'lineCoverage'.
     *
     * @return Value for property 'lineCoverage'.
     */
    public Ratio getLineCoverage() {
        int covered = 0;
        for (CoveragePaintDetails d: lines.values(EMPTY)) {
            if (d.hitCount > 0) {
                covered++;
            }        		
        }
        return Ratio.create(covered, lines.size());
    }

    /**
     * Getter for property 'conditionalCoverage'.
     *
     * @return Value for property 'conditionalCoverage'.
     */
    public Ratio getConditionalCoverage() {
        long maxTotal = 0;
{'fraction_non_alphanumeric': 0.10593998775260258, 'fraction_numerical': 0.018064911206368647, 'mean_word_length': 2.62139689578714, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '5527325', 'n_tokens_mistral': 2207, 'n_tokens_neox': 1942, 'n_words': 428}