View Javadoc

1   /***
2    * 
3    */
4   package ar.com.epere4.util.lang;
5   
6   import java.util.Calendar;
7   import java.util.Date;
8   
9   /***
10   * A class with some utils for Java data types.
11   * 
12   * @author epere4
13   * @since 20/02/2006
14   */
15  public final class Types {
16  
17      /***
18       * Do not allow instances.
19       * 
20       * @since 20/02/2006
21       */
22      private Types() {
23  
24      }
25  
26      /***
27       * 
28       * @param obj
29       *            the object to evaluate.
30       * @return true if the object is an instance of one of the natural java
31       *         types: {@link Number}, {@link String}, {@link Date},
32       *         {@link Calendar}, {@link Boolean} or {@link Character}.
33       * @since 20/02/2006
34       */
35      public static boolean isNaturalJavaObject(final Object obj) {
36          return obj instanceof Number || obj instanceof String
37                  || obj instanceof Date || obj instanceof Calendar
38                  || obj instanceof Boolean || obj instanceof Character;
39      }
40  
41      /***
42       * 
43       * @param clazz
44       *            the class to evaluate.
45       * @return true if the clazz is the same or a subclass of one of the natural
46       *         java types: {@link Number}, {@link String}, {@link Date},
47       *         {@link Calendar}, {@link Boolean} or {@link Character}.
48       * @since 20/02/2006
49       */
50      public static boolean isNaturalJavaClass(final Class clazz) {
51          return Number.class.isAssignableFrom(clazz)
52                  || String.class.isAssignableFrom(clazz)
53                  || Date.class.isAssignableFrom(clazz)
54                  || Calendar.class.isAssignableFrom(clazz)
55                  || Boolean.class.isAssignableFrom(clazz)
56                  || Character.class.isAssignableFrom(clazz);
57      }
58  
59      /***
60       * @param clazz
61       *            the class to be evaluated.
62       * @return true if the clazz represents any of the primitive java data
63       *         types, except void.
64       * @see Class#isPrimitive()
65       * @since 20/02/2006
66       */
67      public static boolean isNativeJavaPrimitive(final Class clazz) {
68          return clazz.isPrimitive() && !clazz.equals(Void.TYPE);
69      }
70  }