/*\
* Copyright 2006 Klaus Rogall, Hamburg, Germany (klaus.rogall@web.de). All rights reserved.
* _____________________________________________________________________________________________________________________
*
* This class is "Open Source" as defined by the Open Source Initiative (OSI). You can redistribute it and/or modify it
* under the terms of the BSD License. The license text is appended to the end of this file.
\*/
package de.klaro.base.util;
/**
* Methoden zur Manupulation und Verarbeitung von Klassen.
*/
public class Classes extends Object
{
/* ______________________________________________________________________________________________________________ *\
\* Konstanten */
/* ______________________________________________________________________________________________________________ *\
\* Klassenvariablen */
/* ______________________________________________________________________________________________________________ *\
\* Instanzvariablen */
/* ______________________________________________________________________________________________________________ *\
\* Konstruktoren */
/**
* Erzeugt eine Instanz dieser Klasse.
*
* Da verhindert werden soll, dass Instanzen dieser Klasse ausserhalb dieser Klasse erzeugt werdem, ist dieser
* Konstruktor 'private' deklariert.
*/
private Classes()
{
super();
}
/* ______________________________________________________________________________________________________________ *\
\* Instanzmethoden */
/* ______________________________________________________________________________________________________________ *\
\* Klassenmethoden */
/**
* Prft, ob ein Typname zu einem primitiven Datentyp ('boolean', 'character', 'byte', 'short', 'integer', 'long',
* 'float', 'double' oder 'void') gehrt.
*
* @param typeName Der Name des Typs
* @return Der Typ ist ein primitiver Datentyp
* @see Boolean#TYPE
* @see Character#TYPE
* @see Byte#TYPE
* @see Short#TYPE
* @see Integer#TYPE
* @see Long#TYPE
* @see Float#TYPE
* @see Double#TYPE
* @see Void#TYPE
*/
public static boolean isPrimitive(String typeName)
{
if (Boolean.TYPE.getName().equals(typeName))
return true;
if (Character.TYPE.getName().equals(typeName))
return true;
if (Byte.TYPE.getName().equals(typeName))
return true;
if (Short.TYPE.getName().equals(typeName))
return true;
if (Integer.TYPE.getName().equals(typeName))
return true;
if (Long.TYPE.getName().equals(typeName))
return true;
if (Float.TYPE.getName().equals(typeName))
return true;
if (Double.TYPE.getName().equals(typeName))
return true;
if (Void.TYPE.getName().equals(typeName))
return true;
return false;
}
/**
* Liefert den Packagenamen der angegebenen Klasse.
*
* @param clazz Die Klasse
* @return Der Packagename der Klasse
*/
public static String packageOf(Class<?> clazz)
{
return (clazz.isPrimitive())? clazz.getName(): clazz.getPackage().getName();
}
/**
* Liefert den Packagenamen der angegebenen Instanz.
*
* @param object Die Instanz
* @return Der Packagename der Klasse
*/
public static String packageOf(Object object)
{
return packageOf(object.getClass());
}
/**
* Liefert den Klassennamen (ohne Packagenamen) der angegebenen Klasse.
*
* @param clazz Die Klasse
* @return Der Klassennamen (ohne Packagenamen) der Klasse
*/
public static String nameOf(Class<?> clazz)
{
return Strings.baseOf(clazz.getName(),'.').replace('$','.');
}
/**
* Liefert den Klassennamen (ohne Packagenamen) der angegebenen Instanz.
*
* @param object Die Instanz
* @return Der Klassennamen (ohne Packagenamen) der Klasse
*/
public static String nameOf(Object object)
{
return nameOf(object.getClass());
}
/* ______________________________________________________________________________________________________________ *\
\* Klassen */
}
/*\
* _____________________________________________________________________________________________________________________
*
* This software is distributed under the terms of the BSD License:
*
* Copyright 2006 Klaus Rogall, Hamburg, Germany (klaus.rogall@web.de). All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice, this list of conditions and the following
* disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided with the distribution.
* - Neither the name of the Klaus Rogall nor the names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* _____________________________________________________________________________________________________________________
\*/