Example usage for java.lang Void TYPE

List of usage examples for java.lang Void TYPE

Introduction

In this page you can find the example usage for java.lang Void TYPE.

Prototype

Class TYPE

To view the source code for java.lang Void TYPE.

Click Source Link

Document

The Class object representing the pseudo-type corresponding to the keyword void .

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Class cls = Void.TYPE;
    String name = cls.getName(); // void
}

From source file:Main.java

public static void main(String[] args) {
    Class c = boolean.class;
    c = Boolean.TYPE;/*w  w  w .ja  v a2 s. co m*/
    c = byte.class;
    c = Byte.TYPE;
    c = char.class;
    c = Character.TYPE;
    c = short.class;
    c = Short.TYPE;
    c = int.class;
    c = Integer.TYPE;
    c = long.class;
    c = Long.TYPE;
    c = float.class;
    c = Float.TYPE;
    c = double.class;
    c = Double.TYPE;
    c = void.class;
    c = Void.TYPE;
}

From source file:Utils.java

public static boolean isJavaBeanCompliantSetter(Method method) {
    if (method == null)
        return false;

    if (method.getReturnType() != Void.TYPE)
        return false;

    if (!method.getName().startsWith("set"))
        return false;

    if (method.getParameterTypes().length != 1)
        return false;

    return true;//  w  w w.ja v a2s  .co m
}

From source file:Main.java

public static boolean hasGetterSignature(Method m) {
    // First: static methods can't be getters
    if (Modifier.isStatic(m.getModifiers())) {
        return false;
    }/*  w  w  w  .j  a  v  a 2 s.  c o  m*/
    // Must take no args
    Class<?>[] pts = m.getParameterTypes();
    if (pts != null && pts.length != 0) {
        return false;
    }
    // Can't be a void method
    if (Void.TYPE == m.getReturnType()) {
        return false;
    }
    // Otherwise looks ok:
    return true;
}

From source file:Main.java

private static Map<Class<?>, Class<?>> getWrapperTypes() {
    Map<Class<?>, Class<?>> ret = new HashMap<Class<?>, Class<?>>();
    ret.put(Boolean.TYPE, Boolean.class);
    ret.put(Character.TYPE, Character.class);
    ret.put(Byte.TYPE, Byte.class);
    ret.put(Short.TYPE, Short.class);
    ret.put(Integer.TYPE, Integer.class);
    ret.put(Long.TYPE, Long.class);
    ret.put(Float.TYPE, Float.class);
    ret.put(Double.TYPE, Double.class);
    ret.put(Void.TYPE, Void.class);
    return ret;/* w  w  w.  j  a  v  a2s  .  co m*/
}

From source file:Main.java

public static Map<String, Object> getProperties(Object object, boolean includeSuperClasses, boolean deepCopy) {
    HashMap<String, Object> map = new HashMap<String, Object>();
    if (object == null) {
        return map;
    }//from   w  w w . j a v  a2s  .  c  o  m

    Class<?> objectClass = object.getClass();
    Method[] methods = includeSuperClasses ? objectClass.getMethods() : objectClass.getDeclaredMethods();
    for (Method method : methods) {
        if (method.getParameterTypes().length == 0 && !method.getReturnType().equals(Void.TYPE)) {
            String methodName = method.getName();
            String propertyName = "";
            if (methodName.startsWith("get")) {
                propertyName = methodName.substring(3);
            } else if (methodName.startsWith("is")) {
                propertyName = methodName.substring(2);
            }
            if (propertyName.length() > 0 && Character.isUpperCase(propertyName.charAt(0))) {
                propertyName = Character.toLowerCase(propertyName.charAt(0)) + propertyName.substring(1);

                Object value = null;
                try {
                    value = method.invoke(object);
                } catch (Exception e) {
                }

                Object value2 = value;

                if (!deepCopy) {
                    map.put(propertyName, value);
                } else {
                    if (isSimpleObject(value)) {
                        map.put(propertyName, value);
                    } else if (value instanceof Map) {
                        Map<String, Object> submap = new HashMap<String, Object>();
                        for (Map.Entry<?, ?> entry : ((Map<?, ?>) value).entrySet()) {
                            submap.put(String.valueOf(entry.getKey()),
                                    convertObject(entry.getValue(), includeSuperClasses));
                        }
                        map.put(propertyName, submap);
                    } else if (value instanceof Iterable) {
                        List<Object> sublist = new ArrayList<Object>();
                        for (Object v : (Iterable<?>) object) {
                            sublist.add(convertObject(v, includeSuperClasses));
                        }
                        map.put(propertyName, sublist);
                    } else if (value.getClass().isArray()) {
                        List<Object> sublist = new ArrayList<Object>();
                        int length = Array.getLength(value);
                        for (int i = 0; i < length; i++) {
                            sublist.add(convertObject(Array.get(value, i), includeSuperClasses));
                        }
                        map.put(propertyName, sublist);
                    } else {
                        map.put(propertyName, getProperties(value, includeSuperClasses, deepCopy));
                    }
                }
            }
        }
    }

    return map;
}

