I would model the config object as a JavaScriptObject
:
public class Config extends JavaScriptObject {
protected Config() { }
public native final boolean hasX() /*-{ return this.x == null; }-*/;
public native final double getX() /*-{ return this.x || 0; }-*/;
public native final void setX(double x) /*-{ this.x = x; }-*/;
public native final void unsetX() /*-{ delete this.x; }-*/;
…
There are obviously other ways to model it (using java.lang.Double
for instance) but that one is probably the most lightweight wrt the compiled JS output.
Or you could use java.lang.Double
arguments, but you'll pay the price for the wrapper object:
public native void cache(Double x, Double y, Double width, Double height, Double length) /*-{
var cache = {};
if (x != null) { cache.x = x.@java.lang.Double::doubleValue()(); }
…
Finally, you could also use special values if that makes sense in your case:
var config = {};
if (x >= 0) { config.x = x; }