Skip to content

Commit 9443bd1

Browse files
committed
Ref #25533: prevent extra sort
1 parent 689eea3 commit 9443bd1

2 files changed

Lines changed: 6 additions & 14 deletions

File tree

src/main/java/eu/openanalytics/containerproxy/model/runtime/AllowedParametersForUser.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ public class AllowedParametersForUser {
3333
* The integer represents the index of the parameter.
3434
* The list is sorted by the index.
3535
*/
36-
private final Map<String, List<Pair<Integer, String>>> values;
36+
private final Map<String, List<String>> values;
3737

3838
/**
3939
* List of all allowed combinations of the parameters for this specific user.
4040
*/
4141
private final HashSet<List<Integer>> allowedCombinations;
4242

4343

44-
public AllowedParametersForUser(Map<String, List<Pair<Integer, String>>> values, HashSet<List<Integer>> allowedCombinations) {
44+
public AllowedParametersForUser(Map<String, List<String>> values, HashSet<List<Integer>> allowedCombinations) {
4545
this.values = values;
4646
this.allowedCombinations = allowedCombinations;
4747
}
@@ -50,7 +50,7 @@ public HashSet<List<Integer>> getAllowedCombinations() {
5050
return allowedCombinations;
5151
}
5252

53-
public Map<String, List<Pair<Integer, String>>> getValues() {
53+
public Map<String, List<String>> getValues() {
5454
return values;
5555
}
5656
}

src/main/java/eu/openanalytics/containerproxy/service/ParametersService.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public AllowedParametersForUser calculateAllowedParametersForUser(Authentication
182182
// 2. compute a unique (per parameter id) index for every value
183183
// mapping of parameter id to a mapping of an allowed value and its index
184184
Map<String, Map<String, Integer>> valuesToIndex = new HashMap<>();
185-
Map<String, List<Pair<Integer, String>>> values = new HashMap<>();
185+
Map<String, List<String>> values = new HashMap<>();
186186
// for every set of allowed values
187187
for (Parameters.ValueSet valueSet : allowedValueSets) {
188188
// for every parameter in this set
@@ -193,21 +193,13 @@ public AllowedParametersForUser calculateAllowedParametersForUser(Authentication
193193
for (String value : valueSet.getParameterValues(parameterId)) {
194194
if (!valuesToIndex.get(parameterId).containsKey(value)) {
195195
// add it to allValues if it does not yet exist
196-
Integer newIndex = valuesToIndex.get(parameterId).size() + 1;
196+
Integer newIndex = values.get(parameterId).size() + 1;
197197
valuesToIndex.get(parameterId).put(value, newIndex);
198-
values.get(parameterId).add(Pair.of(newIndex, value));
198+
values.get(parameterId).add(value);
199199
}
200200
}
201201
}
202202
}
203-
// sort values
204-
values = values.entrySet()
205-
.stream()
206-
.collect(Collectors.toMap(
207-
Map.Entry::getKey,
208-
(v) -> v.getValue()
209-
.stream().sorted(Comparator.comparingInt(Pair::getKey))
210-
.collect(Collectors.toList())));
211203

212204
// 3. compute the set of allowed values
213205
HashSet<List<Integer>> allowedCombinations = new HashSet<>();

0 commit comments

Comments
 (0)