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

ru.taskurotta.server.json.ArrayFactory Maven / Gradle / Ivy

There is a newer version: 0.8.1
Show newest version
package ru.taskurotta.server.json;

import java.lang.reflect.Array;
import java.util.HashMap;

/**
 * Created by void 30.04.13 15:58
 */
public class ArrayFactory {

    public static final HashMap primitives = new HashMap(8);
    static {
        primitives.put("byte", byte.class);
        primitives.put("short", short.class);
        primitives.put("int", int.class);
        primitives.put("long", long.class);
        primitives.put("float", float.class);
        primitives.put("double", double.class);
        primitives.put("char", char.class);
        primitives.put("boolean", boolean.class);
    }

    public static Object newInstance(String className, int length) throws ClassNotFoundException {
        Class theClass = primitives.get(className);
        if (theClass == null) {
            theClass = Class.forName(className);
        }
        return Array.newInstance(theClass, length);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy