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.mdsal.binding.java.api.generator;
10 import java.math.BigDecimal;
11 import java.math.BigInteger;
13 final class BigDecimalRangeGenerator extends AbstractBigRangeGenerator<BigDecimal> {
14 BigDecimalRangeGenerator() {
15 super(BigDecimal.class);
19 protected String format(final BigDecimal value) {
20 if (BigDecimal.ZERO.equals(value)) {
21 return "java.math.BigDecimal.ZERO";
23 if (BigDecimal.ONE.equals(value)) {
24 return "java.math.BigDecimal.ONE";
26 if (BigDecimal.TEN.equals(value)) {
27 return "java.math.BigDecimal.TEN";
30 // FIXME: can we do something better?
31 return "new java.math.BigDecimal(\"" + value + "\")";
36 protected BigDecimal convert(final Number value) {
37 if (value instanceof BigInteger) {
38 return new BigDecimal((BigInteger)value);
39 } else if (value instanceof Byte) {
40 return new BigDecimal(value.intValue());
41 } else if (value instanceof Short) {
42 return new BigDecimal(value.intValue());
43 } else if (value instanceof Integer) {
44 return new BigDecimal(value.intValue());
46 return BigDecimal.valueOf(value.longValue());