Skip to content

Instantly share code, notes, and snippets.

@jmini
Created January 11, 2015 06:57
Show Gist options
  • Save jmini/4be4aebed87b0267cd98 to your computer and use it in GitHub Desktop.
Save jmini/4be4aebed87b0267cd98 to your computer and use it in GitHub Desktop.
Main for the Stackoverflow a question http://stackoverflow.com/q/27884534/91497
//see http://stackoverflow.com/q/27884534/91497
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class Main {
public static void main(String[] args) {
List<Venue> venueList = new ArrayList<Venue>();
Venue newVenue = new Venue();
newVenue.venueName = "value";
newVenue.distance = 1512.9027099609375;
venueList.add(newVenue);
Venue v2 = new Venue();
v2.venueName = "value";
v2.distance = 702.6363525390625;
venueList.add(v2);
Venue v3 = new Venue();
v3.venueName = "value";
v3.distance = 814.787353515625;
venueList.add(v3);
Venue v4 = new Venue();
v4.venueName = "value";
v4.distance = 605.23388671875;
venueList.add(v4);
Collections.sort(venueList, new LocationComparator());
for (Venue venue : venueList) {
System.out.println(venue.distance);
}
}
private static class LocationComparator implements Comparator<Venue> {
@Override
public int compare(Venue one, Venue other) {
return Double.compare(one.distance, other.distance);
}
}
private static class Venue {
private int venueID;
private String venueName;
private String venueLocation;
private String startDate;
private int startHour;
private String startHourType;
private int startMinute;
private String endDate;
private int endHour;
private String endHourType;
private int endMinute;
private String runningTime;
private double distance;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment