Skip to content

Commit

Permalink
136: Status
Browse files Browse the repository at this point in the history
Task-Url: #136
  • Loading branch information
LorenzoBettini committed Aug 28, 2022
1 parent 303e661 commit c91f4cf
Showing 1 changed file with 22 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,43 @@

package org.pitest.pitclipse.runner.model;

import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Ordering;

import org.pitest.pitclipse.runner.results.DetectionStatus;
import static java.util.Comparator.comparing;
import static java.util.Comparator.naturalOrder;
import static java.util.Comparator.nullsLast;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import static com.google.common.collect.Collections2.transform;
import org.pitest.pitclipse.runner.results.DetectionStatus;

public class Status implements Visitable, Countable {

private final DetectionStatus detectionStatus;
private final ImmutableList<ProjectMutations> projectMutations;
private final List<ProjectMutations> projectMutations;
private final MutationsModel mutationsModel;

private Status(MutationsModel mutationsModel, DetectionStatus detectionStatus,
ImmutableList<ProjectMutations> projectMutations) {
List<ProjectMutations> projectMutations) {
this.mutationsModel = mutationsModel;
this.detectionStatus = detectionStatus;
this.projectMutations = ImmutableList.copyOf(
transform(projectMutations, input -> input.copyOf().withStatus(Status.this).build())
);
this.projectMutations = projectMutations.stream()
.map(input -> input.copyOf().withStatus(Status.this).build())
.collect(Collectors.toList());
}

public DetectionStatus getDetectionStatus() {
return detectionStatus;
}

public ImmutableList<ProjectMutations> getProjectMutations() {
public List<ProjectMutations> getProjectMutations() {
return projectMutations;
}

public static class Builder {
private DetectionStatus detectionStatus;
private ImmutableList<ProjectMutations> projectMutations = ImmutableList.of();
private List<ProjectMutations> projectMutations = new ArrayList<>();
private MutationsModel mutationsModel;

private Builder() {
Expand All @@ -64,8 +64,12 @@ public Builder withDetectionStatus(DetectionStatus detectionStatus) {
}

public Builder withProjectMutations(List<ProjectMutations> projectMutations) {
this.projectMutations = Ordering.natural().nullsLast().onResultOf(ProjectName.GET)
.immutableSortedCopy(projectMutations);
this.projectMutations = projectMutations.stream()
.sorted(
comparing(ProjectMutations::getProjectName,
nullsLast(
naturalOrder())))
.collect(Collectors.toList());
return this;
}

Expand Down Expand Up @@ -115,18 +119,10 @@ public long count() {
return sum;
}

private enum ProjectName implements Function<ProjectMutations, String> {
GET;

@Override
public String apply(ProjectMutations input) {
return input.getProjectName();
}

}

public Builder copyOf() {
return builder().withDetectionStatus(detectionStatus).withProjectMutations(projectMutations);
return builder()
.withDetectionStatus(detectionStatus)
.withProjectMutations(projectMutations);
}

public MutationsModel getMutationsModel() {
Expand Down

0 comments on commit c91f4cf

Please sign in to comment.