1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * A timestamp that refers to a date after 1 January 1970 which means its representation as UNIX
13 * timestamp is positive.
16 * The UNIX timestamp representing the stored time has to be positive and small enough so that
17 * a `EpiryTime` can be added to it without an overflow.
19 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
20 public class PositiveTimestamp extends CommonBase {
21 PositiveTimestamp(Object _dummy, long ptr) { super(ptr); }
22 @Override @SuppressWarnings("deprecation")
23 protected void finalize() throws Throwable {
25 if (ptr != 0) { bindings.PositiveTimestamp_free(ptr); }
29 * Checks if two PositiveTimestamps contain equal inner contents.
30 * This ignores pointers and is_owned flags and looks at the values in fields.
31 * Two objects with NULL inner values will be considered "equal" here.
33 public boolean eq(PositiveTimestamp b) {
34 boolean ret = bindings.PositiveTimestamp_eq(this.ptr, b == null ? 0 : b.ptr & ~1);
35 Reference.reachabilityFence(this);
36 Reference.reachabilityFence(b);
41 @Override public boolean equals(Object o) {
42 if (!(o instanceof PositiveTimestamp)) return false;
43 return this.eq((PositiveTimestamp)o);
46 long ret = bindings.PositiveTimestamp_clone_ptr(this.ptr);
47 Reference.reachabilityFence(this);
52 * Creates a copy of the PositiveTimestamp
54 public PositiveTimestamp clone() {
55 long ret = bindings.PositiveTimestamp_clone(this.ptr);
56 Reference.reachabilityFence(this);
57 if (ret >= 0 && ret <= 4096) { return null; }
58 PositiveTimestamp ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new PositiveTimestamp(null, ret); }
59 ret_hu_conv.ptrs_to.add(this);
64 * Create a new `PositiveTimestamp` from a unix timestamp in the Range
65 * `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a
66 * `CreationError::TimestampOutOfBounds`.
68 public static Result_PositiveTimestampCreationErrorZ from_unix_timestamp(long unix_seconds) {
69 long ret = bindings.PositiveTimestamp_from_unix_timestamp(unix_seconds);
70 Reference.reachabilityFence(unix_seconds);
71 if (ret >= 0 && ret <= 4096) { return null; }
72 Result_PositiveTimestampCreationErrorZ ret_hu_conv = Result_PositiveTimestampCreationErrorZ.constr_from_ptr(ret);
77 * Create a new `PositiveTimestamp` from a `SystemTime` with a corresponding unix timestamp in
78 * the Range `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a
79 * `CreationError::TimestampOutOfBounds`.
81 public static Result_PositiveTimestampCreationErrorZ from_system_time(long time) {
82 long ret = bindings.PositiveTimestamp_from_system_time(time);
83 Reference.reachabilityFence(time);
84 if (ret >= 0 && ret <= 4096) { return null; }
85 Result_PositiveTimestampCreationErrorZ ret_hu_conv = Result_PositiveTimestampCreationErrorZ.constr_from_ptr(ret);
90 * Returns the UNIX timestamp representing the stored time
92 public long as_unix_timestamp() {
93 long ret = bindings.PositiveTimestamp_as_unix_timestamp(this.ptr);
94 Reference.reachabilityFence(this);
99 * Returns a reference to the internal `SystemTime` time representation
101 public long as_time() {
102 long ret = bindings.PositiveTimestamp_as_time(this.ptr);
103 Reference.reachabilityFence(this);