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 static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.yang.data.api.codec.BooleanCodec;
15 import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
18 * Do not use this class outside of yangtools, its presence does not fall into the API stability contract.
21 public final class BooleanStringCodec extends TypeDefinitionAwareCodec<Boolean, BooleanTypeDefinition>
22 implements BooleanCodec<String> {
23 private BooleanStringCodec(final @NonNull BooleanTypeDefinition typeDef) {
24 super(typeDef, Boolean.class);
27 public static @NonNull BooleanStringCodec from(final BooleanTypeDefinition normalizedType) {
28 return new BooleanStringCodec(requireNonNull(normalizedType));
32 protected Boolean deserializeImpl(final String product) {
33 // FIXME: should forbid "TRUE" ?
34 if ("true".equalsIgnoreCase(product)) {
36 } else if ("false".equalsIgnoreCase(product)) {
39 throw new IllegalArgumentException("Invalid value '" + product + "' for boolean type. Allowed values are "
40 + "'true' and 'false'");
45 protected String serializeImpl(final Boolean input) {
46 return input.toString();