I have a design dilemma I want to share with you guys: I have a class with various member variables that represents a person. One of the members is the home location of the person in coordinates. This class is persisted in a MySQL database.
The issue I have is that I want to have a list of people that are within a certain radius from the recorded distance from the specified person.
I successfuly created an SQL query that returns a result set with the person's details, and its distance from the pin point. But now is the problem: what's the best way to save this data in Java? Saving the distance inside the person class's members is not good, because the distance is not relevant to the person object. I thought about creating a two dimenesional array which holds the person in the first column and the data in the other. Another option I thought is to create a container object with two values, the person and the distance.
What do you think is the most efficient and "object oriented way" of doing that?
It looks like a job for a Map<Person, Double>
.
I would provide a connection class that holds the distance and person information.
class PinPoint
{
private double x; // Assuming
private double y;
public List<Connection> getConnections(double radius)
{
// Return a list of connections with the person and distance information
}
}
class Connection
{
private double distance;
private Person person;
}
That way you can add more things in the connection class later on, too. If you don't need it a simple map might suffice, too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With