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