/** Should only be called in the constructor */ public void setPeerLocations(String[] peerLocationsString) { if(peerLocationsString != null) { double[] peerLocations = new double[peerLocationsString.length]; for(int i = 0; i < peerLocationsString.length; i++) peerLocations[i] = Location.getLocation(peerLocationsString[i]); updateLocation(currentLocation, peerLocations); } }
public void updateLocation(double newLoc, double[] newLocs) { boolean anythingChanged = location.updateLocation(newLoc, newLocs); node.peers.updatePMUserAlert(); if(anythingChanged) writePeers(); setPeerNodeStatus(System.currentTimeMillis()); }
public void testGetClosestPeerLocation() { for (double[] peers : PEER_LOCATIONS) { PeerLocation pl = new PeerLocation("0.0"); assertTrue(pl.updateLocation(0.0, peers)); for (double target : TARGET_LOCATIONS) { for (Set<Double> exclude : omit(peers)) { double closest = pl.getClosestPeerLocation(target, exclude); assertFalse(exclude.contains(closest)); double ref = trivialFindClosestDistance(peers, target, exclude); if (!Double.isInfinite(ref)) { assertFalse(Double.isNaN(closest)); boolean isPeer = false; for (double peer : peers) { if (closest == peer) { isPeer = true; break; } } assertTrue(isPeer); assertEquals(ref, Location.distance(closest, target), EPSILON); } else { assertTrue(Double.isNaN(closest)); } } } } }