dd04d046844dc1bb094a00c089905cbb9c4c2c70
[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 which means its representation as UNIX
13  * timestamp is positive.
14  * 
15  * # Invariants
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.
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(PositiveTimestamp b) {
34                 boolean ret = bindings.PositiveTimestamp_eq(this.ptr, b == null ? 0 : b.ptr & ~1);
35                 Reference.reachabilityFence(this);
36                 Reference.reachabilityFence(b);
37                 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                 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);
60                 return ret_hu_conv;
61         }
62
63         /**
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`.
67          */
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);
73                 return ret_hu_conv;
74         }
75
76         /**
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`.
80          */
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);
86                 return ret_hu_conv;
87         }
88
89         /**
90          * Returns the UNIX timestamp representing the stored time
91          */
92         public long as_unix_timestamp() {
93                 long ret = bindings.PositiveTimestamp_as_unix_timestamp(this.ptr);
94                 Reference.reachabilityFence(this);
95                 return ret;
96         }
97
98         /**
99          * Returns a reference to the internal `SystemTime` time representation
100          */
101         public long as_time() {
102                 long ret = bindings.PositiveTimestamp_as_time(this.ptr);
103                 Reference.reachabilityFence(this);
104                 return ret;
105         }
106
107 }