2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.data.impl.codec;
10 import com.google.common.base.Optional;
11 import org.opendaylight.yangtools.yang.data.api.codec.BooleanCodec;
12 import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
14 class BooleanStringCodec extends TypeDefinitionAwareCodec<Boolean, BooleanTypeDefinition>
15 implements BooleanCodec<String> {
17 protected BooleanStringCodec(final Optional<BooleanTypeDefinition> typeDef) {
18 super(typeDef, Boolean.class);
22 public final String serialize(final Boolean data) {
23 return data == null ? "" : data.toString();
27 public final Boolean deserialize(final String stringRepresentation) {
28 return Boolean.valueOf(stringRepresentation);
31 static TypeDefinitionAwareCodec<?,BooleanTypeDefinition> from(final BooleanTypeDefinition normalizedType) {
32 return new BooleanStringCodec(Optional.fromNullable(normalizedType));