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
017public final class Utils {
018    private Utils() {
019        throw new IllegalStateException("Utility class");
020    }
021
022    /**
023     * Retrieves the Java Runtime Class of the given Object. B = byte array, S = short array, I = int
024     * array, J = long array, F = float array, D = double array, L = class or interface
025     *
026     * @param o
027     *            the Object to determine the Runtime Class of
028     * @return the Java Runtime Class of the given Object.
029     */
030    public static char getJavaObjectRuntimeClass(Object o) {
031        if (o == null)
032            return ' ';
033
034        String cName = o.getClass().getName();
035
036        if (cName.equals("java.lang.String") || cName.equals("java.util.Vector")
037                || cName.equals("java.util.Arrays$ArrayList") || cName.equals("java.util.ArrayList"))
038            return 'L';
039
040        int cIndex = cName.lastIndexOf('[');
041        if (cIndex >= 0) {
042            return cName.charAt(cIndex + 1);
043        }
044
045        return ' ';
046    }
047
048}