[Java] Update auto-generated bindings to 0.0.115
[ldk-java] / src / main / java / org / ldk / structs / PositiveTimestamp.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  * A timestamp that refers to a date after 1 January 1970.
13  * 
14  * # Invariants
15  * 
16  * The Unix timestamp representing the stored time has to be positive and no greater than
17  * [`MAX_TIMESTAMP`].
18  */
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 {
24                 super.finalize();
25                 if (ptr != 0) { bindings.PositiveTimestamp_free(ptr); }
26         }
27
28         /**
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.
32          */
33         public boolean eq(org.ldk.structs.PositiveTimestamp b) {
34                 boolean ret = bindings.PositiveTimestamp_eq(this.ptr, b == null ? 0 : b.ptr);
35                 Reference.reachabilityFence(this);
36                 Reference.reachabilityFence(b);
37                 if (this != null) { this.ptrs_to.add(b); };
38                 return ret;
39         }
40
41         @Override public boolean equals(Object o) {
42                 if (!(o instanceof PositiveTimestamp)) return false;
43                 return this.eq((PositiveTimestamp)o);
44         }
45         long clone_ptr() {
46                 long ret = bindings.PositiveTimestamp_clone_ptr(this.ptr);
47                 Reference.reachabilityFence(this);
48                 return ret;
49         }
50
51         /**
52          * Creates a copy of the PositiveTimestamp
53          */
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                 org.ldk.structs.PositiveTimestamp ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PositiveTimestamp(null, ret); }
59                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
60                 return ret_hu_conv;
61         }
62
63         /**
64          * Generates a non-cryptographic 64-bit hash of the PositiveTimestamp.
65          */
66         public long hash() {
67                 long ret = bindings.PositiveTimestamp_hash(this.ptr);
68                 Reference.reachabilityFence(this);
69                 return ret;
70         }
71
72         @Override public int hashCode() {
73                 return (int)this.hash();
74         }
75         /**
76          * Creates a `PositiveTimestamp` from a Unix timestamp in the range `0..=MAX_TIMESTAMP`.
77          * 
78          * Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
79          */
80         public static Result_PositiveTimestampCreationErrorZ from_unix_timestamp(long unix_seconds) {
81                 long ret = bindings.PositiveTimestamp_from_unix_timestamp(unix_seconds);
82                 Reference.reachabilityFence(unix_seconds);
83                 if (ret >= 0 && ret <= 4096) { return null; }
84                 Result_PositiveTimestampCreationErrorZ ret_hu_conv = Result_PositiveTimestampCreationErrorZ.constr_from_ptr(ret);
85                 return ret_hu_conv;
86         }
87
88         /**
89          * Creates a `PositiveTimestamp` from a [`SystemTime`] with a corresponding Unix timestamp in
90          * the range `0..=MAX_TIMESTAMP`.
91          * 
92          * Note that the subsecond part is dropped as it is not representable in BOLT 11 invoices.
93          * 
94          * Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
95          */
96         public static Result_PositiveTimestampCreationErrorZ from_system_time(long time) {
97                 long ret = bindings.PositiveTimestamp_from_system_time(time);
98                 Reference.reachabilityFence(time);
99                 if (ret >= 0 && ret <= 4096) { return null; }
100                 Result_PositiveTimestampCreationErrorZ ret_hu_conv = Result_PositiveTimestampCreationErrorZ.constr_from_ptr(ret);
101                 return ret_hu_conv;
102         }
103
104         /**
105          * Creates a `PositiveTimestamp` from a [`Duration`] since the Unix epoch in the range
106          * `0..=MAX_TIMESTAMP`.
107          * 
108          * Note that the subsecond part is dropped as it is not representable in BOLT 11 invoices.
109          * 
110          * Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
111          */
112         public static Result_PositiveTimestampCreationErrorZ from_duration_since_epoch(long duration) {
113                 long ret = bindings.PositiveTimestamp_from_duration_since_epoch(duration);
114                 Reference.reachabilityFence(duration);
115                 if (ret >= 0 && ret <= 4096) { return null; }
116                 Result_PositiveTimestampCreationErrorZ ret_hu_conv = Result_PositiveTimestampCreationErrorZ.constr_from_ptr(ret);
117                 return ret_hu_conv;
118         }
119
120         /**
121          * Returns the Unix timestamp representing the stored time
122          */
123         public long as_unix_timestamp() {
124                 long ret = bindings.PositiveTimestamp_as_unix_timestamp(this.ptr);
125                 Reference.reachabilityFence(this);
126                 return ret;
127         }
128
129         /**
130          * Returns the duration of the stored time since the Unix epoch
131          */
132         public long as_duration_since_epoch() {
133                 long ret = bindings.PositiveTimestamp_as_duration_since_epoch(this.ptr);
134                 Reference.reachabilityFence(this);
135                 return ret;
136         }
137
138         /**
139          * Returns the [`SystemTime`] representing the stored time
140          */
141         public long as_time() {
142                 long ret = bindings.PositiveTimestamp_as_time(this.ptr);
143                 Reference.reachabilityFence(this);
144                 return ret;
145         }
146
147 }