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

org.freshvanilla.lang.misc.SafeCharFieldAccessor Maven / Gradle / Ivy

Go to download

An implementation of OSGi Remote Service Admin, enhanced to provide support for OSGi Promises and streaming using OSGi PushStreams.

The newest version!
package org.freshvanilla.lang.misc;

import java.lang.reflect.Field;

class SafeCharFieldAccessor implements FieldAccessor {
    private final Field f;

    SafeCharFieldAccessor(Field f) {
        this.f = f;
    }

    public  Character getField(Pojo pojo) {
    	try {
			return (Character) f.get(pojo);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
    }

    public  boolean getBoolean(Pojo pojo) {
        return getField(pojo) != 0;
    }

    public  long getNum(Pojo pojo) {
    	return getField(pojo);
    }

    public  double getDouble(Pojo pojo) {
    	return getField(pojo);
    }

    public  void setField(Pojo pojo, Character object) {
    	try {
        	f.set(pojo, object);
        } catch (Exception e) {
        	throw new RuntimeException();
        }
    }

    public  void setBoolean(Pojo pojo, boolean flag) {
        setField(pojo, (char)(flag ? 1 : 0));
    }

    public  void setNum(Pojo pojo, long value) {
    	setField(pojo, (char)value);
    }

    public  void setDouble(Pojo pojo, double value) {
    	setField(pojo, (char)value);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy