Skip to content

Commit

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

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 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 static com.google.common.collect.Collections2.transform;
import java.util.stream.Collectors;

public class ProjectMutations implements Visitable, Countable {
private final String projectName;
private final ImmutableList<PackageMutations> packageMutations;
private final List<PackageMutations> packageMutations;
private final Status status;

private ProjectMutations(Status status, String projectName, ImmutableList<PackageMutations> packageMutations) {
private ProjectMutations(Status status, String projectName, List<PackageMutations> packageMutations) {
this.status = status;
this.projectName = projectName;
this.packageMutations = ImmutableList.copyOf(transform(packageMutations,
input -> input.copyOf().withProjectMutations(ProjectMutations.this).build()));
this.packageMutations = packageMutations.stream()
.map(input -> input.copyOf().withProjectMutations(ProjectMutations.this).build())
.collect(Collectors.toList());
}

@Override
Expand All @@ -51,7 +52,9 @@ public static Builder builder() {
}

public Builder copyOf() {
return builder().withPackageMutations(packageMutations).withProjectName(projectName);
return builder()
.withPackageMutations(packageMutations)
.withProjectName(projectName);
}

public List<PackageMutations> getPackageMutations() {
Expand All @@ -60,7 +63,7 @@ public List<PackageMutations> getPackageMutations() {

public static class Builder {
private String projectName;
private ImmutableList<PackageMutations> packageMutations = ImmutableList.of();
private List<PackageMutations> packageMutations = new ArrayList<>();
private Status status;

private Builder() {
Expand All @@ -72,8 +75,12 @@ public Builder withProjectName(String projectName) {
}

public Builder withPackageMutations(List<PackageMutations> packages) {
this.packageMutations = Ordering.natural().nullsLast().onResultOf(PackageName.GET)
.immutableSortedCopy(packages);
this.packageMutations = packages.stream()
.sorted(
comparing(PackageMutations::getPackageName,
nullsLast(
naturalOrder())))
.collect(Collectors.toList());
return this;
}

Expand Down Expand Up @@ -124,13 +131,4 @@ public Status getStatus() {
return status;
}

private enum PackageName implements Function<PackageMutations, String> {
GET;

@Override
public String apply(PackageMutations input) {
return input.getPackageName();
}
}

}

0 comments on commit c71b337

Please sign in to comment.