Package com.iizix.server.geo
Class UserLocationHistory
- java.lang.Object
- com.iizix.server.geo.UserLocationHistory
- All Implemented Interfaces:
IUserLocationHistory
public class UserLocationHistory extends java.lang.Object implements IUserLocationHistory
The implementation of the user location history.- Author:
- Christopher Mindus
Constructor Summary
Constructors Constructor Description UserLocationHistory(AuthenticatedUser user)Constructor.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddLocationListener(IAppSessionGyro appGyro, IUserLocationListener listener)Adds a listener for changes in the user's location.booleanaddLocationListener(IClientSessionGyro clientGyro, IUserLocationListener listener)Adds a listener for changes in the user's location.booleanequals(java.lang.Object o)Checks for equality.java.util.List<Nearby>findNearbyUsers(double maximumDistance, long maximumAge, boolean useAltitude)Finds nearby users from the latest known location in history with a max given distance and a maximum age of the users location.DeviceLocationgetLatestLocation()Returns the latest known location of the user received by the server (approximation).DeviceLocation[]getLocations()Returns the array of user locations.AuthenticatedUsergetUserInformation()Returns the authenticated user.inthashCode()Gets the hash code.booleanremoveLocationListener(IUserLocationListener listener)Removes a listener for changes in the user's location.java.lang.StringtoString()String representation of the class.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.iizix.user.geo.IUserLocationHistory
findNearbyUsers
Constructor Detail
UserLocationHistory
public UserLocationHistory(AuthenticatedUser user)
Constructor.- Parameters:
user- The authenticated user.
Method Detail
getUserInformation
public AuthenticatedUser getUserInformation()
Returns the authenticated user.- Specified by:
getUserInformationin interfaceIUserLocationHistory- Returns:
- The user.
getLocations
public DeviceLocation[] getLocations()
Returns the array of user locations.- Specified by:
getLocationsin interfaceIUserLocationHistory- Returns:
- The array of user locations.
getLatestLocation
public DeviceLocation getLatestLocation()
Returns the latest known location of the user received by the server (approximation). Two locations with very close timestamp might be interchanged. This method returns the last added location from an array of locations.- Specified by:
getLatestLocationin interfaceIUserLocationHistory- Returns:
- The most up-to-date location of the user, or null if none is found.
findNearbyUsers
public java.util.List<Nearby> findNearbyUsers(double maximumDistance, long maximumAge, boolean useAltitude)
Finds nearby users from the latest known location in history with a max given distance and a maximum age of the users location.The distance uses the Haversine method for calculation.
- Specified by:
findNearbyUsersin interfaceIUserLocationHistory- Parameters:
maximumDistance- The maximum distance in meters.maximumAge- The maximum age of the users location in milliseconds.useAltitude- Flag to use the altitude in the distance calculation or not.- Returns:
- A list of nearby users. Do not assume that the list is sorted by timestamp.
addLocationListener
public boolean addLocationListener(IAppSessionGyro appGyro, IUserLocationListener listener)
Adds a listener for changes in the user's location. This method will add a dispose listener to the client session and remove the listener if not already done.Calling this method twice with the same listener will not cause it to be added again.
- Specified by:
addLocationListenerin interfaceIUserLocationHistory- Parameters:
appGyro- The client session owning the listener.listener- The listener.- Returns:
- true for success, false if listener is already added or if client session is disposed of.
addLocationListener
public boolean addLocationListener(IClientSessionGyro clientGyro, IUserLocationListener listener)
Adds a listener for changes in the user's location. This method will add a dispose listener to the client session and remove the listener if not already done.Calling this method twice with the same listener will not cause it to be added again.
- Specified by:
addLocationListenerin interfaceIUserLocationHistory- Parameters:
clientGyro- The client session owning the listener.listener- The listener.- Returns:
- true for success, false if listener is already added or if client session is disposed of.
removeLocationListener
public boolean removeLocationListener(IUserLocationListener listener)
Removes a listener for changes in the user's location.- Specified by:
removeLocationListenerin interfaceIUserLocationHistory- Parameters:
listener- The listener.- Returns:
- true for success, false if listener is not previously added or has been removed.
equals
public boolean equals(java.lang.Object o)
Checks for equality.- Overrides:
equalsin classjava.lang.Object- Parameters:
o- The object to compare with.- Returns:
- When equals, false otherwise.
hashCode
public int hashCode()
Gets the hash code.- Overrides:
hashCodein classjava.lang.Object- Returns:
- The hash code is the Object's original hash code.
toString
public java.lang.String toString()
String representation of the class.- Overrides:
toStringin classjava.lang.Object- Returns:
- A string with user and distance.