diff --git a/conjure-lib/src/main/java/com/palantir/conjure/java/lib/internal/ConjureCollections.java b/conjure-lib/src/main/java/com/palantir/conjure/java/lib/internal/ConjureCollections.java index 579aaf9b5..c8a5a4df8 100644 --- a/conjure-lib/src/main/java/com/palantir/conjure/java/lib/internal/ConjureCollections.java +++ b/conjure-lib/src/main/java/com/palantir/conjure/java/lib/internal/ConjureCollections.java @@ -20,6 +20,7 @@ import com.palantir.logsafe.Preconditions; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -37,6 +38,10 @@ private ConjureCollections() { // cannot instantiate } + public static List unmodifiableList(List list) { + return Collections.unmodifiableList(list); + } + @SuppressWarnings("unchecked") public static void addAll(Collection addTo, Iterable elementsToAdd) { Preconditions.checkNotNull(elementsToAdd, "elementsToAdd cannot be null"); @@ -139,6 +144,12 @@ public static Set newNonNullSet(Iterable iterable) { return set; } + /** + * The following Conjure boxed list wrappers for the eclipse-collections [type]ArrayList are temporary (except + * ConjureSafeLongList). In eclipse-collections 12, a BoxedMutable[type]List will be released. Once available, + * Conjure[type]List should be replaced with that. + */ + // This method returns a list that can't handle nulls. Do not use this unless the nonNullCollections flag is set public static List newNonNullDoubleList() { return new ConjureDoubleList(new DoubleArrayList()); @@ -157,11 +168,12 @@ public static List newNonNullDoubleList(Iterable iterable) { return doubleList; } - /** - * The following Conjure boxed list wrappers for the eclipse-collections [type]ArrayList are temporary (except - * ConjureSafeLongList). In eclipse-collections 12, a BoxedMutable[type]List will be released. Once available, - * Conjure[type]List should be replaced with that. - */ + // This method modifies a list that can't handle nulls. Do not use this unless the nonNullCollections flag is set + public static void addAllToDoubleList(Collection addTo, double[] elementsToAdd) { + for (double el : elementsToAdd) { + addTo.add(el); + } + } // This method returns a list that can't handle nulls. Do not use this unless the nonNullCollections flag is set public static List newNonNullIntegerList() { @@ -181,9 +193,17 @@ public static List newNonNullIntegerList(Iterable iterable) { return integerList; } + // This method modifies a list that can't handle nulls. Do not use this unless the nonNullCollections flag is set + public static void addAllToIntegerList(Collection addTo, int[] elementsToAdd) { + for (int el : elementsToAdd) { + addTo.add(el); + } + } + /** * Deprecated, this should only ever be called by a previously generated conjure internal implementation. */ + // This method returns a list that can't handle nulls. Do not use this unless the nonNullCollections flag is set public static List newNonNullBooleanList() { return newNonNullList(); } @@ -212,4 +232,11 @@ public static List newNonNullSafeLongList(Iterable iterable) return safeLongList; } + + // This method modifies a list that can't handle nulls. Do not use this unless the nonNullCollections flag is set + public static void addAllToSafeLongList(Collection addTo, long[] elementsToAdd) { + for (long el : elementsToAdd) { + addTo.add(SafeLong.of(el)); + } + } }