Aihua Guo | 1ce2dd1 | 2016-08-12 23:37:44 -0400 | [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 com.google.common.base.MoreObjects; |
| 19 | import com.google.common.base.Objects; |
| 20 | |
| 21 | /** |
| 22 | * Represents node's switching limitations. |
| 23 | */ |
| 24 | public class ConnectivityMatrix { |
| 25 | private final long id; |
| 26 | private TerminationPointKey from; |
| 27 | private TerminationPointKey to; |
| 28 | private boolean isAllowed; |
| 29 | |
| 30 | /** |
| 31 | * Creates an instance of ConnectivityMatrix. |
| 32 | * |
| 33 | * @param id connectivity matrix identifier |
| 34 | * @param from from termination point key |
| 35 | * @param to to termination point key |
| 36 | * @param isAllowed indicate whether this connectivity matrix is useable |
| 37 | */ |
| 38 | public ConnectivityMatrix(long id, TerminationPointKey from, |
| 39 | TerminationPointKey to, boolean isAllowed) { |
| 40 | this.id = id; |
| 41 | this.from = from; |
| 42 | this.to = to; |
| 43 | this.isAllowed = isAllowed; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Constructor with id only. |
| 48 | * |
| 49 | * @param id connectivity matrix id |
| 50 | */ |
| 51 | public ConnectivityMatrix(long id) { |
| 52 | this.id = id; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Returns the id. |
| 57 | * |
| 58 | * @return connectivity matrix id |
| 59 | */ |
| 60 | public long id() { |
| 61 | return id; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Returns the "from" of a connectivity matrix. |
| 66 | * |
| 67 | * @return the "from" of a connectivity matrix |
| 68 | */ |
| 69 | public TerminationPointKey from() { |
| 70 | return from; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Returns the "to" of a connectivity matrix. |
| 75 | * |
| 76 | * @return the "to" of a connectivity matrix |
| 77 | */ |
| 78 | public TerminationPointKey to() { |
| 79 | return to; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Returns true if the connectivity matrix is allowed; false otherwise. |
| 84 | * |
| 85 | * @return true if the connectivity matrix is allowed; false otherwise |
| 86 | */ |
| 87 | public boolean isAllowed() { |
| 88 | return isAllowed; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Sets the from termination point. |
| 93 | * |
| 94 | * @param from the from to set |
| 95 | */ |
| 96 | public void setFrom(TerminationPointKey from) { |
| 97 | this.from = from; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Sets the to termination point. |
| 102 | * |
| 103 | * @param to the to to set |
| 104 | */ |
| 105 | public void setTo(TerminationPointKey to) { |
| 106 | this.to = to; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Sets isAllowed. |
| 111 | * |
| 112 | * @param isAllowed the isAllowed to set |
| 113 | */ |
| 114 | public void setIsAllowed(boolean isAllowed) { |
| 115 | this.isAllowed = isAllowed; |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public int hashCode() { |
| 120 | return Objects.hashCode(id, from, to, isAllowed); |
| 121 | } |
| 122 | |
| 123 | @Override |
| 124 | public boolean equals(Object object) { |
| 125 | if (this == object) { |
| 126 | return true; |
| 127 | } |
| 128 | if (object instanceof ConnectivityMatrix) { |
| 129 | ConnectivityMatrix that = (ConnectivityMatrix) object; |
| 130 | return Objects.equal(this.id, that.id) && |
| 131 | Objects.equal(this.from, that.from) && |
| 132 | Objects.equal(this.to, that.to) && |
| 133 | Objects.equal(this.isAllowed, that.isAllowed); |
| 134 | } |
| 135 | return false; |
| 136 | } |
| 137 | |
| 138 | @Override |
| 139 | public String toString() { |
| 140 | return MoreObjects.toStringHelper(this) |
| 141 | .add("id", id) |
| 142 | .add("from", from) |
| 143 | .add("to", to) |
| 144 | .add("isAllowed", isAllowed) |
| 145 | .toString(); |
| 146 | } |
| 147 | } |