blob: e9b14b91314f8b6292d93d1fc647bcf2de8985ac [file] [log] [blame]
Priyanka B0bee1f82015-10-13 15:39:49 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Priyanka B0bee1f82015-10-13 15:39:49 +05303 *
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
17package org.onosproject.bgpio.types;
18
19import org.jboss.netty.buffer.ChannelBuffer;
20
Priyanka B02040732015-11-29 11:30:29 +053021import com.google.common.base.MoreObjects;
22
Priyanka B0bee1f82015-10-13 15:39:49 +053023/**
24 * Implementation of RouteDistinguisher.
25 */
Priyanka B02040732015-11-29 11:30:29 +053026public class RouteDistinguisher implements Comparable<RouteDistinguisher> {
Priyanka B0bee1f82015-10-13 15:39:49 +053027
28 private long routeDistinguisher;
29
30 /**
31 * Resets fields.
32 */
33 public RouteDistinguisher() {
34 this.routeDistinguisher = 0;
35 }
36
37 /**
38 * Constructor to initialize parameters.
39 *
40 * @param routeDistinguisher route distinguisher
41 */
42 public RouteDistinguisher(long routeDistinguisher) {
43 this.routeDistinguisher = routeDistinguisher;
44 }
45
46 /**
47 * Reads route distinguisher from channelBuffer.
48 *
49 * @param cb channelBuffer
50 * @return object of RouteDistinguisher
51 */
52 public static RouteDistinguisher read(ChannelBuffer cb) {
53 return new RouteDistinguisher(cb.readLong());
54 }
55
56 /**
57 * Returns route distinguisher.
58 *
59 * @return route distinguisher
60 */
61 public long getRouteDistinguisher() {
62 return this.routeDistinguisher;
63 }
Priyanka B02040732015-11-29 11:30:29 +053064
65 @Override
66 public int compareTo(RouteDistinguisher rd) {
67 if (this.equals(rd)) {
68 return 0;
69 }
70 return ((Long) (this.getRouteDistinguisher())).compareTo((Long) (rd.getRouteDistinguisher()));
71 }
72
73 @Override
Ray Milkey676249c2015-12-18 09:27:03 -080074 public boolean equals(Object obj) {
75 if (this == obj) {
76 return true;
77 }
78
79 if (obj instanceof RouteDistinguisher) {
80
81 RouteDistinguisher that = (RouteDistinguisher) obj;
82
83 if (this.routeDistinguisher == that.routeDistinguisher) {
84 return true;
85 }
86 }
87
88 return false;
89 }
90
91 @Override
92 public int hashCode() {
93 return Long.hashCode(routeDistinguisher);
94 }
95
96 @Override
Priyanka B02040732015-11-29 11:30:29 +053097 public String toString() {
98 return MoreObjects.toStringHelper(getClass())
99 .add("routeDistinguisher", routeDistinguisher)
100 .toString();
101 }
Ray Milkey676249c2015-12-18 09:27:03 -0800102}