All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.bingoohuang.springrestclient.utils.PrimitiveWrappers Maven / Gradle / Ivy

There is a newer version: 0.0.23
Show newest version
package com.github.bingoohuang.springrestclient.utils;

import lombok.val;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class PrimitiveWrappers {
    private static final Map, String> WRAPPER_XX_VALUE;

    static {
        val wrapXxValue = new HashMap, String>(8);
        wrapXxValue.put(boolean.class, "booleanValue");
        wrapXxValue.put(char.class, "charValue");
        wrapXxValue.put(byte.class, "byteValue");
        wrapXxValue.put(short.class, "shortValue");
        wrapXxValue.put(int.class, "intValue");
        wrapXxValue.put(float.class, "floatValue");
        wrapXxValue.put(long.class, "longValue");
        wrapXxValue.put(double.class, "doubleValue");

        WRAPPER_XX_VALUE = Collections.unmodifiableMap(wrapXxValue);
    }


    public static String getXxValueMethodName(Class primitiveType) {
        if (!primitiveType.isPrimitive())
            throw new IllegalArgumentException(primitiveType + " is not primitive");

        return WRAPPER_XX_VALUE.get(primitiveType);
    }

    private static final Map, String> WRAPPER_PARSE_XX;

    static {
        val parseXX = new HashMap, String>(8);
        parseXX.put(boolean.class, "parseBoolean");
//        parseXX.put(char.class, "charValue");
        parseXX.put(byte.class, "parseByte");
        parseXX.put(short.class, "parseShort");
        parseXX.put(int.class, "parseInt");
        parseXX.put(float.class, "parseFloat");
        parseXX.put(long.class, "parseLong");
        parseXX.put(double.class, "parseDouble");

        WRAPPER_PARSE_XX = Collections.unmodifiableMap(parseXX);
    }


    public static String getParseXxMethodName(Class primitiveType) {
        if (!primitiveType.isPrimitive())
            throw new IllegalArgumentException(primitiveType + " is not primitive");

        return WRAPPER_PARSE_XX.get(primitiveType);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy