blob: 70defa13ae0bb6d46f5f745d9fdf6eeae854128a [file] [log] [blame]
Sho SHIMIZUf01fe1c2016-05-02 14:41:18 -07001/*
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 SHIMIZUeeef6f42016-05-26 11:53:17 -070016package org.onosproject.store.resource.impl;
Sho SHIMIZUf01fe1c2016-05-02 14:41:18 -070017
18import com.google.common.annotations.Beta;
19import org.onlab.packet.VlanId;
Sho SHIMIZUeeef6f42016-05-26 11:53:17 -070020import org.onosproject.net.resource.DiscreteResourceCodec;
Sho SHIMIZUf01fe1c2016-05-02 14:41:18 -070021
Sho SHIMIZUf01fe1c2016-05-02 14:41:18 -070022/**
23 * Codec for Vlan.
24 */
25@Beta
Sho SHIMIZU59512bf2016-06-01 11:30:58 -070026final class VlanIdCodec implements DiscreteResourceCodec<VlanId> {
Sho SHIMIZUf01fe1c2016-05-02 14:41:18 -070027 @Override
Sho SHIMIZUcf98b1a2016-05-18 15:11:31 -070028 public int encode(VlanId resource) {
29 return resource.toShort();
Sho SHIMIZUf01fe1c2016-05-02 14:41:18 -070030 }
31
32 @Override
Sho SHIMIZUcf98b1a2016-05-18 15:11:31 -070033 public VlanId decode(int value) {
34 return VlanId.vlanId((short) value);
Sho SHIMIZUf01fe1c2016-05-02 14:41:18 -070035 }
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 SHIMIZU59512bf2016-06-01 11:30:58 -070052 return VlanIdCodec.class.hashCode();
Sho SHIMIZUf01fe1c2016-05-02 14:41:18 -070053 }
54}