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 java.util.List; |
| 19 | |
| 20 | import org.onosproject.tetopology.management.api.KeyId; |
| 21 | |
| 22 | import com.google.common.base.MoreObjects; |
| 23 | import com.google.common.base.Objects; |
| 24 | |
| 25 | /** |
| 26 | * Represent a termination point. |
| 27 | * <p> |
| 28 | * The Set/Get methods below are defined to accept and pass references because |
| 29 | * the object class is treated as a "composite" object class that holds |
| 30 | * references to various member objects and their relationships, forming a |
| 31 | * data tree. Internal routines of the TE topology manager may use the |
| 32 | * following example methods to construct and manipulate any piece of data in |
| 33 | * the data tree: |
| 34 | *<pre> |
| 35 | * newNode.getTe().setAdminStatus(), or |
| 36 | * newNode.getSupportingNodeIds().add(nodeId), etc. |
| 37 | *</pre> |
| 38 | * Same for constructors where, for example, a child list may be constructed |
| 39 | * first and passed in by reference to its parent object constructor. |
| 40 | */ |
| 41 | public class DefaultTerminationPoint implements TerminationPoint { |
| 42 | private KeyId id; |
| 43 | private List<TerminationPointKey> supportingTpIds; |
| 44 | private TeTerminationPoint te; |
| 45 | |
| 46 | /** |
| 47 | * Creates an instance of DefaultTerminationPoint. |
| 48 | * |
| 49 | * @param id termination point identifier |
| 50 | * @param tps support termination point identifier |
| 51 | * @param te te parameters of the terminiation point |
| 52 | */ |
| 53 | public DefaultTerminationPoint(KeyId id, List<TerminationPointKey> tps, |
| 54 | TeTerminationPoint te) { |
| 55 | this.id = id; |
| 56 | this.supportingTpIds = tps; |
| 57 | this.te = te; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Creates an instance of DefaultTerminationPoint with teTpId only. |
| 62 | * |
| 63 | * @param id termination point identifier |
| 64 | */ |
| 65 | public DefaultTerminationPoint(KeyId id) { |
| 66 | this.id = id; |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public KeyId id() { |
| 71 | return id; |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public List<TerminationPointKey> getSupportingTpIds() { |
| 76 | return supportingTpIds; |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public TeTerminationPoint getTe() { |
| 81 | return te; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Sets the Id. |
| 86 | * |
| 87 | * @param id the id to set |
| 88 | */ |
| 89 | public void setId(KeyId id) { |
| 90 | this.id = id; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Sets the supportingTpIds. |
| 95 | * |
| 96 | * @param tps the supportingTpIds to set |
| 97 | */ |
| 98 | public void setSupportingTpIds(List<TerminationPointKey> tps) { |
| 99 | this.supportingTpIds = tps; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Sets the te extension. |
| 104 | * |
| 105 | * @param te the te to set |
| 106 | */ |
| 107 | public void setTe(TeTerminationPoint te) { |
| 108 | this.te = te; |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public int hashCode() { |
| 113 | return Objects.hashCode(id, supportingTpIds, te); |
| 114 | } |
| 115 | |
| 116 | @Override |
| 117 | public boolean equals(Object object) { |
| 118 | if (this == object) { |
| 119 | return true; |
| 120 | } |
| 121 | if (object instanceof DefaultTerminationPoint) { |
| 122 | DefaultTerminationPoint that = (DefaultTerminationPoint) object; |
| 123 | return Objects.equal(this.id, that.id) && |
| 124 | Objects.equal(this.supportingTpIds, that.supportingTpIds) && |
| 125 | Objects.equal(this.te, that.te); |
| 126 | } |
| 127 | return false; |
| 128 | } |
| 129 | |
| 130 | @Override |
| 131 | public String toString() { |
| 132 | return MoreObjects.toStringHelper(this) |
| 133 | .add("id", id) |
| 134 | .add("supportingTpIds", supportingTpIds) |
| 135 | .add("te", te) |
| 136 | .toString(); |
| 137 | } |
| 138 | |
| 139 | } |