Improved comments and added som methods to Obj DSO

This commit is contained in:
Ziver Koc 2017-02-08 17:21:27 +01:00
parent 84a3b13b76
commit 7484236292
3 changed files with 24 additions and 5 deletions

View file

@ -27,6 +27,8 @@ package zutil;
/**
* This class is a timer, it will track time and
* timeout after a specific amount of time.
* <br>
* Note that the {@link #start()} method needs to be called for the timer to start.
*
* Created by Ziver on 2015-07-15.
*/
@ -37,6 +39,9 @@ public class Timer {
private long timestamp;
/**
* Creates a new timer that in reset state.
*/
public Timer(long milisec){
this.period = milisec;
reset();

View file

@ -48,7 +48,7 @@ public abstract class DBBeanObjectDSO<T> extends DBBean{
}
if (config != null && !config.isEmpty()) {
Configurator<T> configurator = new Configurator<>(cachedObj);
Configurator<T> configurator = getObjectConfigurator();
configurator.setValues(JSONParser.read(config));
configurator.applyConfiguration();
}
@ -60,7 +60,7 @@ public abstract class DBBeanObjectDSO<T> extends DBBean{
if (cachedObj == null)
this.config = null;
else {
Configurator<T> configurator = new Configurator<>(cachedObj);
Configurator<T> configurator = getObjectConfigurator();
this.config = JSONWriter.toString(configurator.getValuesAsNode());
}
super.save(db);
@ -95,12 +95,16 @@ public abstract class DBBeanObjectDSO<T> extends DBBean{
setObjectClass(clazz.getName());
}
protected void setObjectClass(String clazz){
public void setObjectClass(String clazz){
if (this.type == null || !this.type.equals(type)) {
// TODO: check if clazz is subclass of T
setObject(null);
this.type = clazz;
postUpdateAction(); // instantiate cached object
}
}
public Configurator<T> getObjectConfigurator(){
return new Configurator<>(cachedObj);
}
}

View file

@ -47,6 +47,11 @@ import java.util.logging.Logger;
* object the {@link Configurator#setValues(DataNode)} or {@link Configurator#setValues(Map)}
* can be used to set the individual fields and finally call {@link Configurator#applyConfiguration()}
* to configure the target object.
* <br />
* External listener can be registered to be called before or after configuration changes
* by implementing {@link PreConfigurationActionListener} or {@link PostConfigurationActionListener}.
* The configured object will autmatically be registered as a listener if it also implements
* these interfaces.
*
* <br>
* Supported field types: String, int, boolean, enum
@ -248,6 +253,7 @@ public class Configurator<T> {
if (f.getType() == String.class) type = ConfigType.STRING;
else if(f.getType() == int.class) type = ConfigType.INT;
else if(f.getType() == double.class) type = ConfigType.INT;
else if(f.getType() == boolean.class) type = ConfigType.BOOLEAN;
else if(f.getType().isEnum()) type = ConfigType.ENUM;
else
@ -298,7 +304,11 @@ public class Configurator<T> {
case STRING:
value = v; break;
case INT:
value = Integer.parseInt(v); break;
if (field.getType() == double.class)
value = Double.parseDouble(v);
else
value = Integer.parseInt(v);
break;
case BOOLEAN:
value = Boolean.parseBoolean(v); break;
case ENUM: