blob: e5158f74705329b295ca525211a82efd32225303 [file] [log] [blame]
Aihua Guo1ce2dd12016-08-12 23:37:44 -04001/*
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 */
16package org.onosproject.tetopology.management.api.link;
17
18import com.google.common.base.MoreObjects;
19import com.google.common.base.Objects;
20
21/**
Henry Yu4b4a7eb2016-11-09 20:07:53 -050022 * Representation of a path element.
Aihua Guo1ce2dd12016-08-12 23:37:44 -040023 */
24public class PathElement {
25 private final long pathElementId;
Henry Yu4b4a7eb2016-11-09 20:07:53 -050026 private final long teNodeId;
Aihua Guo1ce2dd12016-08-12 23:37:44 -040027 private final ElementType type;
Henry Yu4b4a7eb2016-11-09 20:07:53 -050028 private final boolean loose;
Aihua Guo1ce2dd12016-08-12 23:37:44 -040029
30 /**
Henry Yu4b4a7eb2016-11-09 20:07:53 -050031 * Creates a path element.
Aihua Guo1ce2dd12016-08-12 23:37:44 -040032 *
33 * @param pathElementId path element identifier
Henry Yu4b4a7eb2016-11-09 20:07:53 -050034 * @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 Guo1ce2dd12016-08-12 23:37:44 -040038 */
Henry Yu4b4a7eb2016-11-09 20:07:53 -050039 public PathElement(long pathElementId, long teNodeId,
40 ElementType type, boolean loose) {
Aihua Guo1ce2dd12016-08-12 23:37:44 -040041 this.pathElementId = pathElementId;
Henry Yu4b4a7eb2016-11-09 20:07:53 -050042 this.teNodeId = teNodeId;
Aihua Guo1ce2dd12016-08-12 23:37:44 -040043 this.type = type;
Henry Yu4b4a7eb2016-11-09 20:07:53 -050044 this.loose = loose;
Aihua Guo1ce2dd12016-08-12 23:37:44 -040045 }
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 Yu4b4a7eb2016-11-09 20:07:53 -050057 * Returns the TE node identifier.
58 *
59 * @return te node id
60 */
61 public long teNodeId() {
62 return teNodeId;
63 }
64
65 /**
Aihua Guo1ce2dd12016-08-12 23:37:44 -040066 * Returns the path element type.
67 *
68 * @return path element type
69 */
70 public ElementType type() {
71 return type;
72 }
73
Henry Yu4b4a7eb2016-11-09 20:07:53 -050074 /**
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 Guo1ce2dd12016-08-12 23:37:44 -040083 @Override
84 public int hashCode() {
Henry Yu4b4a7eb2016-11-09 20:07:53 -050085 return Objects.hashCode(pathElementId, teNodeId, type, loose);
Aihua Guo1ce2dd12016-08-12 23:37:44 -040086 }
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 Yu4b4a7eb2016-11-09 20:07:53 -050095 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 Guo1ce2dd12016-08-12 23:37:44 -040099 }
100 return false;
101 }
102
103 @Override
104 public String toString() {
105 return MoreObjects.toStringHelper(this)
106 .add("pathElementId", pathElementId)
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500107 .add("teNodeId", teNodeId)
Aihua Guo1ce2dd12016-08-12 23:37:44 -0400108 .add("type", type)
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500109 .add("loose", loose)
Aihua Guo1ce2dd12016-08-12 23:37:44 -0400110 .toString();
111 }
112
113}