Java String Sanitize sanitizePrimitives(Class clazz)

Here you can find the source of sanitizePrimitives(Class clazz)

Description

This method checks if the input clazz can be converted to a primitive type.

License

Open Source License

Parameter

Parameter Description
clazz The class to sanitize.

Return

The primitive version of the input class if it exists.

Declaration

public static Class<?> sanitizePrimitives(Class<?> clazz) 

Method Source Code

//package com.java2s;
// The MIT License(MIT)

public class Main {
    /**//from   ww w  .jav  a2s. c o m
     * <p>
     * This method checks if the input {@code clazz} can be converted to a primitive type.
     * </p>
     *
     * <p>
     * For example, if the input {@code clazz} is an {@code Integer}, it will convert it to an {@code int}.
     * </p>
     *
     * @param clazz The class to sanitize.
     * @return The primitive version of the input class if it exists.
     */
    public static Class<?> sanitizePrimitives(Class<?> clazz) {
        if (clazz == Byte.class) {
            return byte.class;
        }

        if (clazz == Short.class) {
            return short.class;
        }

        if (clazz == Integer.class) {
            return int.class;
        }

        if (clazz == Long.class) {
            return long.class;
        }

        if (clazz == Float.class) {
            return float.class;
        }

        if (clazz == Double.class) {
            return double.class;
        }

        if (clazz == Character.class) {
            return char.class;
        }

        if (clazz == Boolean.class) {
            return boolean.class;
        }

        return clazz;
    }
}

Related

  1. sanitizeOperationId(String operationId)
  2. sanitizePackageName(String raw)
  3. sanitizePackageVersion(String string)
  4. sanitizePath(String apiPath)
  5. sanitizePath(String input)
  6. sanitizeProcOrFuncName(String src)
  7. sanitizeProjectName(final String projectName)
  8. sanitizeRefName(String refName)
  9. sanitizeResource(String resource)