Debian Codegraph @

src/dr/evolution/util/Location.java

raw symbols SCIP
1 /*
2 * Location.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
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 * @author Andrew Rambaut
36 * @version $Id$
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 // this.id = id;
56 // ignore setting...
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 // STATIC MEMBERS
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 }