1 /* 2 * Copyright 2013 University of Glasgow. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package broadwick.data; 17 18 import java.util.HashMap; 19 import java.util.Map; 20 import lombok.EqualsAndHashCode; 21 import lombok.Getter; 22 23 /** 24 * Utility class for location data. 25 */ 26 @EqualsAndHashCode 27 @SuppressWarnings("PMD.UnusedPrivateField") 28 public class Location { 29 // TODO what about cutom tags?????? 30 31 /** 32 * Create a new location from a location id and coordinates. A map of species and number of animals at the location 33 * can also be given where a deep copy of the data will be made. 34 * @param id the location id. 35 * @param easting the easting coordinate. 36 * @param northing the northing coordinate. 37 * @param populations a map of species type and number of animals. 38 */ 39 public Location(final String id, final Double easting, final Double northing, 40 final Map<String, Integer> populations) { 41 this.id = id; 42 this.easting = easting; 43 this.northing = northing; 44 this.populations = new HashMap<>(); 45 for (Map.Entry<String, Integer> population : populations.entrySet()) { 46 this.populations.put(population.getKey(), population.getValue()); 47 } 48 } 49 50 /** 51 * Get the NULL location, defined as the one with no id, coordinates or occupants. 52 * @return an instance of a null location. 53 */ 54 public static Location getNullLocation() { 55 return nullLocation; 56 } 57 58 @Getter 59 private final String id; 60 @Getter 61 private final Double easting; 62 @Getter 63 private final Double northing; 64 @Getter 65 private final Map<String, Integer> populations; 66 private static Location nullLocation = new Location("", null, null, new HashMap<String, Integer>()); 67 }