Skip to content

Commit

Permalink
Merge pull request #1860 from scireum/feature/aha/SIRI-857
Browse files Browse the repository at this point in the history
Permits sorting lookup values by a given field.
  • Loading branch information
andyHa authored Oct 23, 2023
2 parents 295e696 + 700199c commit 74cdd9c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/main/java/sirius/biz/codelists/LookupTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -60,7 +61,7 @@ public abstract class LookupTable {
public static final String CONFIG_KEY_MAPPING_FIELD = "mappingsField";
private final String mappingsField;

enum CodeCase {
protected enum CodeCase {
LOWER, UPPER, VERBATIM
}

Expand Down Expand Up @@ -428,6 +429,19 @@ public String forceNormalize(String code) {
return normalize(code).orElseGet(() -> normalizeCodeValue(code));
}

/**
* Provides a comparator which sorts codes by the occurrence order within the list.
*
* @param field the field to sort by. This can be any numeric field. Note that the YAML loader for Jupiter can
* generate such fields when specifying a <tt>rowNumber</tt>.
* See: <a href="https://docs.rs/jupiter/latest/jupiter/idb/idb_yaml_loader/index.html">YAML Loader</a>
* @return a comparator to sort codes by their occurrence order
*/
public Comparator<String> comparator(String field) {
return Comparator.<String, Integer>comparing(code -> fetchFieldValue(code, field).asInt(100))
.thenComparing(this::normalizeCodeValue);
}

/**
* Normalizes the given code by using the given mapping.
* <p>
Expand Down

0 comments on commit 74cdd9c

Please sign in to comment.