aboutsummaryrefslogtreecommitdiffstats
path: root/client/src/main/java/ai/vespa/client/dsl/Select.java
blob: fd1659efbae825e968a4552a4bec3ba8ec117826 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.client.dsl;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Select {

    private final List<String> selectedFields = new ArrayList<>();

    Select(String fieldName) {
        selectedFields.add(fieldName);
    }

    public Select(String fieldName, String... others) {
        selectedFields.add(fieldName);
        selectedFields.addAll(Stream.of(others).collect(Collectors.toList()));
    }

    Select(List<String> fieldNames) {
        selectedFields.addAll(fieldNames);
    }

    public Sources from(String sd) {
        return new Sources(this, sd);
    }

    public Sources from(String sd, String... sds) {
        return new Sources(this, sd, sds);
    }

    @Override
    public String toString() {
        return selectedFields.isEmpty() ? "*" : String.join(", ", selectedFields);
    }

}