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 + "\")";
35 protected BigDecimal convert(final Number value) {
36 if (value instanceof BigInteger) {
37 return new BigDecimal((BigInteger)value);
38 } else if (value instanceof Byte) {
39 return new BigDecimal(value.intValue());
40 } else if (value instanceof Short) {
41 return new BigDecimal(value.intValue());
42 } else if (value instanceof Integer) {
43 return new BigDecimal(value.intValue());
45 return BigDecimal.valueOf(value.longValue());