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

com.javaoffers.brief.modelhelper.convert.Number2PrimitiveConvert Maven / Gradle / Ivy

There is a newer version: 3.6.8
Show newest version
package com.javaoffers.brief.modelhelper.convert;

import com.javaoffers.brief.modelhelper.consistant.ModelConsistants;
import com.javaoffers.brief.modelhelper.core.ConverDescriptor;
import com.javaoffers.brief.modelhelper.core.Register;

import java.lang.reflect.Method;

public class Number2PrimitiveConvert extends AbstractConver {

    Method method;

    @Override
    public Number convert(Number number) {
        try {
            return (Number)method.invoke(number);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public void register(Register register) {
        Class[] baseNumberClass = ModelConsistants.baseNumberClass;
        for(Class des: baseNumberClass){
            try {
                Number2PrimitiveConvert convert = new Number2PrimitiveConvert();
                Class pclass = ModelConsistants.numberPrimitivesMapping.get(des);
                Method method = Number.class.getDeclaredMethod(pclass.getSimpleName() + "Value");
                method.setAccessible(true);
                convert.method = method;
                register.registerConvert(new ConverDescriptor(Number.class,des),convert);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy