Aihua Guo | 1ce2dd1 | 2016-08-12 23:37:44 -0400 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame^] | 2 | * Copyright 2016 Open Networking Foundation |
Aihua Guo | 1ce2dd1 | 2016-08-12 23:37:44 -0400 | [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 | package org.onosproject.tetopology.management.api.link; |
| 17 | |
| 18 | import com.google.common.base.MoreObjects; |
| 19 | import com.google.common.base.Objects; |
| 20 | |
| 21 | /** |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 22 | * Representation of a path element. |
Aihua Guo | 1ce2dd1 | 2016-08-12 23:37:44 -0400 | [diff] [blame] | 23 | */ |
| 24 | public class PathElement { |
| 25 | private final long pathElementId; |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 26 | private final long teNodeId; |
Aihua Guo | 1ce2dd1 | 2016-08-12 23:37:44 -0400 | [diff] [blame] | 27 | private final ElementType type; |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 28 | private final boolean loose; |
Aihua Guo | 1ce2dd1 | 2016-08-12 23:37:44 -0400 | [diff] [blame] | 29 | |
| 30 | /** |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 31 | * Creates a path element. |
Aihua Guo | 1ce2dd1 | 2016-08-12 23:37:44 -0400 | [diff] [blame] | 32 | * |
| 33 | * @param pathElementId path element identifier |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 34 | * @param teNodeId identifier of the TE node to which this |
| 35 | * path element belongs |
| 36 | * @param type path element type |
| 37 | * @param loose loose if true; strict if false |
Aihua Guo | 1ce2dd1 | 2016-08-12 23:37:44 -0400 | [diff] [blame] | 38 | */ |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 39 | public PathElement(long pathElementId, long teNodeId, |
| 40 | ElementType type, boolean loose) { |
Aihua Guo | 1ce2dd1 | 2016-08-12 23:37:44 -0400 | [diff] [blame] | 41 | this.pathElementId = pathElementId; |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 42 | this.teNodeId = teNodeId; |
Aihua Guo | 1ce2dd1 | 2016-08-12 23:37:44 -0400 | [diff] [blame] | 43 | this.type = type; |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 44 | this.loose = loose; |
Aihua Guo | 1ce2dd1 | 2016-08-12 23:37:44 -0400 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Returns the path element identifier. |
| 49 | * |
| 50 | * @return path element id |
| 51 | */ |
| 52 | public long pathElementId() { |
| 53 | return pathElementId; |
| 54 | } |
| 55 | |
| 56 | /** |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 57 | * Returns the TE node identifier. |
| 58 | * |
| 59 | * @return te node id |
| 60 | */ |
| 61 | public long teNodeId() { |
| 62 | return teNodeId; |
| 63 | } |
| 64 | |
| 65 | /** |
Aihua Guo | 1ce2dd1 | 2016-08-12 23:37:44 -0400 | [diff] [blame] | 66 | * Returns the path element type. |
| 67 | * |
| 68 | * @return path element type |
| 69 | */ |
| 70 | public ElementType type() { |
| 71 | return type; |
| 72 | } |
| 73 | |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 74 | /** |
| 75 | * Returns the loose flag. true = loose; false = strict. |
| 76 | * |
| 77 | * @return loose value |
| 78 | */ |
| 79 | public boolean loose() { |
| 80 | return loose; |
| 81 | } |
| 82 | |
Aihua Guo | 1ce2dd1 | 2016-08-12 23:37:44 -0400 | [diff] [blame] | 83 | @Override |
| 84 | public int hashCode() { |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 85 | return Objects.hashCode(pathElementId, teNodeId, type, loose); |
Aihua Guo | 1ce2dd1 | 2016-08-12 23:37:44 -0400 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public boolean equals(Object object) { |
| 90 | if (this == object) { |
| 91 | return true; |
| 92 | } |
| 93 | if (object instanceof PathElement) { |
| 94 | PathElement that = (PathElement) object; |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 95 | return Objects.equal(pathElementId, that.pathElementId) && |
| 96 | Objects.equal(teNodeId, that.teNodeId) && |
| 97 | Objects.equal(type, that.type) && |
| 98 | Objects.equal(loose, that.loose); |
Aihua Guo | 1ce2dd1 | 2016-08-12 23:37:44 -0400 | [diff] [blame] | 99 | } |
| 100 | return false; |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public String toString() { |
| 105 | return MoreObjects.toStringHelper(this) |
| 106 | .add("pathElementId", pathElementId) |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 107 | .add("teNodeId", teNodeId) |
Aihua Guo | 1ce2dd1 | 2016-08-12 23:37:44 -0400 | [diff] [blame] | 108 | .add("type", type) |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 109 | .add("loose", loose) |
Aihua Guo | 1ce2dd1 | 2016-08-12 23:37:44 -0400 | [diff] [blame] | 110 | .toString(); |
| 111 | } |
| 112 | |
| 113 | } |