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

org.freshvanilla.lang.misc.SafeBooleanFieldAccessor 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 SafeBooleanFieldAccessor implements FieldAccessor {
    private final Field f;

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

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

    public  boolean getBoolean(Pojo pojo) {
    	try {
			return f.getBoolean(pojo);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
    }

    public  long getNum(Pojo pojo) {
			return getBoolean(pojo) ? 1 : 0;
    }

    public  double getDouble(Pojo pojo) {
			return getBoolean(pojo) ? 1 : 0;
    }

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

    public  void setBoolean(Pojo pojo, boolean flag) {
    	setField(pojo, flag);
    }

    public  void setNum(Pojo pojo, long value) {
    	setField(pojo, value != 0);
    }

    public  void setDouble(Pojo pojo, double value) {
    	setField(pojo, value != 0);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy