Shashikanth VH | 26fd38a | 2016-04-26 18:11:37 +0530 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2016-present 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.protocol.flowspec; |
| 18 | |
| 19 | import java.util.Objects; |
| 20 | import org.slf4j.Logger; |
| 21 | import org.slf4j.LoggerFactory; |
| 22 | |
| 23 | import com.google.common.base.MoreObjects; |
| 24 | |
| 25 | /** |
| 26 | * Provides BGP flow specification route index. |
| 27 | */ |
| 28 | public class BgpFlowSpecRouteKey implements Comparable<Object> { |
| 29 | |
| 30 | private static final Logger log = LoggerFactory.getLogger(BgpFlowSpecRouteKey.class); |
| 31 | |
| 32 | private final String routeKey; |
| 33 | |
| 34 | /** |
| 35 | * Constructor to initialize parameters. |
| 36 | * |
| 37 | * @param routeKey route key |
| 38 | */ |
| 39 | public BgpFlowSpecRouteKey(String routeKey) { |
| 40 | this.routeKey = routeKey; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Returns route key. |
| 45 | * |
| 46 | * @return route key |
| 47 | */ |
| 48 | public String routeKey() { |
| 49 | return this.routeKey; |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public int hashCode() { |
| 54 | return Objects.hashCode(routeKey); |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public boolean equals(Object obj) { |
| 59 | if (this == obj) { |
| 60 | return true; |
| 61 | } |
| 62 | if (obj instanceof BgpFlowSpecRouteKey) { |
| 63 | BgpFlowSpecRouteKey other = (BgpFlowSpecRouteKey) obj; |
| 64 | return this.routeKey.equals(other.routeKey); |
| 65 | } |
| 66 | return false; |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public int compareTo(Object o) { |
| 71 | if (this.equals(o)) { |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | if (o instanceof BgpFlowSpecRouteKey) { |
| 76 | BgpFlowSpecRouteKey other = (BgpFlowSpecRouteKey) o; |
| 77 | if (this.routeKey.compareTo(other.routeKey) != 0) { |
| 78 | return this.routeKey.compareTo(other.routeKey); |
| 79 | } |
| 80 | return 0; |
| 81 | } |
| 82 | return 1; |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public String toString() { |
| 87 | return MoreObjects.toStringHelper(getClass()).omitNullValues() |
| 88 | .add("routeKey", routeKey) |
| 89 | .toString(); |
| 90 | } |
| 91 | } |