View Javadoc
1   /*
2    * Copyright 2018-2022 the original author or authors.
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  
17  package org.bremersee.geojson.model;
18  
19  import static org.bremersee.geojson.GeoJsonConstants.GEOMETRIES;
20  
21  import com.fasterxml.jackson.annotation.JsonIgnore;
22  import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
23  import com.fasterxml.jackson.annotation.JsonProperty;
24  import io.swagger.v3.oas.annotations.media.Schema;
25  import java.io.Serial;
26  import java.io.Serializable;
27  import java.util.Collection;
28  import java.util.List;
29  import java.util.Optional;
30  import java.util.stream.Collectors;
31  import lombok.Builder;
32  import lombok.EqualsAndHashCode;
33  import lombok.Getter;
34  import lombok.Setter;
35  import lombok.ToString;
36  
37  /**
38   * GeoJSON GeometryCollection.
39   *
40   * @author Christian Bremer
41   */
42  @Schema(description = "GeoJSON GeometryCollection.")
43  @JsonIgnoreProperties(ignoreUnknown = true)
44  @Getter
45  @Setter
46  @EqualsAndHashCode(callSuper = true)
47  @ToString(callSuper = true)
48  public class GeometryCollection extends Geometry implements Serializable {
49  
50    @Serial
51    private static final long serialVersionUID = 1L;
52  
53    /**
54     * The geometries.
55     */
56    @Schema(description = "The geometries.")
57    @JsonProperty(GEOMETRIES)
58    private List<Geometry> geometries;
59  
60    /**
61     * Instantiates a new geometry collection.
62     */
63    public GeometryCollection() {
64      setType(TypeEnum.GEOMETRYCOLLECTION);
65    }
66  
67    /**
68     * Instantiates a new geometry collection.
69     *
70     * @param bbox the bbox
71     * @param geometries the geometries
72     */
73    @Builder(toBuilder = true)
74    public GeometryCollection(BoundingBox bbox, List<Geometry> geometries) {
75      super(bbox);
76      setType(TypeEnum.GEOMETRYCOLLECTION);
77      this.geometries = geometries;
78    }
79  
80    @Schema(hidden = true)
81    @JsonIgnore
82    @Override
83    Object getGeometryJsonValue() {
84      return Optional.ofNullable(getGeometries())
85          .stream()
86          .flatMap(Collection::stream)
87          .map(Geometry::toJson)
88          .collect(Collectors.toList());
89    }
90  
91  }
92