From source file:Main.java

public static Class<?> findClass(String className) throws ClassNotFoundException {
    // [JACKSON-597]: support primitive types (and void)
    if (className.indexOf('.') < 0) {
        if ("int".equals(className))
            return Integer.TYPE;
        if ("long".equals(className))
            return Long.TYPE;
        if ("float".equals(className))
            return Float.TYPE;
        if ("double".equals(className))
            return Double.TYPE;
        if ("boolean".equals(className))
            return Boolean.TYPE;
        if ("byte".equals(className))
            return Byte.TYPE;
        if ("char".equals(className))
            return Character.TYPE;
        if ("short".equals(className))
            return Short.TYPE;
        if ("void".equals(className))
            return Void.TYPE;
    }/* w w w. ja  v a  2 s. co  m*/
    // Two-phase lookup: first using context ClassLoader; then default
    Throwable prob = null;
    ClassLoader loader = Thread.currentThread().getContextClassLoader();

    if (loader != null) {
        try {
            return Class.forName(className, true, loader);
        } catch (Exception e) {
            prob = getRootCause(e);
        }
    }
    try {
        return Class.forName(className);
    } catch (Exception e) {
        if (prob == null) {
            prob = getRootCause(e);
        }
    }
    if (prob instanceof RuntimeException) {
        throw (RuntimeException) prob;
    }
    throw new ClassNotFoundException(prob.getMessage(), prob);
}

From source file:Main.java

/**
 * Tells if a type is numerical; works both for primitive types and classes.
 * /*  w ww .  j a  v  a  2 s.  co m*/
 * @param type can't be {@code null}
 * 
 * @since 2.3.21
 */
public static boolean isNumerical(Class type) {
    return Number.class.isAssignableFrom(type)
            || type.isPrimitive() && type != Boolean.TYPE && type != Character.TYPE && type != Void.TYPE;
}

From source file:org.lunarray.model.descriptor.util.ModelBuilderUtil.java

/**
 * Resolves a type's cardinality./*from   www  . j  a va  2  s . com*/
 * 
 * @param type
 *            The type. May not be null.
 * @return Single if the type is a primitive, multiple if the type is a
 *         collection, else nullable.
 */
public static Cardinality resolveCardinality(final Class<?> type) {
    Validate.notNull(type, "Type may not be null.");
    // Get cardinality
    final Cardinality cardinality;
    if (Void.class.equals(type) || Void.TYPE.equals(type)) {
        cardinality = Cardinality.NONE;
    } else if (type.isPrimitive()) {
        cardinality = Cardinality.SINGLE;
    } else if (Collection.class.isAssignableFrom(type)) {
        cardinality = Cardinality.MULTIPLE;
    } else {
        cardinality = Cardinality.NULLABLE;
    }
    return cardinality;
}

From source file:Main.java

public static String getPrimitiveLetter(Class<?> paramClass) {
    if (Integer.TYPE.equals(paramClass)) {
        return "I";
    }/*from  ww  w  . j  a v  a2  s .co  m*/
    if (Void.TYPE.equals(paramClass)) {
        return "V";
    }
    if (Boolean.TYPE.equals(paramClass)) {
        return "Z";
    }
    if (Character.TYPE.equals(paramClass)) {
        return "C";
    }
    if (Byte.TYPE.equals(paramClass)) {
        return "B";
    }
    if (Short.TYPE.equals(paramClass)) {
        return "S";
    }
    if (Float.TYPE.equals(paramClass)) {
        return "F";
    }
    if (Long.TYPE.equals(paramClass)) {
        return "J";
    }
    if (Double.TYPE.equals(paramClass)) {
        return "D";
    }
    throw new IllegalStateException("Type: " + paramClass.getCanonicalName() + " is not a primitive type");
}