Skip to content

Commit

Permalink
Fixed removing duplicates (manually instead of using set)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaytj95 committed Oct 7, 2015
1 parent 53e29f7 commit a1eaa80
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 7 deletions.
Binary file modified bin/com/jasonjohn/unchainedapi/UnchainedAPI.class
Binary file not shown.
Binary file modified bin/com/jasonjohn/unchainedapi/UnchainedRestaurant.class
Binary file not shown.
Binary file modified bin/com/jasonjohn/unchainedapi/Util.class
Binary file not shown.
2 changes: 1 addition & 1 deletion src/com/jasonjohn/unchainedapi/UnchainedAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private ArrayList<UnchainedRestaurant> getVenuesNearby(String query, String ll)
}

//remove any duplicates
combined = Util.removeDuplicates(combined);
combined = Util.removeDuplicatesManually(combined);
combined.trimToSize();

return combined;
Expand Down
2 changes: 1 addition & 1 deletion src/com/jasonjohn/unchainedapi/UnchainedRestaurant.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public boolean equals(Object o) {
name1 = Util.normalizeVenueName(name1);
name2 = Util.normalizeVenueName(name2);

if(name1.contains(name2)) {
if(name1.contains(name2) || name2.contains(name1)) {
return true;
} else return false;
}
Expand Down
35 changes: 30 additions & 5 deletions src/com/jasonjohn/unchainedapi/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*
*/
public class Util {

/**
* Google Geocoding key and secret
*/
Expand All @@ -49,7 +49,32 @@ public static ArrayList<UnchainedRestaurant> removeDuplicates(ArrayList<Unchaine
noDuplicates.addAll(setItems);
return noDuplicates;
}


public static ArrayList<UnchainedRestaurant> removeDuplicatesManually(ArrayList<UnchainedRestaurant> chains) {
int size = chains.size();

// not using a method in the check also speeds up the execution
// also i must be less that size-1 so that j doesn't
// throw IndexOutOfBoundsException
for (int i = 0; i < size - 1; i++) {
// start from the next item after strings[i]
// since the ones before are checked
for (int j = i + 1; j < size; j++) {
// no need for if ( i == j ) here
if (!chains.get(j).equals(chains.get(i)))
continue;
chains.remove(j);
// decrease j because the array got re-indexed
j--;
// decrease the size of the array
size--;
} // for j
} // for i

return chains;

}

/**
* Get lat,lng from a Google Maps query (ie "Mall of GA")
* @param query maps query (ie "Mall of GA" or "Buford Hwy")
Expand All @@ -69,7 +94,7 @@ public static String getLatLngFromMapsQuery(String query) throws UnchainedAPIExc
JSONObject geometryObject = resultsArray.getJSONObject(0).getJSONObject("geometry");
JSONObject location = geometryObject.getJSONObject("location");
String ll = location.getString("lat") + "," + location.getString("lng");

System.out.println("Geocoding result: ll =" + ll);
return ll;
} else {
Expand All @@ -80,7 +105,7 @@ public static String getLatLngFromMapsQuery(String query) throws UnchainedAPIExc
throw new UnchainedAPIException("GOOGLE GEOCODE ERROR: BAD JSON");
}
}

/**
* Function to query a URL and retrieve a JSON Response
* @param url
Expand Down Expand Up @@ -124,7 +149,7 @@ public static JSONObject getJsonFromUrl(String url) {
}
return jObj;
}


/**
* Normalize venue names (used for comparisons) so that "McDonald's == Mcdonalds")
Expand Down

0 comments on commit a1eaa80

Please sign in to comment.