Sho SHIMIZU | f01fe1c | 2016-05-02 14:41:18 -0700 | [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 | */ |
Sho SHIMIZU | eeef6f4 | 2016-05-26 11:53:17 -0700 | [diff] [blame] | 16 | package org.onosproject.store.resource.impl; |
Sho SHIMIZU | f01fe1c | 2016-05-02 14:41:18 -0700 | [diff] [blame] | 17 | |
| 18 | import com.google.common.annotations.Beta; |
| 19 | import org.onlab.packet.MplsLabel; |
Sho SHIMIZU | eeef6f4 | 2016-05-26 11:53:17 -0700 | [diff] [blame] | 20 | import org.onosproject.net.resource.DiscreteResourceCodec; |
Sho SHIMIZU | f01fe1c | 2016-05-02 14:41:18 -0700 | [diff] [blame] | 21 | |
Sho SHIMIZU | f01fe1c | 2016-05-02 14:41:18 -0700 | [diff] [blame] | 22 | /** |
| 23 | * Codec for MplsLabel. |
| 24 | */ |
| 25 | @Beta |
Sho SHIMIZU | 59512bf | 2016-06-01 11:30:58 -0700 | [diff] [blame] | 26 | final class MplsLabelCodec implements DiscreteResourceCodec<MplsLabel> { |
Sho SHIMIZU | f01fe1c | 2016-05-02 14:41:18 -0700 | [diff] [blame] | 27 | @Override |
Sho SHIMIZU | cf98b1a | 2016-05-18 15:11:31 -0700 | [diff] [blame] | 28 | public int encode(MplsLabel resource) { |
| 29 | return resource.toInt(); |
Sho SHIMIZU | f01fe1c | 2016-05-02 14:41:18 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | @Override |
Sho SHIMIZU | cf98b1a | 2016-05-18 15:11:31 -0700 | [diff] [blame] | 33 | public MplsLabel decode(int value) { |
| 34 | return MplsLabel.mplsLabel(value); |
Sho SHIMIZU | f01fe1c | 2016-05-02 14:41:18 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | @Override |
| 38 | public boolean equals(Object obj) { |
| 39 | if (obj == this) { |
| 40 | return true; |
| 41 | } |
| 42 | |
| 43 | if (obj == null || getClass() != obj.getClass()) { |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | return true; |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public int hashCode() { |
Sho SHIMIZU | 59512bf | 2016-06-01 11:30:58 -0700 | [diff] [blame] | 52 | return MplsLabelCodec.class.hashCode(); |
Sho SHIMIZU | f01fe1c | 2016-05-02 14:41:18 -0700 | [diff] [blame] | 53 | } |
| 54 | } |