blob: 4edd6f5722beac42a7406e4b2fd8d4ad9a3e56bf (
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
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.documentmodel;
import com.yahoo.document.Field;
import java.io.Serializable;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* @author baldersheim
* @since 2010-02-19
*/
public class FieldView implements Serializable {
private String name;
private Map<String, Field> fields = new LinkedHashMap<>();
/**
* Creates a view with a name
* @param name Name of the view.
*/
public FieldView(String name) {
this.name = name;
}
public String getName() { return name; }
public Collection<Field> getFields() { return fields.values(); }
public Field get(String name) { return fields.get(name); }
public void remove(String name) { fields.remove(name); }
/**
* This method will add a field to a view. All fields must come from the same document type. Not enforced here.
* @param field The field to add.
* @return Itself for chaining purposes.
*/
public FieldView add(Field field) {
if (fields.containsKey(field.getName())) {
if ( ! fields.get(field.getName()).equals(field)) {
throw new IllegalArgumentException(
"View '" + name + "' already contains a field with name '" +
field.getName() + "' and definition : " +
fields.get(field.getName()).toString() + ". Your is : " + field.toString());
}
} else {
fields.put(field.getName(), field);
}
return this;
}
/**
* This method will join the two views.
* @param view The view to be joined in to this.
* @return Itself for chaining.
*/
public FieldView add(FieldView view) {
for(Field field : view.getFields()) {
add(field);
}
return this;
}
}
|