Cleanup use of Guava library
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / codec / Int8StringCodec.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.yangtools.yang.data.impl.codec;
10
11 import java.util.Objects;
12 import java.util.Optional;
13 import org.opendaylight.yangtools.yang.data.api.codec.Int8Codec;
14 import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
15
16 final class Int8StringCodec extends AbstractIntegerStringCodec<Byte, IntegerTypeDefinition>
17         implements Int8Codec<String> {
18
19     Int8StringCodec(final Optional<IntegerTypeDefinition> typeDef) {
20         super(typeDef, extractRange(typeDef.orElse(null)), Byte.class);
21     }
22
23     @Override
24     Byte deserialize(final String stringRepresentation, final int base) {
25         return Byte.valueOf(stringRepresentation, base);
26     }
27
28     @Override
29     public String serialize(final Byte data) {
30         return Objects.toString(data, "");
31     }
32
33     @Override
34     Byte convertValue(final Number value) {
35         return value.byteValue();
36     }
37 }