aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/schema/Cluster.java
blob: f5ea4fdffc79d6daa49621730918a62f00fc4156 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.schema;

import com.yahoo.api.annotations.Beta;

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

/**
 * Information about the search aspects of a content cluster.
 *
 * @author bratseth
 */
@Beta
public class Cluster {

    private final String name;
    private final boolean isStreaming;
    private final Set<String> schemas;

    private Cluster(Builder builder) {
        this.name = builder.name;
        this.isStreaming = builder.isStreaming;
        this.schemas = Set.copyOf(builder.schemas);
    }

    public String name() { return name; }

    /** Returns true if this cluster uses streaming search. */
    public boolean isStreaming() { return isStreaming; }

    /** Returns the names of the subset of all schemas that are present in this cluster. */
    public Set<String> schemas() { return schemas; }

    @Override
    public boolean equals(Object o) {
        if ( ! (o instanceof Cluster other)) return false;
        if ( ! this.name.equals(other.name)) return false;
        if ( this.isStreaming != other.isStreaming()) return false;
        if ( ! this.schemas.equals(other.schemas)) return false;
        return true;
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, isStreaming, schemas);
    }

    @Override
    public String toString() { return "cluster '" + name + "'"; }

    public static class Builder {

        private final String name;
        private boolean isStreaming = false;
        private final Set<String> schemas = new HashSet<>();

        public Builder(String name) {
            this.name = name;
        }

        public Builder setStreaming(boolean isStreaming) {
            this.isStreaming = isStreaming;
            return this;
        }

        public Builder addSchema(String schema) {
            schemas.add(schema);
            return this;
        }

        public Cluster build() {
            return new Cluster(this);
        }

    }

}