blob: 2e981a893ce934477e878b653165379c9c845055 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.schema.fieldoperation;
import com.yahoo.schema.document.Attribute;
import com.yahoo.schema.document.SDField;
import com.yahoo.schema.document.Sorting;
/**
* @author Einar M R Rosenvinge
*/
public class SortingOperation implements FieldOperation {
private final String attributeName;
private Boolean ascending;
private Boolean descending;
private Sorting.Function function;
private Sorting.Strength strength;
private String locale;
public SortingOperation(String attributeName) {
this.attributeName = attributeName;
}
public String getAttributeName() {
return attributeName;
}
public Boolean getAscending() {
return ascending;
}
public void setAscending() {
this.ascending = true;
}
public Boolean getDescending() {
return descending;
}
public void setDescending() {
this.descending = true;
}
public Sorting.Function getFunction() {
return function;
}
public void setFunction(Sorting.Function function) {
this.function = function;
}
public Sorting.Strength getStrength() {
return strength;
}
public void setStrength(Sorting.Strength strength) {
this.strength = strength;
}
public String getLocale() {
return locale;
}
public void setLocale(String locale) {
this.locale = locale;
}
public void apply(SDField field) {
Attribute attribute = field.getAttributes().get(attributeName);
if (attribute == null) {
attribute = new Attribute(attributeName, field.getDataType());
field.addAttribute(attribute);
}
Sorting sorting = attribute.getSorting();
if (ascending != null) {
sorting.setAscending();
}
if (descending != null) {
sorting.setDescending();
}
if (function != null) {
sorting.setFunction(function);
}
if (strength != null) {
sorting.setStrength(strength);
}
if (locale != null) {
sorting.setLocale(locale);
}
}
}
|