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 com.google.common.base.MoreObjects; |
| 19 | import com.google.common.base.Objects; |
| 20 | import com.google.common.collect.ImmutableList; |
| 21 | import com.google.common.collect.Lists; |
| 22 | import org.onosproject.tetopology.management.api.KeyId; |
| 23 | |
| 24 | import java.util.List; |
| 25 | |
| 26 | /** |
| 27 | * The default implementation of TE termination point. |
| 28 | */ |
| 29 | public class DefaultTerminationPoint implements TerminationPoint { |
| 30 | private final KeyId tpId; |
| 31 | private final List<TerminationPointKey> supportingTpIds; |
| 32 | private final Long teTpId; |
| 33 | |
| 34 | /** |
| 35 | * Creates a termination point. |
| 36 | * |
| 37 | * @param tpId termination point identifier |
| 38 | * @param tps support termination point identifier |
| 39 | * @param teTpId TE termination point identifier |
| 40 | */ |
| 41 | public DefaultTerminationPoint(KeyId tpId, |
| 42 | List<TerminationPointKey> tps, |
| 43 | Long teTpId) { |
| 44 | this.tpId = tpId; |
| 45 | this.supportingTpIds = tps != null ? Lists.newArrayList(tps) : null; |
| 46 | this.teTpId = teTpId; |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public KeyId tpId() { |
| 51 | return tpId; |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public Long teTpId() { |
| 56 | return teTpId; |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public List<TerminationPointKey> supportingTpIds() { |
| 61 | if (supportingTpIds == null) { |
| 62 | return null; |
| 63 | } |
| 64 | return ImmutableList.copyOf(supportingTpIds); |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public int hashCode() { |
| 69 | return Objects.hashCode(tpId, supportingTpIds, teTpId); |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public boolean equals(Object object) { |
| 74 | if (this == object) { |
| 75 | return true; |
| 76 | } |
| 77 | if (object instanceof DefaultTerminationPoint) { |
| 78 | DefaultTerminationPoint that = (DefaultTerminationPoint) object; |
| 79 | return Objects.equal(tpId, that.tpId) && |
| 80 | Objects.equal(supportingTpIds, that.supportingTpIds) && |
| 81 | Objects.equal(teTpId, that.teTpId); |
| 82 | } |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public String toString() { |
| 88 | return MoreObjects.toStringHelper(this) |
| 89 | .add("tpId", tpId) |
| 90 | .add("supportingTpIds", supportingTpIds) |
| 91 | .add("teTpId", teTpId) |
| 92 | .toString(); |
| 93 | } |
| 94 | |
| 95 | |
| 96 | } |