1 package org.geojson; 2 3 import com.fasterxml.jackson.annotation.JsonInclude; 4 5 import java.util.HashMap; 6 import java.util.Map; 7 8 public class Feature extends GeoJsonObject { 9 10 @JsonInclude(JsonInclude.Include.ALWAYS) 11 private Map<String, Object> properties = new HashMap<String, Object>(); 12 @JsonInclude(JsonInclude.Include.ALWAYS) 13 private GeoJsonObject geometry; 14 private String id; 15 setProperty(String key, Object value)16 public void setProperty(String key, Object value) { 17 properties.put(key, value); 18 } 19 20 @SuppressWarnings("unchecked") getProperty(String key)21 public <T> T getProperty(String key) { 22 return (T)properties.get(key); 23 } 24 getProperties()25 public Map<String, Object> getProperties() { 26 return properties; 27 } 28 setProperties(Map<String, Object> properties)29 public void setProperties(Map<String, Object> properties) { 30 this.properties = properties; 31 } 32 getGeometry()33 public GeoJsonObject getGeometry() { 34 return geometry; 35 } 36 setGeometry(GeoJsonObject geometry)37 public void setGeometry(GeoJsonObject geometry) { 38 this.geometry = geometry; 39 } 40 getId()41 public String getId() { 42 return id; 43 } 44 setId(String id)45 public void setId(String id) { 46 this.id = id; 47 } 48 49 @Override accept(GeoJsonObjectVisitor<T> geoJsonObjectVisitor)50 public <T> T accept(GeoJsonObjectVisitor<T> geoJsonObjectVisitor) { 51 return geoJsonObjectVisitor.visit(this); 52 } 53 equals(Object o)54 @Override public boolean equals(Object o) { 55 if (this == o) 56 return true; 57 if (o == null || getClass() != o.getClass()) 58 return false; 59 if (!super.equals(o)) 60 return false; 61 Feature feature = (Feature)o; 62 if (properties != null ? !properties.equals(feature.properties) : feature.properties != null) 63 return false; 64 if (geometry != null ? !geometry.equals(feature.geometry) : feature.geometry != null) 65 return false; 66 return !(id != null ? !id.equals(feature.id) : feature.id != null); 67 } 68 hashCode()69 @Override public int hashCode() { 70 int result = super.hashCode(); 71 result = 31 * result + (properties != null ? properties.hashCode() : 0); 72 result = 31 * result + (geometry != null ? geometry.hashCode() : 0); 73 result = 31 * result + (id != null ? id.hashCode() : 0); 74 return result; 75 } 76 77 @Override toString()78 public String toString() { 79 return "Feature{properties=" + properties + ", geometry=" + geometry + ", id='" + id + "'}"; 80 } 81 } 82