]> git.basschouten.com Git - openhab-addons.git/blob
dd1e6d6bfff53409614b151e616972116232fdb7
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.vigicrues.internal.dto.opendatasoft;
14
15 import java.util.ArrayList;
16 import java.util.List;
17 import java.util.Optional;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21
22 import com.google.gson.annotations.SerializedName;
23
24 /**
25  * The {@link OpenDatasoftResponse} is the Java class used to map the JSON
26  * response to an opendatasoft endpoint request.
27  *
28  * @author GaĆ«l L'hopital - Initial contribution
29  */
30 @NonNullByDefault
31 public class OpenDatasoftResponse {
32     @SerializedName("nhits")
33     private int nHits;
34     private @Nullable Parameters parameters;
35     private List<Record> records = new ArrayList<>();
36
37     public int getNHits() {
38         return nHits;
39     }
40
41     public Optional<Parameters> getParameters() {
42         Parameters parameters = this.parameters;
43         if (parameters != null) {
44             return Optional.of(parameters);
45         }
46         return Optional.empty();
47     }
48
49     public Optional<VigiCruesFields> getFirstRecord() {
50         return records.stream().findFirst().flatMap(Record::getFields);
51     }
52 }