Skip to content

Instantly share code, notes, and snippets.

@jfuerth
Created March 16, 2012 22:09
Show Gist options
  • Save jfuerth/2053147 to your computer and use it in GitHub Desktop.
Save jfuerth/2053147 to your computer and use it in GitHub Desktop.
Builder Pattern compatible with Errai Marshalling
package ca.fuerth.demo.client.shared;
import java.util.Date;
import org.jboss.errai.common.client.api.annotations.Portable;
import org.jboss.errai.marshalling.client.api.annotations.MapsTo;
@Portable
public final class OrientationSensorReading {
private final Date observationTime;
private final double x;
private final double y;
private final double z;
public OrientationSensorReading(
@MapsTo("observationTime") Date observationTime,
@MapsTo("x") double x,
@MapsTo("y") double y,
@MapsTo("z") double z) {
this.observationTime = new Date(observationTime.getTime());
this.x = x;
this.y = y;
this.z = z;
}
public Date getObservationTime() { return new Date(observationTime.getTime()); }
public double getX() { return x; }
public double getY() { return y; }
public double getZ() { return z; }
@Override
public String toString() {
return "OrientationSensorReading [observationTime=" + observationTime
+ ", x=" + x + ", y=" + y + ", z=" + z + "]";
}
public static class Builder {
private Date observationTime = new Date();
private double x;
private double y;
private double z;
public Builder time(Date time) { this.observationTime = time; return this; }
public Builder x(double x) { this.x = x; return this; }
public Builder y(double y) { this.y = y; return this; }
public Builder z(double z) { this.z = z; return this; }
public OrientationSensorReading build() {
return new OrientationSensorReading(observationTime, x, y, z);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment