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

org.mongodb.morphia.geo.Point Maven / Gradle / Ivy

The newest version!
package org.mongodb.morphia.geo;

import org.mongodb.morphia.annotations.Embedded;
import org.mongodb.morphia.annotations.Entity;

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

/**
 * Represents a GeoJSON Point type.  Will be persisted into the database according to the
 * specification. Therefore because of this, this entity will never have its own ID or store the its Class name.
 * 

* The builder for creating a Point is the {@code GeoJson.pointBuilder} method, or the helper {@code GeoJson.point} factory method. * * @see org.mongodb.morphia.geo.GeoJson#point(double, double) */ @Embedded @Entity(noClassnameStored = true) 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; } /** * Return the latitude of this point. * * @return the Point's latitude */ public double getLatitude() { return coordinates.get(1); } /** * Return the longitude of this point. * * @return the Point's longitude */ public double getLongitude() { return coordinates.get(0); } @Override public int hashCode() { return coordinates.hashCode(); } /* equals, hashCode and toString. Useful primarily for testing and debugging. Don't forget to re-create when changing this class */ @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 - 2024 Weber Informatics LLC | Privacy Policy