blob: d91b207c519222b7c943f218d226582c4899a584 [file] [log] [blame]
Sho SHIMIZU9db6da62016-06-01 12:31:21 -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 */
16
17package org.onosproject.store.resource.impl;
18
19import org.onosproject.net.PortNumber;
20import org.onosproject.net.resource.DiscreteResourceCodec;
21
22class PortNumberCodec implements DiscreteResourceCodec<PortNumber> {
23 @Override
24 public int encode(PortNumber resource) {
25 return (int) resource.toLong();
26 }
27
28 @Override
29 public PortNumber decode(int value) {
30 return PortNumber.portNumber(value);
31 }
32
33 @Override
34 public boolean equals(Object obj) {
35 if (obj == this) {
36 return true;
37 }
38
39 if (obj == null || getClass() != obj.getClass()) {
40 return false;
41 }
42
43 return true;
44 }
45
46 @Override
47 public int hashCode() {
48 return PortNumber.class.hashCode();
49 }
50}