All Downloads are FREE. Search and download functionalities are using the official Maven repository.

eu.hansolo.toolbox.geo.GeoLocationBuilder Maven / Gradle / Ivy

Go to download

Toolbox contains a collection of useful tools incl. events, properties, helper classes etc.

The newest version!
/*
 * SPDX-License-Identifier: Apache-2.0
 *
 * Copyright 2023 Gerrit Grunwald.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package eu.hansolo.toolbox.geo;

import eu.hansolo.toolbox.properties.DoubleProperty;
import eu.hansolo.toolbox.properties.LongProperty;
import eu.hansolo.toolbox.properties.ReadOnlyProperty;
import eu.hansolo.toolbox.properties.StringProperty;

import java.util.HashMap;


public class GeoLocationBuilder> {
    private HashMap properties = new HashMap<>();


    // ******************** Constructors **************************************
    protected GeoLocationBuilder() {}


    // ******************** Methods *******************************************
    public static final GeoLocationBuilder create() {
        return new GeoLocationBuilder();
    }

    public final B name(final String name) {
        properties.put("name", new StringProperty(name));
        return (B) this;
    }

    public final B timestamp(final long timestamp) {
        properties.put("timestamp", new LongProperty(timestamp));
        return (B) this;
    }

    public final B latitude(final double latitude) {
        properties.put("latitude", new DoubleProperty(latitude));
        return (B) this;
    }

    public final B longitude(final double longitude) {
        properties.put("longitude", new DoubleProperty(longitude));
        return (B) this;
    }

    public final B altitude(final double altitude) {
        properties.put("altitude", new DoubleProperty(altitude));
        return (B) this;
    }

    public final B accuracy(final double accuracy) {
        properties.put("accuracy", new DoubleProperty(accuracy));
        return (B)this;
    }

    public final B info(final String info) {
        properties.put("info", new StringProperty(info));
        return (B) this;
    }

    public final GeoLocation build() {
        GeoLocation location = new GeoLocation();
        properties.forEach((key, property) -> {
            switch(key) {
                case "name"      -> location.setName(((StringProperty) property).get());
                case "timestamp" -> location.setTimestamp(((LongProperty) property).get());
                case "latitude"  -> location.setLatitude(((DoubleProperty) property).get());
                case "longitude" -> location.setLongitude(((DoubleProperty) property).get());
                case "altitude"  -> location.setAltitude(((DoubleProperty) property).get());
                case "accuracy"  -> location.setAccuracy(((DoubleProperty) property).get());
                case "info"      -> location.setInfo(((StringProperty) property).get());
            }
        });
        return location;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy