1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.bremersee.geojson.converter.deserialization;
18
19 import static java.util.Objects.isNull;
20
21 import java.io.Serial;
22 import java.io.Serializable;
23 import java.util.List;
24 import org.locationtech.jts.geom.Coordinate;
25 import org.locationtech.jts.geom.CoordinateSequence;
26 import org.locationtech.jts.geom.impl.CoordinateArraySequence;
27
28
29
30
31
32
33 class ObjectToCoordinateSequenceConverter implements Serializable {
34
35 @Serial
36 private static final long serialVersionUID = 1L;
37
38 private final ObjectToCoordinateConverter coordinateConverter;
39
40
41
42
43
44
45 ObjectToCoordinateSequenceConverter(ObjectToCoordinateConverter coordinateConverter) {
46 if (isNull(coordinateConverter)) {
47 throw new IllegalArgumentException("Coordinate converter must be present.");
48 }
49 this.coordinateConverter = coordinateConverter;
50 }
51
52
53
54
55
56
57
58 CoordinateSequence convert(Object source) {
59 Coordinate[] coords;
60 if (isNull(source)) {
61 coords = new Coordinate[0];
62 } else {
63
64 coords = ((List<Object>) source).stream()
65 .map(coordinateConverter::convert)
66 .toArray(Coordinate[]::new);
67 }
68 return new CoordinateArraySequence(coords);
69 }
70
71 }