9bb55a291bd781b27307d6074c71add6a5cea7e7
[mdsal.git] / binding / mdsal-binding-java-api-generator / src / main / java / org / opendaylight / mdsal / binding / java / api / generator / BigIntegerRangeGenerator.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.mdsal.binding.java.api.generator;
9
10 import java.math.BigInteger;
11
12 final class BigIntegerRangeGenerator extends AbstractBigRangeGenerator<BigInteger> {
13     BigIntegerRangeGenerator() {
14         super(BigInteger.class);
15     }
16
17     @Override
18     protected String format(final BigInteger value) {
19         if (BigInteger.ZERO.equals(value)) {
20             return "java.math.BigInteger.ZERO";
21         }
22         if (BigInteger.ONE.equals(value)) {
23             return "java.math.BigInteger.ONE";
24         }
25         if (BigInteger.TEN.equals(value)) {
26             return "java.math.BigInteger.TEN";
27         }
28
29         // Check for conversion to long
30         final long l = value.longValue();
31         if (value.equals(BigInteger.valueOf(l))) {
32             return "java.math.BigInteger.valueOf(" + l + "L)";
33         }
34
35         return "new java.math.BigInteger(\"" + value.toString() + "\")";
36     }
37
38     @Override
39     @Deprecated
40     protected BigInteger convert(final Number value) {
41         return BigInteger.valueOf(value.longValue());
42     }
43 }