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.yangtools.yang.parser.stmt.rfc6020;
10 import com.google.common.base.Splitter;
11 import java.math.BigDecimal;
12 import org.opendaylight.yangtools.yang.model.api.stmt.UnresolvedNumber;
15 * Utility class for manipulating YANG base and extended types implementation.
17 public final class TypeUtils {
18 public static final Splitter PIPE_SPLITTER = Splitter.on('|').trimResults();
19 public static final Splitter TWO_DOTS_SPLITTER = Splitter.on("..").trimResults();
21 // these objects are to compare whether range has MAX or MIN value
22 // none of these values should appear as Yang number according to spec so they are safe to use
23 private static final BigDecimal YANG_MIN_NUM = BigDecimal.valueOf(-Double.MAX_VALUE);
24 private static final BigDecimal YANG_MAX_NUM = BigDecimal.valueOf(Double.MAX_VALUE);
29 private static BigDecimal yangConstraintToBigDecimal(final Number number) {
30 if (UnresolvedNumber.max().equals(number)) {
33 if (UnresolvedNumber.min().equals(number)) {
37 return new BigDecimal(number.toString());
40 public static int compareNumbers(final Number n1, final Number n2) {
41 final BigDecimal num1 = yangConstraintToBigDecimal(n1);
42 final BigDecimal num2 = yangConstraintToBigDecimal(n2);
43 return new BigDecimal(num1.toString()).compareTo(new BigDecimal(num2.toString()));