Cleanup use of Guava library
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / codec / Uint64StringCodec.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.math.BigInteger;
12 import java.util.Objects;
13 import java.util.Optional;
14 import org.opendaylight.yangtools.yang.data.api.codec.Uint64Codec;
15 import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
16
17 final class Uint64StringCodec extends AbstractIntegerStringCodec<BigInteger, UnsignedIntegerTypeDefinition> implements
18         Uint64Codec<String> {
19
20     Uint64StringCodec(final Optional<UnsignedIntegerTypeDefinition> typeDef) {
21         super(typeDef, extractRange(typeDef.orElse(null)), BigInteger.class);
22     }
23
24     @Override
25     BigInteger deserialize(final String stringRepresentation, final int base) {
26         return new BigInteger(stringRepresentation, base);
27     }
28
29     @Override
30     public String serialize(final BigInteger data) {
31         return Objects.toString(data, "");
32     }
33
34     @Override
35     BigInteger convertValue(final Number value) {
36         if (value instanceof BigInteger) {
37             return (BigInteger) value;
38         }
39         return BigInteger.valueOf(value.longValue());
40     }
41 }