blob: f3eae2c4334ef58355512dc7bcc4b816998f1b1d (
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config;
import java.util.Objects;
/**
* A config definition key: name, namespace)
*
* @author bratseth
*/
public class ConfigDefinitionKey {
private final String name;
private final String namespace;
/**
* Creates a config definition key.
*
* @param name config definition name
* @param namespace config definition namespace
*/
public ConfigDefinitionKey(String name, String namespace) {
require(name, "A config name cannot be null or empty");
require(namespace, "A config namespace cannot be null or empty");
this.name = name;
this.namespace = namespace;
}
private static void require(String object, String message) {
Objects.requireNonNull(object, message);
if (object.isEmpty())
throw new IllegalArgumentException(message);
}
public ConfigDefinitionKey(ConfigKey<?> key) {
this(key.getName(), key.getNamespace());
}
public String getName() { return name; }
public String getNamespace() { return namespace; }
public String asFileName() {
return namespace + "." + name + ".def";
}
@Override
public boolean equals(Object o) {
if (o == this) return true;
if ( ! (o instanceof ConfigDefinitionKey)) return false;
ConfigDefinitionKey other = (ConfigDefinitionKey)o;
return name.equals(other.getName()) && namespace.equals(other.getNamespace());
}
@Override
public int hashCode() {
return namespace.hashCode() + name.hashCode();
}
@Override
public String toString() {
return namespace + "." + name;
}
}
|