Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2016 Open Networking Laboratory |
| 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 | package org.onosproject.tetopology.management.api.node; |
| 17 | |
| 18 | import java.util.BitSet; |
| 19 | |
| 20 | import org.onosproject.tetopology.management.api.TeStatus; |
| 21 | |
| 22 | import com.google.common.base.MoreObjects; |
| 23 | import com.google.common.base.Objects; |
| 24 | |
| 25 | /** |
| 26 | * Representation of common node attributes. |
| 27 | */ |
| 28 | public class CommonNodeData { |
| 29 | private final String name; |
| 30 | private final TeStatus adminStatus; |
| 31 | private final TeStatus opStatus; |
| 32 | private final BitSet flags; |
| 33 | |
| 34 | /** |
| 35 | * Creates a common node data instance. |
| 36 | * |
| 37 | * @param name the TE node name |
| 38 | * @param adminStatus the admin status |
| 39 | * @param opStatus the operational status |
| 40 | * @param flags the node flags |
| 41 | */ |
| 42 | public CommonNodeData(String name, TeStatus adminStatus, |
| 43 | TeStatus opStatus, BitSet flags) { |
| 44 | this.name = name; |
| 45 | this.adminStatus = adminStatus; |
| 46 | this.opStatus = opStatus; |
| 47 | this.flags = flags; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Creates a common node data instance based on a given TE node. |
| 52 | * |
| 53 | * @param node the given TE node |
| 54 | */ |
| 55 | public CommonNodeData(TeNode node) { |
| 56 | this.name = node.name(); |
| 57 | this.adminStatus = node.adminStatus(); |
| 58 | this.opStatus = node.opStatus(); |
| 59 | this.flags = node.flags(); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Returns the TE node name. |
| 64 | * |
| 65 | * @return the name |
| 66 | */ |
| 67 | public String name() { |
| 68 | return name; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Returns the administrative status. |
| 73 | * |
| 74 | * @return the admin status |
| 75 | */ |
| 76 | public TeStatus adminStatus() { |
| 77 | return adminStatus; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Returns the operational status. |
| 82 | * |
| 83 | * @return the operational status |
| 84 | */ |
| 85 | public TeStatus opStatus() { |
| 86 | return opStatus; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Returns the flags in the common node data. |
| 91 | * |
| 92 | * @return the flags |
| 93 | */ |
| 94 | public BitSet flags() { |
| 95 | return flags; |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public int hashCode() { |
| 100 | return Objects.hashCode(name, adminStatus, opStatus, flags); |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public boolean equals(Object object) { |
| 105 | if (this == object) { |
| 106 | return true; |
| 107 | } |
| 108 | if (object instanceof CommonNodeData) { |
| 109 | CommonNodeData that = (CommonNodeData) object; |
| 110 | return Objects.equal(name, that.name) && |
| 111 | Objects.equal(adminStatus, that.adminStatus) && |
| 112 | Objects.equal(opStatus, that.opStatus) && |
| 113 | Objects.equal(flags, that.flags); |
| 114 | } |
| 115 | return false; |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public String toString() { |
| 120 | return MoreObjects.toStringHelper(this) |
| 121 | .add("name", name) |
| 122 | .add("adminStatus", adminStatus) |
| 123 | .add("opStatus", opStatus) |
| 124 | .add("flags", flags) |
| 125 | .toString(); |
| 126 | } |
| 127 | } |