001/*****************************************************************************
002 * Copyright by The HDF Group.                                               *
003 * Copyright by the Board of Trustees of the University of Illinois.         *
004 * All rights reserved.                                                      *
005 *                                                                           *
006 * This file is part of the HDF Java Products distribution.                  *
007 * The full copyright notice, including terms governing use, modification,   *
008 * and redistribution, is contained in the files COPYING and Copyright.html. *
009 * COPYING can be found at the root of the source code distribution tree.    *
010 * Or, see https://support.hdfgroup.org/products/licenses.html               *
011 * If you do not have access to either file, you may request a copy from     *
012 * help@hdfgroup.org.                                                        *
013 ****************************************************************************/
014
015package hdf.object;
016
017/** General utility class */
018public final class Utils {
019    private Utils() {
020        throw new IllegalStateException("Utility class");
021    }
022
023    /**
024     * Retrieves the Java Runtime Class of the given Object. B = byte array, S = short array, I = int
025     * array, J = long array, F = float array, D = double array, L = class or interface
026     *
027     * @param o
028     *            the Object to determine the Runtime Class of
029     * @return the Java Runtime Class of the given Object.
030     */
031    public static char getJavaObjectRuntimeClass(Object o) {
032        if (o == null)
033            return ' ';
034
035        String cName = o.getClass().getName();
036
037        if (cName.equals("java.lang.String") || cName.equals("java.util.Vector")
038                || cName.equals("java.util.Arrays$ArrayList") || cName.equals("java.util.ArrayList"))
039            return 'L';
040
041        int cIndex = cName.lastIndexOf('[');
042        if (cIndex >= 0) {
043            return cName.charAt(cIndex + 1);
044        }
045
046        return ' ';
047    }
048
049}