org.conqat.engine.sourcecode.coverage.ProbeCoverageInfo Maven / Gradle / Ivy
/*-------------------------------------------------------------------------+
| |
| Copyright (c) 2005-2018 The ConQAT Project |
| |
| Licensed 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.conqat.engine.sourcecode.coverage;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.conqat.lib.commons.collections.CollectionUtils;
import org.conqat.lib.commons.collections.UnmodifiableList;
import org.conqat.lib.commons.js_export.ExportAsType;
import org.conqat.lib.commons.js_export.ExportToTypeScript;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Holds coverage information for a file represented as "probes". See
* {@link CoverageProbeBase} for a description of probes.
*
* We use this object both to represent covered and coverable information. The
* flag {@link #uploaded} differs between the two cases.
*/
@ExportToTypeScript
public class ProbeCoverageInfo implements Serializable {
private static final long serialVersionUID = 1L;
/** The name of the JSON property name for {@link #probes}. */
private static final String PROBES_PROPERTY = "probes";
/** The name of the JSON property name for {@link #uploaded}. */
private static final String UPLOADED_PROPERTY = "uploaded";
@JsonProperty(PROBES_PROPERTY)
@ExportAsType("Array")
private final ArrayList probes;
/**
* Signals whether this is coverage info uploaded externally. See also class
* comment
*/
@JsonProperty(UPLOADED_PROPERTY)
private final boolean uploaded;
public ProbeCoverageInfo(boolean uploaded) {
this.probes = new ArrayList<>();
this.uploaded = uploaded;
}
@JsonCreator
public ProbeCoverageInfo(@JsonProperty(UPLOADED_PROPERTY) boolean uploaded,
@JsonProperty(PROBES_PROPERTY) Collection probes) {
this(uploaded);
this.probes.addAll(probes);
}
/** Constructor. */
public ProbeCoverageInfo(ProbeCoverageInfo coverageProbeInfo) {
this.probes = new ArrayList<>(coverageProbeInfo.probes);
this.uploaded = coverageProbeInfo.uploaded;
}
/** Adds the given probe */
public void addProbe(CoverageProbeBase probe) {
probes.add(probe);
}
public UnmodifiableList getProbes() {
return CollectionUtils.asUnmodifiable(probes);
}
/** Overwrites the probes of this coverage info. */
public void setProbes(List probes) {
this.probes.clear();
this.probes.addAll(probes);
}
/** @see #uploaded */
public boolean isUploaded() {
return uploaded;
}
/** Returns the number of coverable entities of this probe coverage */
public int getCoverableCount() {
int coverableCount = 0;
for (CoverageProbeBase probe : probes) {
coverableCount += probe.getCoverableCount();
}
return coverableCount;
}
/** Returns the number of covered entities of this probe coverage */
public int getCoveredCount() {
int coveredCount = 0;
for (CoverageProbeBase probe : probes) {
coveredCount += probe.getCoveredCount();
}
return coveredCount;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy