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

br.com.anteros.nosql.persistence.mongodb.geo.Point Maven / Gradle / Ivy

There is a newer version: 1.0.6
Show newest version
package br.com.anteros.nosql.persistence.mongodb.geo;



import java.util.ArrayList;
import java.util.List;

import br.com.anteros.nosql.persistence.metadata.annotations.Embedded;


@Embedded
public class Point implements Geometry {
    private final List coordinates = new ArrayList();

    Point(final double latitude, final double longitude) {
        coordinates.add(longitude);
        coordinates.add(latitude);
    }

    Point(final List coordinates) {
        this.coordinates.addAll(coordinates);
    }

    @Override
    public List getCoordinates() {
        return coordinates;
    }

    public double getLatitude() {
        return coordinates.get(1);
    }

    public double getLongitude() {
        return coordinates.get(0);
    }

    @Override
    public int hashCode() {
        return coordinates.hashCode();
    }

    @Override
    public boolean equals(final Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        Point point = (Point) o;

        if (getCoordinates().size() != point.getCoordinates().size()) {
            return false;
        }
        for (int i = 0; i < coordinates.size(); i++) {
            final Double coordinate = coordinates.get(i);
            if (Double.compare(coordinate, point.getCoordinates().get(i)) != 0) {
                return false;
            }
        }

        return true;
    }

    @Override
    public String toString() {
        return String.format("Point{coordinates=%s}", coordinates);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy