Support passing trait instance references from C to Java without clone or double...
[ldk-java] / src / main / java / org / ldk / structs / PaymentId.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 javax.annotation.Nullable;
8
9
10 /**
11  * A payment identifier used to uniquely identify a payment to LDK.
12  */
13 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
14 public class PaymentId extends CommonBase {
15         PaymentId(Object _dummy, long ptr) { super(ptr); }
16         @Override @SuppressWarnings("deprecation")
17         protected void finalize() throws Throwable {
18                 super.finalize();
19                 if (ptr != 0) { bindings.PaymentId_free(ptr); }
20         }
21
22         /**
23          * Checks if two PaymentIds contain equal inner contents.
24          */
25         public long hash() {
26                 long ret = bindings.PaymentId_hash(this.ptr);
27                 return ret;
28         }
29
30         /**
31          * Creates a copy of the PaymentId
32          */
33         public PaymentId clone() {
34                 long ret = bindings.PaymentId_clone(this.ptr);
35                 if (ret >= 0 && ret < 1024) { return null; }
36                 PaymentId ret_hu_conv = new PaymentId(null, ret);
37                 ret_hu_conv.ptrs_to.add(this);
38                 return ret_hu_conv;
39         }
40
41         /**
42          * Checks if two PaymentIds contain equal inner contents.
43          * This ignores pointers and is_owned flags and looks at the values in fields.
44          * Two objects with NULL inner values will be considered "equal" here.
45          */
46         public boolean eq(PaymentId b) {
47                 boolean ret = bindings.PaymentId_eq(this.ptr, b == null ? 0 : b.ptr & ~1);
48                 this.ptrs_to.add(b);
49                 return ret;
50         }
51
52         /**
53          * Serialize the PaymentId object into a byte array which can be read by PaymentId_read
54          */
55         public byte[] write() {
56                 byte[] ret = bindings.PaymentId_write(this.ptr);
57                 return ret;
58         }
59
60         /**
61          * Read a PaymentId from a byte array, created by PaymentId_write
62          */
63         public static Result_PaymentIdDecodeErrorZ read(byte[] ser) {
64                 long ret = bindings.PaymentId_read(ser);
65                 if (ret >= 0 && ret < 1024) { return null; }
66                 Result_PaymentIdDecodeErrorZ ret_hu_conv = Result_PaymentIdDecodeErrorZ.constr_from_ptr(ret);
67                 return ret_hu_conv;
68         }
69
70 }