2 * Copyright (c) 2010-2024 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.denonmarantz.internal.xml.adapters;
15 import static org.openhab.binding.denonmarantz.internal.DenonMarantzBindingConstants.DB_OFFSET;
17 import java.math.BigDecimal;
19 import javax.xml.bind.annotation.adapters.XmlAdapter;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
25 * Maps Denon volume values in db to percentage
27 * @author Jeroen Idserda - Initial contribution
30 public class VolumeAdapter extends XmlAdapter<@Nullable String, BigDecimal> {
33 public BigDecimal unmarshal(@Nullable String v) throws Exception {
34 if (v != null && !"--".equals(v.trim())) {
35 return new BigDecimal(v.trim()).add(DB_OFFSET);
38 return BigDecimal.ZERO;
42 public @Nullable String marshal(BigDecimal v) throws Exception {
43 if (v.equals(BigDecimal.ZERO)) {
47 return v.subtract(DB_OFFSET).toString();