eu.hansolo.fx.countries.tools.LocationBuilder Maven / Gradle / Ivy
package eu.hansolo.fx.countries.tools;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.Property;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.paint.Color;
import java.time.Instant;
import java.util.HashMap;
public class LocationBuilder> {
private HashMap properties = new HashMap<>();
// ******************** Constructors **************************************
protected LocationBuilder() {}
// ******************** Methods *******************************************
public static final LocationBuilder create() {
return new LocationBuilder();
}
public final B name(final String name) {
properties.put("name", new SimpleStringProperty(name));
return (B) this;
}
public final B timestamp(final Instant timestamp) {
properties.put("timestamp", new SimpleObjectProperty<>(timestamp));
return (B) this;
}
public final B latitude(final double latitude) {
properties.put("latitude", new SimpleDoubleProperty(latitude));
return (B) this;
}
public final B longitude(final double longitude) {
properties.put("longitude", new SimpleDoubleProperty(longitude));
return (B) this;
}
public final B altitude(final double altitude) {
properties.put("altitude", new SimpleDoubleProperty(altitude));
return (B) this;
}
public final B info(final String info) {
properties.put("info", new SimpleStringProperty(info));
return (B) this;
}
public final B fill(final Color fill) {
properties.put("fill", new SimpleObjectProperty(fill));
return (B) this;
}
public final B stroke(final Color stroke) {
properties.put("stroke", new SimpleObjectProperty(stroke));
return (B) this;
}
public final B zoomLevel(final int level) {
properties.put("zoomLevel", new SimpleIntegerProperty(level));
return (B) this;
}
public final Location build() {
Location location = new Location();
properties.forEach((key, property) -> {
if ("name".equals(key)) {
location.setName(((StringProperty) properties.get(key)).get());
} else if ("timestamp".equals(key)) {
location.setTimestamp(((ObjectProperty) properties.get(key)).get());
} else if ("latitude".equals(key)) {
location.setLatitude(((DoubleProperty) properties.get(key)).get());
} else if ("longitude".equals(key)) {
location.setLongitude(((DoubleProperty) properties.get(key)).get());
} else if ("altitude".equals(key)) {
location.setAltitude(((DoubleProperty) properties.get(key)).get());
} else if ("info".equals(key)) {
location.setInfo(((StringProperty) properties.get(key)).get());
} else if ("fill".equals(key)) {
location.setFill(((ObjectProperty) properties.get(key)).get());
} else if ("stroke".equals(key)) {
location.setStroke(((ObjectProperty) properties.get(key)).get());
} else if ("zoomLevel".equals(key)) {
location.setZoomLevel(((IntegerProperty) properties.get(key)).get());
}
});
return location;
}
}