feba81f33782d92fa608b09e599700c9941482de
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / codec / Uint32StringCodec.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 com.google.common.base.Optional;
12 import java.util.Objects;
13 import org.opendaylight.yangtools.yang.data.api.codec.Uint32Codec;
14 import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
15
16 final class Uint32StringCodec extends AbstractIntegerStringCodec<Long, UnsignedIntegerTypeDefinition> implements
17         Uint32Codec<String> {
18
19     Uint32StringCodec(final Optional<UnsignedIntegerTypeDefinition> typeDef) {
20         super(typeDef, extractRange(typeDef.orNull()), Long.class);
21     }
22
23     @Override
24     Long deserialize(final String stringRepresentation, final int base) {
25         return Long.valueOf(stringRepresentation, base);
26     }
27
28     @Override
29     public String serialize(final Long data) {
30         return Objects.toString(data, "");
31     }
32
33     @Override
34     Long convertValue(final Number value) {
35         return value.longValue();
36     }
37 }