diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 6644bb938..e511bbd63 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -51,19 +51,23 @@ If the output is not quite correct, check for invisible trailing spaces!
+
+ Added a constructor to "AbstractListChromosome" that does not copy the
+ input argument.
+
- BSP tree now provides an API to compute a global signed distance from
- a test point to the region. The distance is positive if the point is
- outside of the region, negative if the point is inside, and zero
- when the point is at the boundary. The distance is continuous
- everywhere, so it can be used with a root solver to identify accurately
- boundary crossings. This API is available for all BSP trees, in
- Euclidean and spherical geometries, and in all dimensions.
+ BSP tree now provides an API to compute a global signed distance from
+ a test point to the region. The distance is positive if the point is
+ outside of the region, negative if the point is inside, and zero
+ when the point is at the boundary. The distance is continuous
+ everywhere, so it can be used with a root solver to identify accurately
+ boundary crossings. This API is available for all BSP trees, in
+ Euclidean and spherical geometries, and in all dimensions.
- IntervalsSet now implements Iterable<double[]>, so one can iterate
- over the sub-intervals without building a full list containing
- a copy of everything beforehand.
+ IntervalsSet now implements Iterable<double[]>, so one can iterate
+ over the sub-intervals without building a full list containing
+ a copy of everything beforehand.
"Precision#round(double, ...)" will now return negative zero for negative
diff --git a/src/main/java/org/apache/commons/math3/genetics/AbstractListChromosome.java b/src/main/java/org/apache/commons/math3/genetics/AbstractListChromosome.java
index f133fc432..ce4541cd8 100644
--- a/src/main/java/org/apache/commons/math3/genetics/AbstractListChromosome.java
+++ b/src/main/java/org/apache/commons/math3/genetics/AbstractListChromosome.java
@@ -34,17 +34,16 @@ public abstract class AbstractListChromosome extends Chromosome {
private final List representation;
/**
- * Constructor.
+ * Constructor, copying the input representation.
* @param representation inner representation of the chromosome
* @throws InvalidRepresentationException iff the representation
can not represent a valid chromosome
*/
public AbstractListChromosome(final List representation) throws InvalidRepresentationException {
- checkValidity(representation);
- this.representation = Collections.unmodifiableList(new ArrayList(representation));
+ this(representation, true);
}
/**
- * Constructor.
+ * Constructor, copying the input representation.
* @param representation inner representation of the chromosome
* @throws InvalidRepresentationException iff the representation
can not represent a valid chromosome
*/
@@ -52,6 +51,17 @@ public abstract class AbstractListChromosome extends Chromosome {
this(Arrays.asList(representation));
}
+ /**
+ * Constructor.
+ * @param representation inner representation of the chromosome
+ * @param copyList if {@code true}, the representation will be copied, otherwise it will be referenced.
+ */
+ public AbstractListChromosome(final List representation, final boolean copyList) {
+ checkValidity(representation);
+ this.representation =
+ Collections.unmodifiableList(copyList ? new ArrayList(representation) : representation);
+ }
+
/**
* Asserts that representation
can represent a valid chromosome.
*