blob: 12f0c79b8c4f92869d69084916f182e619be4d91 [file] [log] [blame]
Sho SHIMIZUc0e010dd2016-05-02 14:46:22 -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 */
16package org.onosproject.net.resource;
17
18/**
19 * Represents no-op codec intended to used in an empty discrete resource set only.
20 * It's not supposed to be used by other classes.
21 */
Sho SHIMIZUcf98b1a2016-05-18 15:11:31 -070022public class NoOpCodec implements DiscreteResourceCodec<Object> {
Sho SHIMIZUc0e010dd2016-05-02 14:46:22 -070023 public static final DiscreteResourceCodec INSTANCE = new NoOpCodec();
24
25 @Override
Sho SHIMIZUcf98b1a2016-05-18 15:11:31 -070026 public int encode(Object resource) {
Sho SHIMIZUc0e010dd2016-05-02 14:46:22 -070027 return 0;
28 }
29
30 @Override
Sho SHIMIZUcf98b1a2016-05-18 15:11:31 -070031 public Object decode(int value) {
Sho SHIMIZUc0e010dd2016-05-02 14:46:22 -070032 return Resource.ROOT;
33 }
34
35 @Override
36 public boolean equals(Object obj) {
37 if (obj == this) {
38 return true;
39 }
40
41 if (obj == null || getClass() != obj.getClass()) {
42 return false;
43 }
44
45 return true;
46 }
47
48 @Override
49 public int hashCode() {
50 return NoOpCodec.class.hashCode();
51 }
52}