01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: ClassUtils.java 3704 2007-03-20 10:46:55Z gbevin $
07: */
08: package com.uwyn.rife.tools;
09:
10: import java.util.Date;
11:
12: public abstract class ClassUtils {
13: public static boolean isNumeric(Class klass) {
14: if (Number.class.isAssignableFrom(klass) || byte.class == klass
15: || short.class == klass || int.class == klass
16: || long.class == klass || float.class == klass
17: || double.class == klass) {
18: return true;
19: }
20:
21: return false;
22: }
23:
24: public static boolean isText(Class klass) {
25: if (CharSequence.class.isAssignableFrom(klass)
26: || Character.class == klass || char.class == klass) {
27: return true;
28: }
29:
30: return false;
31: }
32:
33: public static boolean isBasic(Class klass) {
34: if (null == klass) {
35: return false;
36: }
37:
38: if (isNumeric(klass) || boolean.class == klass
39: || Boolean.class == klass
40: || Date.class.isAssignableFrom(klass) || klass.isEnum()
41: || isText(klass)) {
42: return true;
43: }
44:
45: return false;
46: }
47:
48: public static String simpleClassName(Class klass) {
49: String class_name = klass.getName();
50: if (klass.getPackage() != null) {
51: class_name = class_name.substring(klass.getPackage()
52: .getName().length() + 1);
53: }
54:
55: return class_name;
56: }
57:
58: public static String shortenClassName(Class klass) {
59: return simpleClassName(klass).replace('$', '_').toLowerCase();
60: }
61:
62: public static String[] getEnumClassValues(Class klass) {
63: if (JavaSpecificationUtils.isAtLeastJdk15() && klass.isEnum()) {
64: Object[] values = klass.getEnumConstants();
65: return ArrayUtils.createStringArray(values);
66: }
67:
68: return null;
69: }
70: }
|