Skip to content

Commit 16150fc

Browse files
order elements of a MultiChoice.Array
1 parent 3283986 commit 16150fc

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

api/src/org/labkey/api/data/MultiChoice.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import org.json.JSONArray;
77
import org.junit.Assert;
88
import org.junit.Test;
9-
import org.labkey.api.collections.CaseInsensitiveHashSet;
109
import org.labkey.api.exp.property.IPropertyValidator;
1110
import org.labkey.api.exp.property.PropertyService;
1211
import org.labkey.api.gwt.client.model.PropertyValidatorType;
@@ -21,7 +20,6 @@
2120
import java.sql.ResultSet;
2221
import java.sql.SQLException;
2322
import java.sql.Types;
24-
import java.text.Format;
2523
import java.util.ArrayList;
2624
import java.util.Arrays;
2725
import java.util.Collection;
@@ -32,6 +30,7 @@
3230
import java.util.Map;
3331
import java.util.Objects;
3432
import java.util.Set;
33+
import java.util.TreeSet;
3534
import java.util.function.BiConsumer;
3635
import java.util.function.BinaryOperator;
3736
import java.util.function.Function;
@@ -216,12 +215,12 @@ public static class Array implements List<String>, java.sql.Array
216215

217216
protected Array(Stream<Object> str)
218217
{
219-
CaseInsensitiveHashSet set = new CaseInsensitiveHashSet();
220-
array = str.filter(Objects::nonNull)
218+
TreeSet<String> setCaseSensitive = new TreeSet<>();
219+
str.filter(Objects::nonNull)
221220
.map(s -> StringUtils.trimToNull(s.toString()))
222221
.filter(Objects::nonNull)
223-
.filter(set::add)
224-
.toArray(String[]::new);
222+
.forEach(setCaseSensitive::add);
223+
array = setCaseSensitive.toArray(new String[0]);
225224
}
226225

227226
protected Array(Object[] array)
@@ -575,6 +574,8 @@ public void testConvert() throws Exception
575574
assertEquals(expected, _converter.convert(Array.class, new String[]{"a,","b\"","c "}));
576575
assertEquals(expected, _converter.convert(Array.class, List.of("a,","b\"","c ")));
577576
assertEquals(expected, _converter.convert(Array.class, new JSONArray(List.of("a,","b\"","c "))));
577+
// test that result is ordered
578+
assertEquals(expected, _converter.convert(Array.class, "\"c \",\"b\"\"\",\"a,\""));
578579
}
579580

580581
@Test

0 commit comments

Comments
 (0)