blob: fa220003adc8ad9c23ab72e767d586d767f4f06c (
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchdefinition;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import com.yahoo.searchdefinition.document.FieldSet;
/**
* The field sets owned by a {@link Schema}
* Both built in and user defined.
*
* @author vegardh
*/
public class FieldSets {
private final Map<String, FieldSet> userFieldSets;
private final Map<String, FieldSet> builtInFieldSets;
public FieldSets() {
userFieldSets = new LinkedHashMap<>();
builtInFieldSets = new LinkedHashMap<>();
}
FieldSets(FieldSets other) {
userFieldSets = new LinkedHashMap<>(other.userFieldSets);
builtInFieldSets = new LinkedHashMap<>(other.builtInFieldSets);
}
void add(FieldSets other) {
userFieldSets.putAll(other.userFieldSets);
builtInFieldSets.putAll(other.builtInFieldSets);
}
/**
* Adds an entry to user field sets, creating entries as needed
*
* @param setName name of a field set
* @param field field to add to field set
*/
public void addUserFieldSetItem(String setName, String field) {
if (userFieldSets.get(setName) == null) {
// First entry in this set
userFieldSets.put(setName, new FieldSet(setName));
}
userFieldSets.get(setName).addFieldName(field);
}
/**
* Adds an entry to built in field sets, creating entries as needed
*
* @param setName name of a field set
* @param field field to add to field set
*/
public void addBuiltInFieldSetItem(String setName, String field) {
if (builtInFieldSets.get(setName) == null) {
// First entry in this set
builtInFieldSets.put(setName, new FieldSet(setName));
}
builtInFieldSets.get(setName).addFieldName(field);
}
/** Returns the built in field sets, unmodifiable */
public Map<String, FieldSet> builtInFieldSets() {
return Collections.unmodifiableMap(builtInFieldSets);
}
/** Returns the user defined field sets, unmodifiable */
public Map<String, FieldSet> userFieldSets() {
return Collections.unmodifiableMap(userFieldSets);
}
}
|