org.freshvanilla.lang.misc.SafeShortFieldAccessor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com.paremus.dosgi.net Show documentation
Show all versions of com.paremus.dosgi.net Show documentation
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 SafeShortFieldAccessor implements FieldAccessor {
private final Field f;
SafeShortFieldAccessor(Field f) {
this.f = f;
}
public Short getField(Pojo pojo) {
try {
return (Short) 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, Short object) {
try {
f.set(pojo, object);
} catch (Exception e) {
throw new RuntimeException();
}
}
public void setBoolean(Pojo pojo, boolean flag) {
setField(pojo, (short)(flag ? 1 : 0));
}
public void setNum(Pojo pojo, long value) {
setField(pojo, (short)value);
}
public void setDouble(Pojo pojo, double value) {
setField(pojo, (short)value);
}
}