blob: d229e92a90d64fe8cdb9727fafa1edf95f78da58 [file] [log] [blame]
Thomas Vachuska48448082016-02-19 22:14:54 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Thomas Vachuska48448082016-02-19 22:14:54 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.net.region;
18
19import com.google.common.base.MoreObjects;
20import com.google.common.collect.ImmutableList;
21import org.onosproject.cluster.NodeId;
Simon Hunt53612212016-12-04 17:19:52 -080022import org.onosproject.net.AbstractAnnotated;
23import org.onosproject.net.Annotations;
Thomas Vachuska48448082016-02-19 22:14:54 -080024
25import java.util.List;
26import java.util.Objects;
27import java.util.Set;
28
29/**
30 * Default implementation of a region.
31 */
Simon Hunt53612212016-12-04 17:19:52 -080032public final class DefaultRegion extends AbstractAnnotated implements Region {
Thomas Vachuska48448082016-02-19 22:14:54 -080033
34 private final RegionId id;
35 private final String name;
36 private final Type type;
37 private final List<Set<NodeId>> masters;
38
39 /**
40 * Creates a region using the supplied information.
41 *
42 * @param id region identifier
43 * @param name friendly name
44 * @param type region type
Simon Hunt53612212016-12-04 17:19:52 -080045 * @param annots annotations
Thomas Vachuska48448082016-02-19 22:14:54 -080046 * @param masters list of sets of cluster node identifiers; in order of mastership
47 */
Simon Hunt53612212016-12-04 17:19:52 -080048 public DefaultRegion(RegionId id, String name, Type type,
49 Annotations annots, List<Set<NodeId>> masters) {
50 super(annots);
Thomas Vachuska48448082016-02-19 22:14:54 -080051 this.id = id;
52 this.name = name;
53 this.type = type;
54 this.masters = masters != null ? ImmutableList.copyOf(masters) : ImmutableList.of();
55 }
56
57 @Override
58 public RegionId id() {
59 return id;
60 }
61
62 @Override
63 public String name() {
64 return name;
65 }
66
67 @Override
68 public Type type() {
69 return type;
70 }
71
72 @Override
73 public List<Set<NodeId>> masters() {
74 return masters;
75 }
76
77 @Override
78 public int hashCode() {
79 return Objects.hash(id, name, type, masters);
80 }
81
82 @Override
83 public boolean equals(Object obj) {
84 if (this == obj) {
85 return true;
86 }
87 if (obj instanceof DefaultRegion) {
88 final DefaultRegion that = (DefaultRegion) obj;
89 return Objects.equals(this.id, that.id)
90 && Objects.equals(this.name, that.name)
91 && Objects.equals(this.type, that.type)
92 && Objects.equals(this.masters, that.masters);
93 }
94 return false;
95 }
96
97 @Override
98 public String toString() {
99 return MoreObjects.toStringHelper(this)
100 .add("id", id)
101 .add("name", name)
102 .add("type", type)
103 .add("masters", masters)
104 .toString();
105 }
106
107}