aboutsummaryrefslogtreecommitdiffstats
path: root/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/EndpointId.java
blob: b7ca8587efa4d6f7798673713e4f5e9789b5aabd (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.application;

import java.util.Objects;

/**
 * A user-specified endpoint ID.  This is typically the first part of an endpoint name.
 *
 * @author ogronnesby
 */
public class EndpointId implements Comparable<EndpointId> {

    private static final EndpointId DEFAULT = new EndpointId("default");

    private final String id;

    private EndpointId(String id) {
        this.id = requireNotEmpty(id);
    }

    public String id() { return id; }

    @Override
    public String toString() {
        return "endpoint id '" + id + "'";
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        EndpointId that = (EndpointId) o;
        return Objects.equals(id, that.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }

    private static String requireNotEmpty(String input) {
        Objects.requireNonNull(input);
        if (input.isEmpty()) {
            throw new IllegalArgumentException("The value EndpointId was empty");
        }
        return input;
    }

    public static EndpointId defaultId() { return DEFAULT; }

    public static EndpointId of(String id) { return new EndpointId(id); }

    @Override
    public int compareTo(EndpointId o) {
        return id.compareTo(o.id);
    }

}