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 * Positive duration that defines when (relatively to the timestamp) in the future the invoice
16 * The number of seconds this expiry time represents has to be in the range
17 * `0...(SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME)` to avoid overflows when adding it to a
20 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
21 public class ExpiryTime extends CommonBase {
22 ExpiryTime(Object _dummy, long ptr) { super(ptr); }
23 @Override @SuppressWarnings("deprecation")
24 protected void finalize() throws Throwable {
26 if (ptr != 0) { bindings.ExpiryTime_free(ptr); }
30 long ret = bindings.ExpiryTime_clone_ptr(this.ptr);
31 Reference.reachabilityFence(this);
36 * Creates a copy of the ExpiryTime
38 public ExpiryTime clone() {
39 long ret = bindings.ExpiryTime_clone(this.ptr);
40 Reference.reachabilityFence(this);
41 if (ret >= 0 && ret <= 4096) { return null; }
42 ExpiryTime ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ExpiryTime(null, ret); }
43 ret_hu_conv.ptrs_to.add(this);
48 * Checks if two ExpiryTimes contain equal inner contents.
51 long ret = bindings.ExpiryTime_hash(this.ptr);
52 Reference.reachabilityFence(this);
56 @Override public int hashCode() {
57 return (int)this.hash();
60 * Checks if two ExpiryTimes contain equal inner contents.
61 * This ignores pointers and is_owned flags and looks at the values in fields.
62 * Two objects with NULL inner values will be considered "equal" here.
64 public boolean eq(ExpiryTime b) {
65 boolean ret = bindings.ExpiryTime_eq(this.ptr, b == null ? 0 : b.ptr & ~1);
66 Reference.reachabilityFence(this);
67 Reference.reachabilityFence(b);
72 @Override public boolean equals(Object o) {
73 if (!(o instanceof ExpiryTime)) return false;
74 return this.eq((ExpiryTime)o);
77 * Construct an `ExpiryTime` from seconds. If there exists a `PositiveTimestamp` which would
78 * overflow on adding the `EpiryTime` to it then this function will return a
79 * `CreationError::ExpiryTimeOutOfBounds`.
81 public static Result_ExpiryTimeCreationErrorZ from_seconds(long seconds) {
82 long ret = bindings.ExpiryTime_from_seconds(seconds);
83 Reference.reachabilityFence(seconds);
84 if (ret >= 0 && ret <= 4096) { return null; }
85 Result_ExpiryTimeCreationErrorZ ret_hu_conv = Result_ExpiryTimeCreationErrorZ.constr_from_ptr(ret);
90 * Construct an `ExpiryTime` from a `Duration`. If there exists a `PositiveTimestamp` which
91 * would overflow on adding the `EpiryTime` to it then this function will return a
92 * `CreationError::ExpiryTimeOutOfBounds`.
94 public static Result_ExpiryTimeCreationErrorZ from_duration(long duration) {
95 long ret = bindings.ExpiryTime_from_duration(duration);
96 Reference.reachabilityFence(duration);
97 if (ret >= 0 && ret <= 4096) { return null; }
98 Result_ExpiryTimeCreationErrorZ ret_hu_conv = Result_ExpiryTimeCreationErrorZ.constr_from_ptr(ret);
103 * Returns the expiry time in seconds
105 public long as_seconds() {
106 long ret = bindings.ExpiryTime_as_seconds(this.ptr);
107 Reference.reachabilityFence(this);
112 * Returns a reference to the underlying `Duration` (=expiry time)
114 public long as_duration() {
115 long ret = bindings.ExpiryTime_as_duration(this.ptr);
116 Reference.reachabilityFence(this);