Priyanka B | 0bee1f8 | 2015-10-13 15:39:49 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | |
| 17 | package org.onosproject.bgpio.types; |
| 18 | |
| 19 | import org.jboss.netty.buffer.ChannelBuffer; |
| 20 | |
Priyanka B | 0204073 | 2015-11-29 11:30:29 +0530 | [diff] [blame] | 21 | import com.google.common.base.MoreObjects; |
| 22 | |
Priyanka B | 0bee1f8 | 2015-10-13 15:39:49 +0530 | [diff] [blame] | 23 | /** |
| 24 | * Implementation of RouteDistinguisher. |
| 25 | */ |
Priyanka B | 0204073 | 2015-11-29 11:30:29 +0530 | [diff] [blame] | 26 | public class RouteDistinguisher implements Comparable<RouteDistinguisher> { |
Priyanka B | 0bee1f8 | 2015-10-13 15:39:49 +0530 | [diff] [blame] | 27 | |
| 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 B | 0204073 | 2015-11-29 11:30:29 +0530 | [diff] [blame] | 64 | |
| 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 Milkey | 676249c | 2015-12-18 09:27:03 -0800 | [diff] [blame] | 74 | 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 B | 0204073 | 2015-11-29 11:30:29 +0530 | [diff] [blame] | 97 | public String toString() { |
| 98 | return MoreObjects.toStringHelper(getClass()) |
| 99 | .add("routeDistinguisher", routeDistinguisher) |
| 100 | .toString(); |
| 101 | } |
Ray Milkey | 676249c | 2015-12-18 09:27:03 -0800 | [diff] [blame] | 102 | } |