blob: 7e2a83b6b9ad157c94ac4cab4a238470be56a681 (
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.serviceview;
import java.util.Arrays;
import java.util.List;
import com.google.common.collect.ImmutableList;
/**
* Model a single cluster of services in the Vespa model.
*
* @author Steinar Knutsen
*/
public final class Cluster implements Comparable<Cluster> {
public final String name;
public final String type;
/**
* An ordered list of the service instances in this cluster.
*/
public final ImmutableList<Service> services;
public Cluster(String name, String type, List<Service> services) {
this.name = name;
this.type = type;
ImmutableList.Builder<Service> builder = ImmutableList.builder();
Service[] sortingBuffer = services.toArray(new Service[0]);
Arrays.sort(sortingBuffer);
builder.add(sortingBuffer);
this.services = builder.build();
}
@Override
public int compareTo(Cluster other) {
int nameOrder = name.compareTo(other.name);
if (nameOrder != 0) {
return nameOrder;
}
return type.compareTo(other.type);
}
@Override
public int hashCode() {
final int prime = 761;
int result = 1;
result = prime * result + name.hashCode();
result = prime * result + type.hashCode();
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Cluster other = (Cluster) obj;
if (!name.equals(other.name)) {
return false;
}
return type.equals(other.type);
}
@Override
public String toString() {
final int maxLen = 3;
StringBuilder builder = new StringBuilder();
builder.append("Cluster [name=").append(name).append(", type=").append(type).append(", services=")
.append(services.subList(0, Math.min(services.size(), maxLen))).append("]");
return builder.toString();
}
}
|