]> git.basschouten.com Git - openhab-addons.git/blob
3ee9f957a3f6b37b7bcf363fd22682fa492eb471
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.network.internal.utils;
14
15 import java.util.Optional;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18
19 /**
20  * Information about the ping result.
21  *
22  * @author Andreas Hirsch - Initial contribution
23  */
24 @NonNullByDefault
25 public class PingResult {
26
27     private boolean success;
28     private Optional<Double> responseTimeInMS = Optional.empty();
29     private double executionTimeInMS;
30
31     /**
32      * @param success <code>true</code> if the device was reachable, <code>false</code> if not.
33      * @param executionTimeInMS Execution time of the ping command in ms.
34      */
35     public PingResult(boolean success, double executionTimeInMS) {
36         this.success = success;
37         this.executionTimeInMS = executionTimeInMS;
38     }
39
40     /**
41      * @return <code>true</code> if the device was reachable, <code>false</code> if not.
42      */
43     public boolean isSuccess() {
44         return success;
45     }
46
47     /**
48      * @return Response time in ms which was returned by the ping command. Optional is empty if response time provided
49      *         by ping command is not available.
50      */
51     public Optional<Double> getResponseTimeInMS() {
52         return responseTimeInMS;
53     }
54
55     /**
56      * @param responseTimeInMS Response time in ms which was returned by the ping command.
57      */
58     public void setResponseTimeInMS(double responseTimeInMS) {
59         this.responseTimeInMS = Optional.of(responseTimeInMS);
60     }
61
62     @Override
63     public String toString() {
64         return "PingResult{" + "success=" + success + ", responseTimeInMS=" + responseTimeInMS + ", executionTimeInMS="
65                 + executionTimeInMS + '}';
66     }
67
68     /**
69      * @return Execution time of the ping command in ms.
70      */
71     public double getExecutionTimeInMS() {
72         return executionTimeInMS;
73     }
74 }