diff options
Diffstat (limited to 'src/main/java/org/geojson/Feature.java')
-rw-r--r-- | src/main/java/org/geojson/Feature.java | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/main/java/org/geojson/Feature.java b/src/main/java/org/geojson/Feature.java new file mode 100644 index 0000000..1d9c7fe --- /dev/null +++ b/src/main/java/org/geojson/Feature.java @@ -0,0 +1,81 @@ +package org.geojson; + +import com.fasterxml.jackson.annotation.JsonInclude; + +import java.util.HashMap; +import java.util.Map; + +public class Feature extends GeoJsonObject { + + @JsonInclude(JsonInclude.Include.ALWAYS) + private Map<String, Object> properties = new HashMap<String, Object>(); + @JsonInclude(JsonInclude.Include.ALWAYS) + private GeoJsonObject geometry; + private String id; + + public void setProperty(String key, Object value) { + properties.put(key, value); + } + + @SuppressWarnings("unchecked") + public <T> T getProperty(String key) { + return (T)properties.get(key); + } + + public Map<String, Object> getProperties() { + return properties; + } + + public void setProperties(Map<String, Object> properties) { + this.properties = properties; + } + + public GeoJsonObject getGeometry() { + return geometry; + } + + public void setGeometry(GeoJsonObject geometry) { + this.geometry = geometry; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + @Override + public <T> T accept(GeoJsonObjectVisitor<T> geoJsonObjectVisitor) { + return geoJsonObjectVisitor.visit(this); + } + + @Override public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + if (!super.equals(o)) + return false; + Feature feature = (Feature)o; + if (properties != null ? !properties.equals(feature.properties) : feature.properties != null) + return false; + if (geometry != null ? !geometry.equals(feature.geometry) : feature.geometry != null) + return false; + return !(id != null ? !id.equals(feature.id) : feature.id != null); + } + + @Override public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (properties != null ? properties.hashCode() : 0); + result = 31 * result + (geometry != null ? geometry.hashCode() : 0); + result = 31 * result + (id != null ? id.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "Feature{properties=" + properties + ", geometry=" + geometry + ", id='" + id + "'}"; + } +} |