blob: 61abf96a7ecc52569b0166afaa1f545486f6f66b (
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
|
// 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<>();
public ParsedStruct(String name) {
super(name, "struct");
}
List<ParsedField> getFields() { return List.copyOf(fields.values()); }
List<String> getInherited() { return List.copyOf(inherited); }
void addField(ParsedField field) {
String fieldName = field.name();
if (fields.containsKey(fieldName)) {
throw new IllegalArgumentException("struct "+name()+" already has field "+fieldName);
}
fields.put(fieldName, field);
}
void inherit(String other) { inherited.add(other); }
}
|