aboutsummaryrefslogtreecommitdiffstats
path: root/messagebus/src/main/java/com/yahoo/messagebus/routing/VerbatimDirective.java
blob: 3e2c10934d0c29414ab53d3522f9140d11a07614 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.messagebus.routing;

/**
 * This class represents a verbatim match within a {@link Hop}'s selector. This is nothing more than a string that will
 * be used as-is when performing service name lookups.
 *
 * @author Simon Thoresen Hult
 */
public class VerbatimDirective implements HopDirective {

    private final String image;

    /**
     * Constructs a new verbatim selector item for a given image.
     *
     * @param image The image to assign to this.
     */
    public VerbatimDirective(String image) {
        this.image = image;
    }

    @Override
    public boolean matches(HopDirective dir) {

        return dir instanceof VerbatimDirective && image.equals(((VerbatimDirective)dir).image);
    }

    /**
     * Returns the image to which this is a verbatim match.
     *
     * @return The image.
     */
    public String getImage() {
        return image;
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof VerbatimDirective)) {
            return false;
        }
        VerbatimDirective rhs = (VerbatimDirective)obj;
        if (!image.equals(rhs.image)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        return image != null ? image.hashCode() : 0;
    }

    @Override
    public String toString() {
        return image;
    }

    @Override
    public String toDebugString() {
        return "VerbatimDirective(image = '" + image + "')";
    }
}