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.
16 * The Unix timestamp representing the stored time has to be positive and no greater than
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 org.ldk.structs.PositiveTimestamp ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PositiveTimestamp(null, ret); }
59 ret_hu_conv.ptrs_to.add(this);
64 * Creates a `PositiveTimestamp` from a Unix timestamp in the range `0..=MAX_TIMESTAMP`.
66 * Otherwise, returns a [`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 * Creates a `PositiveTimestamp` from a [`SystemTime`] with a corresponding Unix timestamp in
78 * the range `0..=MAX_TIMESTAMP`.
80 * Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
82 public static Result_PositiveTimestampCreationErrorZ from_system_time(long time) {
83 long ret = bindings.PositiveTimestamp_from_system_time(time);
84 Reference.reachabilityFence(time);
85 if (ret >= 0 && ret <= 4096) { return null; }
86 Result_PositiveTimestampCreationErrorZ ret_hu_conv = Result_PositiveTimestampCreationErrorZ.constr_from_ptr(ret);
91 * Creates a `PositiveTimestamp` from a [`Duration`] since the Unix epoch in the range
92 * `0..=MAX_TIMESTAMP`.
94 * Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
96 public static Result_PositiveTimestampCreationErrorZ from_duration_since_epoch(long duration) {
97 long ret = bindings.PositiveTimestamp_from_duration_since_epoch(duration);
98 Reference.reachabilityFence(duration);
99 if (ret >= 0 && ret <= 4096) { return null; }
100 Result_PositiveTimestampCreationErrorZ ret_hu_conv = Result_PositiveTimestampCreationErrorZ.constr_from_ptr(ret);
105 * Returns the Unix timestamp representing the stored time
107 public long as_unix_timestamp() {
108 long ret = bindings.PositiveTimestamp_as_unix_timestamp(this.ptr);
109 Reference.reachabilityFence(this);
114 * Returns the duration of the stored time since the Unix epoch
116 public long as_duration_since_epoch() {
117 long ret = bindings.PositiveTimestamp_as_duration_since_epoch(this.ptr);
118 Reference.reachabilityFence(this);
123 * Returns the [`SystemTime`] representing the stored time
125 public long as_time() {
126 long ret = bindings.PositiveTimestamp_as_time(this.ptr);
127 Reference.reachabilityFence(this);