Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    private static final Class PRIMITIVE_TYPE_STRING = String.class;
    private static final Class PRIMITIVE_TYPE_INTEGER = int.class;
    private static final Class PRIMITIVE_TYPE_INTEGER_BOXED = Integer.class;
    private static final Class PRIMITIVE_TYPE_LONG = long.class;
    private static final Class PRIMITIVE_TYPE_LONG_BOXED = Long.class;
    private static final Class PRIMITIVE_TYPE_FLOAT = float.class;
    private static final Class PRIMITIVE_TYPE_FLOAT_BOXED = Float.class;
    private static final Class PRIMITIVE_TYPE_DOUBLE = double.class;
    private static final Class PRIMITIVE_TYPE_DOUBLE_BOXED = Double.class;
    private static final Class PRIMITIVE_TYPE_BOOLEAN = boolean.class;
    private static final Class PRIMITIVE_TYPE_BOOLEAN_BOXED = Boolean.class;

    public static boolean isBuiltIn(Class clazz) {
        if (isString(clazz) || isPrimitive(clazz))
            return true;

        return false;
    }

    public static boolean isString(Object object) {
        return isSubclassOf(object.getClass(), PRIMITIVE_TYPE_STRING);
    }

    public static boolean isString(Class clazz) {
        return isSubclassOf(clazz, PRIMITIVE_TYPE_STRING);
    }

    public static boolean isPrimitive(Class clazz) {
        if (isInteger(clazz) || isLong(clazz) || isBoolean(clazz) || isFloat(clazz) || isDouble(clazz))
            return true;

        return false;
    }

    public static boolean isSubclassOf(Class clazz, Class what) {
        while (clazz != null) {
            if (clazz == what)
                return true;

            clazz = clazz.getSuperclass();
        }

        return false;
    }

    public static boolean isInteger(Class clazz) {
        return clazz == PRIMITIVE_TYPE_INTEGER || clazz == PRIMITIVE_TYPE_INTEGER_BOXED;
    }

    public static boolean isLong(Class clazz) {
        return clazz == PRIMITIVE_TYPE_LONG || clazz == PRIMITIVE_TYPE_LONG_BOXED;
    }

    public static boolean isBoolean(Class clazz) {
        return clazz == PRIMITIVE_TYPE_BOOLEAN || clazz == PRIMITIVE_TYPE_BOOLEAN_BOXED;
    }

    public static boolean isFloat(Class clazz) {
        return clazz == PRIMITIVE_TYPE_FLOAT || clazz == PRIMITIVE_TYPE_FLOAT_BOXED;
    }

    public static boolean isDouble(Class clazz) {
        return clazz == PRIMITIVE_TYPE_DOUBLE || clazz == PRIMITIVE_TYPE_DOUBLE_BOXED;
    }
}