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 * Quantity of items supported by an [`Offer`].
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class Quantity extends CommonBase {
16 private Quantity(Object _dummy, long ptr) { super(ptr); }
17 @Override @SuppressWarnings("deprecation")
18 protected void finalize() throws Throwable {
20 if (ptr != 0) { bindings.Quantity_free(ptr); }
22 static Quantity constr_from_ptr(long ptr) {
23 bindings.LDKQuantity raw_val = bindings.LDKQuantity_ref_from_ptr(ptr);
24 if (raw_val.getClass() == bindings.LDKQuantity.Bounded.class) {
25 return new Bounded(ptr, (bindings.LDKQuantity.Bounded)raw_val);
27 if (raw_val.getClass() == bindings.LDKQuantity.Unbounded.class) {
28 return new Unbounded(ptr, (bindings.LDKQuantity.Unbounded)raw_val);
30 if (raw_val.getClass() == bindings.LDKQuantity.One.class) {
31 return new One(ptr, (bindings.LDKQuantity.One)raw_val);
33 assert false; return null; // Unreachable without extending the (internal) bindings interface
37 * Up to a specific number of items (inclusive). Use when more than one item can be requested
38 * but is limited (e.g., because of per customer or inventory limits).
40 * May be used with `NonZeroU64::new(1)` but prefer to use [`Quantity::One`] if only one item
43 public final static class Bounded extends Quantity {
44 public final long bounded;
45 private Bounded(long ptr, bindings.LDKQuantity.Bounded obj) {
47 this.bounded = obj.bounded;
51 * One or more items. Use when more than one item can be requested without any limit.
53 public final static class Unbounded extends Quantity {
54 private Unbounded(long ptr, bindings.LDKQuantity.Unbounded obj) {
59 * Only one item. Use when only a single item can be requested.
61 public final static class One extends Quantity {
62 private One(long ptr, bindings.LDKQuantity.One obj) {
67 long ret = bindings.Quantity_clone_ptr(this.ptr);
68 Reference.reachabilityFence(this);
73 * Creates a copy of the Quantity
75 public Quantity clone() {
76 long ret = bindings.Quantity_clone(this.ptr);
77 Reference.reachabilityFence(this);
78 if (ret >= 0 && ret <= 4096) { return null; }
79 org.ldk.structs.Quantity ret_hu_conv = org.ldk.structs.Quantity.constr_from_ptr(ret);
80 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
85 * Utility method to constructs a new Bounded-variant Quantity
87 public static Quantity bounded(long a) {
88 long ret = bindings.Quantity_bounded(a);
89 Reference.reachabilityFence(a);
90 if (ret >= 0 && ret <= 4096) { return null; }
91 org.ldk.structs.Quantity ret_hu_conv = org.ldk.structs.Quantity.constr_from_ptr(ret);
92 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
97 * Utility method to constructs a new Unbounded-variant Quantity
99 public static Quantity unbounded() {
100 long ret = bindings.Quantity_unbounded();
101 if (ret >= 0 && ret <= 4096) { return null; }
102 org.ldk.structs.Quantity ret_hu_conv = org.ldk.structs.Quantity.constr_from_ptr(ret);
103 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
108 * Utility method to constructs a new One-variant Quantity
110 public static Quantity one() {
111 long ret = bindings.Quantity_one();
112 if (ret >= 0 && ret <= 4096) { return null; }
113 org.ldk.structs.Quantity ret_hu_conv = org.ldk.structs.Quantity.constr_from_ptr(ret);
114 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };