/** Asserts that two locations are equal with some allowed tolerance. */ public static void tolerantAssertLocationsEquals( Locations l1, Locations l2, int xTolerance, int yTolerance, String message) { Iterator<Point> it1 = l1.iterator(); Iterator<Point> it2 = l2.iterator(); Point p1, p2; while (it1.hasNext()) { p1 = it1.next(); p2 = it2.next(); if (!_tolerantAssertPointEquals(p1, p2, xTolerance, yTolerance)) { throw new AssertionError( "The locations are not equal or are not in tolerance.\n" + "First location: " + l1 + ".\n" + "Second location: " + l2 + ".\n" + "Diverging point: " + p1 + " (first), " + p2 + " (second).\n" + message); } } }
private double calculateDistance(Location fromLocation, Location toLocation) { Coordinate from = null; Coordinate to = null; if (fromLocation.getCoordinate() != null & toLocation.getCoordinate() != null) { from = fromLocation.getCoordinate(); to = toLocation.getCoordinate(); } else if (locations != null) { from = locations.getCoord(fromLocation.getId()); to = locations.getCoord(toLocation.getId()); } if (from == null || to == null) throw new NullPointerException(); return calculateDistance(from, to); }
@Test public void testAsGenotype() { StringBuilder sb = new StringBuilder(); for (String location : Locations.locations()) { sb.append("AC"); } Genome genome = new Genome("profileId", sb.toString()); Genotype genotype = genome.asGenotype(); assertEquals(genome.getProfileId(), genotype.getProfileId()); for (String location : Locations.locations()) { assertEquals("AC", genotype.getValues().get(location)); } }
public void addChild(Location child) { // Previously, setParent delegated to addChildLocation and we sometimes ended up with // duplicate entries here. Instead this now uses a similar scheme to // AbstractLocation.setParent/addChild (with any weaknesses for distribution that such a // scheme might have...). // // We continue to use a list to allow identical-looking locations, but they must be different // instances. synchronized (children) { for (Location contender : children) { if (contender == child) { // don't re-add; no-op return; } } children.add(child); } if (isManaged()) { Locations.manage(child, managementContext); } else if (managementContext != null) { if (((LocalLocationManager) managementContext.getLocationManager()) .getLocationEvenIfPreManaged(child.getId()) == null) { ((ManagementContextInternal) managementContext).prePreManage(child); } } children.add(child); child.setParent(this); }
@SmallTest @MediumTest @LargeTest public void testObjectWrapsJSONCollection() throws JSONException { JSONObject jsonLocation = new JSONObject(); jsonLocation.put("city", "Seattle"); JSONArray jsonArray = new JSONArray(); jsonArray.put(jsonLocation); JSONObject jsonLocations = new JSONObject(); jsonLocations.put("locations", jsonArray); Locations locations = GraphObject.Factory.create(jsonLocations, Locations.class); Collection<GraphLocation> locationsGraphObjectCollection = locations.getLocations(); assertTrue(locationsGraphObjectCollection != null); GraphLocation graphLocation = locationsGraphObjectCollection.iterator().next(); assertTrue(graphLocation != null); assertEquals("Seattle", graphLocation.getCity()); }