Skip to content
Snippets Groups Projects

Copy constructors and partial constructor deprecation

All threads resolved!
8 files
+ 185
28
Compare changes
  • Side-by-side
  • Inline

Files

+ 42
0
@@ -4,6 +4,7 @@ import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.time.ZonedDateTime;
import java.util.stream.Collectors;
import nl.tudelft.ewi.auta.common.model.metric.MetricSettings;
import org.springframework.data.annotation.Id;
@@ -79,7 +80,12 @@ public class Assignment {
/**
* Create a new assignment object.
* @param name the name of the assignment
*
* @deprecated all partial constructors are confusing and no full constructor exists.
* Use the default constructor {@link #Assignment()} and set the name explicitly
* with {@link #setName(String)}
*/
@Deprecated
public Assignment(final String name) {
this.name = name;
this.priority = 0;
@@ -99,7 +105,13 @@ public class Assignment {
* @param name the name of the assignment
* @param maxWarnings the maximum number of warnings
* @param maxFailures the maximum number of failures
*
* @deprecated all partial constructors are confusing and no full constructor exists.
* Use the default constructor {@link #Assignment()} and set the values explicitly
* with {@link #setName(String)}, {@link #setMaxWarnings(Integer)}, and
* {@link #setMaxFailures(Integer)}
*/
@Deprecated
public Assignment(final String name, final int maxWarnings, final int maxFailures) {
this.priority = 0;
this.id = null;
@@ -112,7 +124,12 @@ public class Assignment {
* Create a new assignment with maximum number of warnings and failures.
* @param maxWarnings the maximum number of warnings
* @param maxFailures the maximum number of failures
*
* @deprecated all partial constructors are confusing and no full constructor exists.
* Use the default constructor {@link #Assignment()} and set the values explicitly
* with {@link #setMaxWarnings(Integer)} and {@link #setMaxFailures(Integer)}
*/
@Deprecated
public Assignment(final int maxWarnings, final int maxFailures) {
this.priority = 0;
this.id = null;
@@ -121,6 +138,31 @@ public class Assignment {
this.maxFailures = maxFailures;
}
/**
* Creates a new assignment by deeply cloning another.
*
* @param other the assignment to copy
*/
public Assignment(final Assignment other) {
// Copy simple properties. Strings, enums, and (boxed) primitives are immutable and
// therefore do not require cloning
this.id = other.id;
this.name = other.name;
this.priority = other.priority;
this.deleted = other.deleted;
this.workUnitName = other.workUnitName;
this.workUnitId = other.workUnitId;
this.projectName = other.projectName;
this.maxWarnings = other.maxWarnings;
this.maxFailures = other.maxFailures;
this.allowedLanguages = new HashSet<>(other.allowedLanguages);
// Clone settings recursively
this.metricSettings = other.metricSettings.stream()
.map(MetricSettings::new)
.collect(Collectors.toSet());
}
/**
* Add a submission to an assignment.
* @param submission the submission to add
Loading