diff options
Diffstat (limited to 'config-model')
-rw-r--r-- | config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedSorting.java | 38 | ||||
-rw-r--r-- | config-model/src/main/javacc/IntermediateParser.jj | 8 |
2 files changed, 36 insertions, 10 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedSorting.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedSorting.java index 2a090e94312..d4686c594da 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedSorting.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedSorting.java @@ -1,23 +1,49 @@ package com.yahoo.searchdefinition.parser; +import java.util.Optional; + /** * This class holds the extracted information after parsing a "sorting" * block, using simple data structures as far as possible. Do not put * advanced logic here! * @author arnej27959 **/ -class ParsedSorting { +class ParsedSorting extends ParsedBlock { enum Function { RAW, LOWERCASE, UCA } enum Strength { PRIMARY, SECONDARY, TERTIARY, QUATERNARY, IDENTICAL } - void setAscending() {} - void setDescending() {} + private boolean ascending = true; + private Function sortFunction = null; + private Strength sortStrength = null; + private String sortLocale = null; + + ParsedSorting(String blockName, String blockType) { + super(blockName, blockType); + } + + boolean getAscending() { return this.ascending; } + boolean getDescending() { return ! this.ascending; } + Optional<Function> getFunction() { return Optional.ofNullable(sortFunction); } + Optional<Strength> getStrength() { return Optional.ofNullable(sortStrength); } + Optional<String> getLocale() { return Optional.ofNullable(sortLocale); } + + void setAscending() { this.ascending = true; } - void setLocale(String locale) {} + void setDescending() { this.ascending = false; } - void setFunction(Function func) {} - void setStrength(Strength strength) {} + void setLocale(String value) { + verifyThat(sortLocale == null, "sorting already has locale", sortLocale); + this.sortLocale = value; + } + void setFunction(Function value) { + verifyThat(sortFunction == null, "sorting already has function", sortFunction); + this.sortFunction = value; + } + void setStrength(Strength value) { + verifyThat(sortStrength == null, "sorting already has strength", sortStrength); + this.sortStrength = value; + } } diff --git a/config-model/src/main/javacc/IntermediateParser.jj b/config-model/src/main/javacc/IntermediateParser.jj index 193fc49f19f..67e8b84c66d 100644 --- a/config-model/src/main/javacc/IntermediateParser.jj +++ b/config-model/src/main/javacc/IntermediateParser.jj @@ -1064,7 +1064,7 @@ void fieldSorting(ParsedField field) : ParsedSorting sortInfo; } { - sortInfo = sorting() { field.setSorting(sortInfo); } + sortInfo = sorting(field.name(), "field") { field.setSorting(sortInfo); } } /* pick up sorting in field block */ @@ -1073,12 +1073,12 @@ void attributeSorting(ParsedAttribute attribute) : ParsedSorting sortInfo; } { - sortInfo = sorting() { attribute.setSorting(sortInfo); } + sortInfo = sorting(attribute.name(), "attribute") { attribute.setSorting(sortInfo); } } -ParsedSorting sorting() : +ParsedSorting sorting(String blockName, String blockType) : { - ParsedSorting sort = new ParsedSorting(); + ParsedSorting sort = new ParsedSorting(blockName, blockType); } { <SORTING> |