Introduce top-level pom file.
[mdsal.git] / binding / mdsal-binding-java-api-generator / src / main / java / org / opendaylight / yangtools / sal / java / api / generator / BigDecimalRangeGenerator.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.sal.java.api.generator;
9
10 import java.math.BigDecimal;
11 import java.math.BigInteger;
12
13 final class BigDecimalRangeGenerator extends AbstractBigRangeGenerator<BigDecimal> {
14     BigDecimalRangeGenerator() {
15         super(BigDecimal.class);
16     }
17
18     @Override
19     protected String format(final BigDecimal value) {
20         if (BigDecimal.ZERO.equals(value)) {
21             return "java.math.BigDecimal.ZERO";
22         }
23         if (BigDecimal.ONE.equals(value)) {
24             return "java.math.BigDecimal.ONE";
25         }
26         if (BigDecimal.TEN.equals(value)) {
27             return "java.math.BigDecimal.TEN";
28         }
29
30         // FIXME: can we do something better?
31         return "new java.math.BigDecimal(\"" + value + "\")";
32     }
33
34     @Override
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());
44         } else {
45             return BigDecimal.valueOf(value.longValue());
46         }
47     }
48 }