Here you can find the source of getRank(Class aNumberClass)
Parameter | Description |
---|---|
aNumberClass | a Class derived from Number, or Number.class itself. |
public static int getRank(Class aNumberClass)
//package com.java2s; /******************************************************************************* * Copyright 2000, 2006 Visual Systems Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License version 2 * which accompanies this distribution in a file named "COPYING". * /* w w w. ja v a 2 s . co m*/ * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *******************************************************************************/ import java.util.HashMap; import java.util.Map; public class Main { /** Key is a Number Class, Value is an Integer indicating rank. */ private static final Map<Class<?>, Integer> NUMBER_RANK_MAP = new HashMap<Class<?>, Integer>(); /** * Gets the ordinal type rank of the given Number Class. The rank can be used to determine type promotion. * The following Number types are supported: * BigDecimal, BigInteger, Byte, Double, Float, Integer, Long, Short, Number. Number is supported as an * abstract type. It has the highest rank. * * @param aNumberClass a Class derived from Number, or Number.class itself. * * @return the rank of the Number type. Zero is the lowest rank, positive numbers indicate * higher rank. */ public static int getRank(Class aNumberClass) { Integer rank = (Integer) NUMBER_RANK_MAP.get(aNumberClass); assert rank != null; return rank.intValue(); } }