blob: cc3b2425726121bf97e170b94968de9aa0e92907 (
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchdefinition.parser;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* This class holds the extracted information after parsing a "struct"
* block, using simple data structures as far as possible. Do not put
* advanced logic here!
* @author arnej27959
**/
public class ParsedStruct extends ParsedBlock {
private final List<String> inherited = new ArrayList<>();
private final Map<String, ParsedField> fields = new HashMap<>();
private String ownedBy = null;
public ParsedStruct(String name) {
super(name, "struct");
}
List<ParsedField> getFields() { return List.copyOf(fields.values()); }
List<String> getInherited() { return List.copyOf(inherited); }
String getOwner() { return ownedBy; }
void addField(ParsedField field) {
String fieldName = field.name();
verifyThat(! fields.containsKey(fieldName), "already has field", fieldName);
fields.put(fieldName, field);
}
void inherit(String other) {
verifyThat(! name().equals(other), "cannot inherit from itself");
inherited.add(other);
}
void tagOwner(String document) {
verifyThat(ownedBy == null, "already owned by document "+ownedBy);
this.ownedBy = document;
}
}
|