ecb2d4c948a1dd770c8882314bac5c3796f5ada6
[ldk-java] / src / main / java / org / ldk / structs / ExpiryTime.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
12  * Positive duration that defines when (relatively to the timestamp) in the future the invoice
13  * expires
14  * 
15  * # Invariants
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
18  * timestamp
19  */
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 {
25                 super.finalize();
26                 if (ptr != 0) { bindings.ExpiryTime_free(ptr); }
27         }
28
29         long clone_ptr() {
30                 long ret = bindings.ExpiryTime_clone_ptr(this.ptr);
31                 Reference.reachabilityFence(this);
32                 return ret;
33         }
34
35         /**
36          * Creates a copy of the ExpiryTime
37          */
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);
44                 return ret_hu_conv;
45         }
46
47         /**
48          * Checks if two ExpiryTimes contain equal inner contents.
49          */
50         public long hash() {
51                 long ret = bindings.ExpiryTime_hash(this.ptr);
52                 Reference.reachabilityFence(this);
53                 return ret;
54         }
55
56         @Override public int hashCode() {
57                 return (int)this.hash();
58         }
59         /**
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.
63          */
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);
68                 this.ptrs_to.add(b);
69                 return ret;
70         }
71
72         @Override public boolean equals(Object o) {
73                 if (!(o instanceof ExpiryTime)) return false;
74                 return this.eq((ExpiryTime)o);
75         }
76         /**
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`.
80          */
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);
86                 return ret_hu_conv;
87         }
88
89         /**
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`.
93          */
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);
99                 return ret_hu_conv;
100         }
101
102         /**
103          * Returns the expiry time in seconds
104          */
105         public long as_seconds() {
106                 long ret = bindings.ExpiryTime_as_seconds(this.ptr);
107                 Reference.reachabilityFence(this);
108                 return ret;
109         }
110
111         /**
112          * Returns a reference to the underlying `Duration` (=expiry time)
113          */
114         public long as_duration() {
115                 long ret = bindings.ExpiryTime_as_duration(this.ptr);
116                 Reference.reachabilityFence(this);
117                 return ret;
118         }
119
120 }