Introduce top-level pom file.
[mdsal.git] / code-generator / binding-java-api-generator / src / main / java / org / opendaylight / yangtools / sal / 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.yangtools.sal.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         } else {
34             return "new java.math.BigInteger(\"" + value.toString() + "\")";
35         }
36     }
37
38     @Override
39     protected BigInteger convert(final Number value) {
40         return BigInteger.valueOf(value.longValue());
41     }
42 }