blob: 57de66f80a0ffc414be16276c8e0ca1b1c72ea91 (
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.indexinglanguage.expressions;
import com.yahoo.document.DataType;
import com.yahoo.document.DocumentType;
import com.yahoo.document.Field;
import com.yahoo.vespa.indexinglanguage.ExpressionConverter;
import com.yahoo.vespa.objects.ObjectOperation;
import com.yahoo.vespa.objects.ObjectPredicate;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
/**
* @author Simon Thoresen Hult
*/
public abstract class ExpressionList<T extends Expression> extends CompositeExpression implements Iterable<T> {
private final List<T> expressions = new LinkedList<T>();
protected ExpressionList(Iterable<? extends T> lst, DataType inputType) {
super(inputType);
for (T exp : lst) {
this.expressions.add(exp);
}
}
protected List<Expression> convertChildList(ExpressionConverter converter) {
return asList().stream().map(converter::convert).filter(Objects::nonNull).toList();
}
@Override
public void setStatementOutput(DocumentType documentType, Field field) {
for (Expression expression : expressions)
expression.setStatementOutput(documentType, field);
}
public int size() {
return expressions.size();
}
public T get(int idx) {
return expressions.get(idx);
}
public boolean isEmpty() {
return expressions.isEmpty();
}
public List<T> asList() {
return Collections.unmodifiableList(expressions);
}
@Override
public Iterator<T> iterator() {
return expressions.iterator();
}
@Override
@SuppressWarnings("rawtypes")
public boolean equals(Object obj) {
if (!(obj instanceof ExpressionList rhs)) return false;
if (!expressions.equals(rhs.expressions)) return false;
return true;
}
@Override
public int hashCode() {
return getClass().hashCode() + expressions.hashCode();
}
@Override
public void selectMembers(ObjectPredicate predicate, ObjectOperation operation) {
for (T exp : expressions) {
exp.select(predicate, operation);
}
}
}
|