2 * Copyright (c) 2010-2023 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;
22 * Maps Denon volume values in db to percentage
24 * @author Jeroen Idserda - Initial contribution
26 public class VolumeAdapter extends XmlAdapter<String, BigDecimal> {
29 public BigDecimal unmarshal(String v) throws Exception {
30 if (v != null && !v.trim().equals("--")) {
31 return new BigDecimal(v.trim()).add(DB_OFFSET);
34 return BigDecimal.ZERO;
38 public String marshal(BigDecimal v) throws Exception {
39 if (v.equals(BigDecimal.ZERO)) {
43 return v.subtract(DB_OFFSET).toString();