Thomas Vachuska | 4844808 | 2016-02-19 22:14:54 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Thomas Vachuska | 4844808 | 2016-02-19 22:14:54 -0800 | [diff] [blame] | 3 | * |
| 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 | |
| 17 | package org.onosproject.net.region; |
| 18 | |
| 19 | import com.google.common.base.MoreObjects; |
| 20 | import com.google.common.collect.ImmutableList; |
| 21 | import org.onosproject.cluster.NodeId; |
Simon Hunt | 5361221 | 2016-12-04 17:19:52 -0800 | [diff] [blame] | 22 | import org.onosproject.net.AbstractAnnotated; |
| 23 | import org.onosproject.net.Annotations; |
Thomas Vachuska | 4844808 | 2016-02-19 22:14:54 -0800 | [diff] [blame] | 24 | |
| 25 | import java.util.List; |
| 26 | import java.util.Objects; |
| 27 | import java.util.Set; |
| 28 | |
| 29 | /** |
| 30 | * Default implementation of a region. |
| 31 | */ |
Simon Hunt | 5361221 | 2016-12-04 17:19:52 -0800 | [diff] [blame] | 32 | public final class DefaultRegion extends AbstractAnnotated implements Region { |
Thomas Vachuska | 4844808 | 2016-02-19 22:14:54 -0800 | [diff] [blame] | 33 | |
| 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 Hunt | 5361221 | 2016-12-04 17:19:52 -0800 | [diff] [blame] | 45 | * @param annots annotations |
Thomas Vachuska | 4844808 | 2016-02-19 22:14:54 -0800 | [diff] [blame] | 46 | * @param masters list of sets of cluster node identifiers; in order of mastership |
| 47 | */ |
Simon Hunt | 5361221 | 2016-12-04 17:19:52 -0800 | [diff] [blame] | 48 | public DefaultRegion(RegionId id, String name, Type type, |
| 49 | Annotations annots, List<Set<NodeId>> masters) { |
| 50 | super(annots); |
Thomas Vachuska | 4844808 | 2016-02-19 22:14:54 -0800 | [diff] [blame] | 51 | 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 | } |