NebulaGraph Java Client  release-3.8
DurationWrapper.java
1 /* Copyright (c) 2021 vesoft inc. All rights reserved.
2  *
3  * This source code is licensed under Apache 2.0 License.
4  */
5 
6 package com.vesoft.nebula.client.graph.data;
7 
8 import com.vesoft.nebula.Duration;
9 import java.util.Objects;
10 
11 public class DurationWrapper extends BaseDataObject {
12  private final Duration duration;
13 
17  public DurationWrapper(Duration duration) {
18  this.duration = duration;
19  }
20 
24  public long getSeconds() {
25  return duration.seconds;
26  }
27 
31  public int getMicroseconds() {
32  return duration.microseconds;
33  }
34 
38  public int getMonths() {
39  return duration.months;
40  }
41 
45  public String getDurationString() {
46  return String.format("duration({months:%d, seconds:%d, microseconds:%d})",
48  }
49 
50 
51  @Override
52  public String toString() {
53  long totalSeconds = duration.seconds + duration.microseconds / 1000000;
54  int remainMicroSeconds = duration.microseconds % 1000000;
55  String microSends = String.format("%06d", remainMicroSeconds) + "000";
56  return String.format("P%dMT%d.%sS", duration.months, totalSeconds, microSends);
57  }
58 
59  @Override
60  public boolean equals(Object o) {
61  if (this == o) {
62  return true;
63  }
64  if (o == null || getClass() != o.getClass()) {
65  return false;
66  }
68  return duration.months == that.getMonths()
69  && duration.seconds == that.getSeconds()
70  && duration.microseconds == that.getMicroseconds();
71  }
72 
73  @Override
74  public int hashCode() {
75  return Objects.hash(duration);
76  }
77 
78 }
int getMicroseconds()
@retrun utc duration microseconds
DurationWrapper(Duration duration)
DurationWrapper is a wrapper for the duration type of nebula-graph.