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 list of hops along a payment path terminating with a channel to the recipient.
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class RouteHint extends CommonBase {
16 RouteHint(Object _dummy, long ptr) { super(ptr); }
17 @Override @SuppressWarnings("deprecation")
18 protected void finalize() throws Throwable {
20 if (ptr != 0) { bindings.RouteHint_free(ptr); }
23 public RouteHintHop[] get_a() {
24 long[] ret = bindings.RouteHint_get_a(this.ptr);
25 Reference.reachabilityFence(this);
26 RouteHintHop[] ret_conv_14_arr = new RouteHintHop[ret.length];
27 for (int o = 0; o < ret.length; o++) {
28 long ret_conv_14 = ret[o];
29 RouteHintHop ret_conv_14_hu_conv = null; if (ret_conv_14 < 0 || ret_conv_14 > 4096) { ret_conv_14_hu_conv = new RouteHintHop(null, ret_conv_14); }
30 ret_conv_14_hu_conv.ptrs_to.add(this);
31 ret_conv_14_arr[o] = ret_conv_14_hu_conv;
33 return ret_conv_14_arr;
36 public void set_a(RouteHintHop[] val) {
37 bindings.RouteHint_set_a(this.ptr, val != null ? Arrays.stream(val).mapToLong(val_conv_14 -> val_conv_14 == null ? 0 : val_conv_14.ptr & ~1).toArray() : null);
38 Reference.reachabilityFence(this);
39 Reference.reachabilityFence(val);
43 * Constructs a new RouteHint given each field
45 public static RouteHint of(RouteHintHop[] a_arg) {
46 long ret = bindings.RouteHint_new(a_arg != null ? Arrays.stream(a_arg).mapToLong(a_arg_conv_14 -> a_arg_conv_14 == null ? 0 : a_arg_conv_14.ptr & ~1).toArray() : null);
47 Reference.reachabilityFence(a_arg);
48 if (ret >= 0 && ret <= 4096) { return null; }
49 RouteHint ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new RouteHint(null, ret); }
50 ret_hu_conv.ptrs_to.add(ret_hu_conv);
55 long ret = bindings.RouteHint_clone_ptr(this.ptr);
56 Reference.reachabilityFence(this);
61 * Creates a copy of the RouteHint
63 public RouteHint clone() {
64 long ret = bindings.RouteHint_clone(this.ptr);
65 Reference.reachabilityFence(this);
66 if (ret >= 0 && ret <= 4096) { return null; }
67 RouteHint ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new RouteHint(null, ret); }
68 ret_hu_conv.ptrs_to.add(this);
73 * Checks if two RouteHints contain equal inner contents.
76 long ret = bindings.RouteHint_hash(this.ptr);
77 Reference.reachabilityFence(this);
81 @Override public int hashCode() {
82 return (int)this.hash();
85 * Checks if two RouteHints contain equal inner contents.
86 * This ignores pointers and is_owned flags and looks at the values in fields.
87 * Two objects with NULL inner values will be considered "equal" here.
89 public boolean eq(RouteHint b) {
90 boolean ret = bindings.RouteHint_eq(this.ptr, b == null ? 0 : b.ptr & ~1);
91 Reference.reachabilityFence(this);
92 Reference.reachabilityFence(b);
97 @Override public boolean equals(Object o) {
98 if (!(o instanceof RouteHint)) return false;
99 return this.eq((RouteHint)o);
102 * Serialize the RouteHint object into a byte array which can be read by RouteHint_read
104 public byte[] write() {
105 byte[] ret = bindings.RouteHint_write(this.ptr);
106 Reference.reachabilityFence(this);
111 * Read a RouteHint from a byte array, created by RouteHint_write
113 public static Result_RouteHintDecodeErrorZ read(byte[] ser) {
114 long ret = bindings.RouteHint_read(ser);
115 Reference.reachabilityFence(ser);
116 if (ret >= 0 && ret <= 4096) { return null; }
117 Result_RouteHintDecodeErrorZ ret_hu_conv = Result_RouteHintDecodeErrorZ.constr_from_ptr(ret);