-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathGeometryCollection.java
89 lines (75 loc) · 2.17 KB
/
GeometryCollection.java
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package org.geojson;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class GeometryCollection extends GeoJsonObject implements Iterable<GeoJsonObject> {
private List<GeoJsonObject> geometries = new ArrayList<GeoJsonObject>();
public GeometryCollection() {}
/**
* Constructs the collection with an initial list of geometries.
* @param geos the initial list of geometries to be added
* @since issue #45
*/
public GeometryCollection( List<GeoJsonObject> geos )
{ this.setGeometries(geos) ; }
public List<GeoJsonObject> getGeometries() {
return geometries;
}
public void setGeometries( List<GeoJsonObject> geometries )
{
if( geometries == null ) this.geometries.clear() ;
else this.geometries = geometries ;
this.calculateBounds() ;
}
@Override
public Iterator<GeoJsonObject> iterator() {
return geometries.iterator();
}
public GeometryCollection add( GeoJsonObject geometry )
{
if( geometry == null ) return this ; // trivially
geometries.add(geometry) ;
this.setBbox( accumulateBounds(
this.getBbox(), geometry.calculateBounds() ) ) ;
return this ;
}
@Override
public double[] calculateBounds()
{
if( geometries.isEmpty() )
this.setBbox(null) ;
else
{
double[] box = STARTING_BOUNDS.clone() ;
for( GeoJsonObject geo : this.getGeometries() )
GeoJsonObject.accumulateBounds( box, geo.getBbox() ) ;
this.setBbox(box) ;
}
return this.getBbox() ;
}
@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 instanceof GeometryCollection))
return false;
if (!super.equals(o))
return false;
GeometryCollection that = (GeometryCollection)o;
return !(geometries != null ? !geometries.equals(that.geometries) : that.geometries != null);
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (geometries != null ? geometries.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "GeometryCollection{" + "geometries=" + geometries + "} " + super.toString();
}
}