1d98df53c052bcc53c459e8191061d95ce03ffbd
[ldk-java] / src / main / java / org / ldk / structs / ProbingError.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  * An error that may occur when sending a payment probe.
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class ProbingError extends CommonBase {
16         private ProbingError(Object _dummy, long ptr) { super(ptr); }
17         @Override @SuppressWarnings("deprecation")
18         protected void finalize() throws Throwable {
19                 super.finalize();
20                 if (ptr != 0) { bindings.ProbingError_free(ptr); }
21         }
22         static ProbingError constr_from_ptr(long ptr) {
23                 bindings.LDKProbingError raw_val = bindings.LDKProbingError_ref_from_ptr(ptr);
24                 if (raw_val.getClass() == bindings.LDKProbingError.Invoice.class) {
25                         return new Invoice(ptr, (bindings.LDKProbingError.Invoice)raw_val);
26                 }
27                 if (raw_val.getClass() == bindings.LDKProbingError.Sending.class) {
28                         return new Sending(ptr, (bindings.LDKProbingError.Sending)raw_val);
29                 }
30                 assert false; return null; // Unreachable without extending the (internal) bindings interface
31         }
32
33         /**
34          * An error resulting from the provided [`Bolt11Invoice`].
35          */
36         public final static class Invoice extends ProbingError {
37                 public final java.lang.String invoice;
38                 private Invoice(long ptr, bindings.LDKProbingError.Invoice obj) {
39                         super(null, ptr);
40                         this.invoice = obj.invoice;
41                 }
42         }
43         /**
44          * An error occurring when sending a payment probe.
45          */
46         public final static class Sending extends ProbingError {
47                 public final org.ldk.structs.ProbeSendFailure sending;
48                 private Sending(long ptr, bindings.LDKProbingError.Sending obj) {
49                         super(null, ptr);
50                         long sending = obj.sending;
51                         org.ldk.structs.ProbeSendFailure sending_hu_conv = org.ldk.structs.ProbeSendFailure.constr_from_ptr(sending);
52                         if (sending_hu_conv != null) { sending_hu_conv.ptrs_to.add(this); };
53                         this.sending = sending_hu_conv;
54                 }
55         }
56         long clone_ptr() {
57                 long ret = bindings.ProbingError_clone_ptr(this.ptr);
58                 Reference.reachabilityFence(this);
59                 return ret;
60         }
61
62         /**
63          * Creates a copy of the ProbingError
64          */
65         public ProbingError clone() {
66                 long ret = bindings.ProbingError_clone(this.ptr);
67                 Reference.reachabilityFence(this);
68                 if (ret >= 0 && ret <= 4096) { return null; }
69                 org.ldk.structs.ProbingError ret_hu_conv = org.ldk.structs.ProbingError.constr_from_ptr(ret);
70                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
71                 return ret_hu_conv;
72         }
73
74         /**
75          * Utility method to constructs a new Invoice-variant ProbingError
76          */
77         public static ProbingError invoice(java.lang.String a) {
78                 long ret = bindings.ProbingError_invoice(a);
79                 Reference.reachabilityFence(a);
80                 if (ret >= 0 && ret <= 4096) { return null; }
81                 org.ldk.structs.ProbingError ret_hu_conv = org.ldk.structs.ProbingError.constr_from_ptr(ret);
82                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
83                 return ret_hu_conv;
84         }
85
86         /**
87          * Utility method to constructs a new Sending-variant ProbingError
88          */
89         public static ProbingError sending(org.ldk.structs.ProbeSendFailure a) {
90                 long ret = bindings.ProbingError_sending(a.ptr);
91                 Reference.reachabilityFence(a);
92                 if (ret >= 0 && ret <= 4096) { return null; }
93                 org.ldk.structs.ProbingError ret_hu_conv = org.ldk.structs.ProbingError.constr_from_ptr(ret);
94                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
95                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); };
96                 return ret_hu_conv;
97         }
98
99         /**
100          * Checks if two ProbingErrors contain equal inner contents.
101          * This ignores pointers and is_owned flags and looks at the values in fields.
102          */
103         public boolean eq(org.ldk.structs.ProbingError b) {
104                 boolean ret = bindings.ProbingError_eq(this.ptr, b == null ? 0 : b.ptr);
105                 Reference.reachabilityFence(this);
106                 Reference.reachabilityFence(b);
107                 return ret;
108         }
109
110         @Override public boolean equals(Object o) {
111                 if (!(o instanceof ProbingError)) return false;
112                 return this.eq((ProbingError)o);
113         }
114 }