| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.evolution.util; |
| 27 |
|
| 28 |
import dr.util.Attribute; |
| 29 |
import dr.util.Identifiable; |
| 30 |
|
| 31 |
import java.util.TreeMap; |
| 32 |
import java.util.Map; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public class Location implements Identifiable { |
| 39 |
|
| 40 |
public static final String LOCATION = "location"; |
| 41 |
|
| 42 |
private Location(final String id, final int index, final String description, final double longitude, final double latitude) { |
| 43 |
this.id = id; |
| 44 |
this.index = index; |
| 45 |
this.description = description; |
| 46 |
this.longitude = longitude; |
| 47 |
this.latitude = latitude; |
| 48 |
} |
| 49 |
|
| 50 |
public String getId() { |
| 51 |
return id; |
| 52 |
} |
| 53 |
|
| 54 |
public void setId(String id) { |
| 55 |
|
| 56 |
|
| 57 |
} |
| 58 |
|
| 59 |
public String getDescription() { |
| 60 |
return description; |
| 61 |
} |
| 62 |
|
| 63 |
public double getLongitude() { |
| 64 |
return longitude; |
| 65 |
} |
| 66 |
|
| 67 |
public double getLatitude() { |
| 68 |
return latitude; |
| 69 |
} |
| 70 |
|
| 71 |
public int getIndex() { |
| 72 |
return index; |
| 73 |
} |
| 74 |
|
| 75 |
@Override |
| 76 |
public String toString() { |
| 77 |
return getId(); |
| 78 |
} |
| 79 |
|
| 80 |
private final String id; |
| 81 |
private final int index; |
| 82 |
private final String description; |
| 83 |
|
| 84 |
private final double longitude; |
| 85 |
private final double latitude; |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
public static Location newLocation(String id, String description, double longitude, double latitude) { |
| 90 |
if (getLocation(id) != null) { |
| 91 |
throw new IllegalArgumentException("Location with id, " + id + ", already exists"); |
| 92 |
} |
| 93 |
int index = getLocationCount(); |
| 94 |
Location location = new Location(id, index, description, longitude, latitude); |
| 95 |
locations.put(index, location); |
| 96 |
return location; |
| 97 |
} |
| 98 |
|
| 99 |
public static Location getLocation(String id) { |
| 100 |
for (Location location : locations.values()) { |
| 101 |
if (location.getId().equals(id)) { |
| 102 |
return location; |
| 103 |
} |
| 104 |
} |
| 105 |
return null; |
| 106 |
} |
| 107 |
|
| 108 |
public static int getLocationCount() { |
| 109 |
return locations.keySet().size(); |
| 110 |
} |
| 111 |
|
| 112 |
public static Location getLocation(int index) { |
| 113 |
return locations.get(index); |
| 114 |
} |
| 115 |
|
| 116 |
static private Map<Integer, Location> locations = new TreeMap<Integer, Location>(); |
| 117 |
} |