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;
11 * A trait which can both lookup and update routing channel penalty scores.
13 * This is used in places where both bounds are required and implemented for all types which
14 * implement [`ScoreLookUp`] and [`ScoreUpdate`].
16 * Bindings users may need to manually implement this for their custom scoring implementations.
18 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
19 public class Score extends CommonBase {
20 final bindings.LDKScore bindings_instance;
21 Score(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
22 private Score(bindings.LDKScore arg, bindings.LDKScoreLookUp ScoreLookUp, bindings.LDKScoreUpdate ScoreUpdate) {
23 super(bindings.LDKScore_new(arg, ScoreLookUp, ScoreUpdate));
24 this.ptrs_to.add(arg);
25 this.ptrs_to.add(ScoreLookUp);
26 this.ptrs_to.add(ScoreUpdate);
27 this.bindings_instance = arg;
29 @Override @SuppressWarnings("deprecation")
30 protected void finalize() throws Throwable {
31 if (ptr != 0) { bindings.Score_free(ptr); } super.finalize();
34 * Destroys the object, freeing associated resources. After this call, any access
35 * to this object may result in a SEGFAULT or worse.
37 * You should generally NEVER call this method. You should let the garbage collector
38 * do this for you when it finalizes objects. However, it may be useful for types
39 * which represent locks and should be closed immediately to avoid holding locks
42 public void destroy() {
43 if (ptr != 0) { bindings.Score_free(ptr); }
46 public static interface ScoreInterface {
48 * Serialize the object into a byte array
52 private static class LDKScoreHolder { Score held; }
53 public static Score new_impl(ScoreInterface arg, ScoreLookUp.ScoreLookUpInterface ScoreLookUp_impl, ScoreUpdate.ScoreUpdateInterface ScoreUpdate_impl) {
54 final LDKScoreHolder impl_holder = new LDKScoreHolder();
55 impl_holder.held = new Score(new bindings.LDKScore() {
56 @Override public byte[] write() {
57 byte[] ret = arg.write();
58 Reference.reachabilityFence(arg);
61 }, ScoreLookUp.new_impl(ScoreLookUp_impl).bindings_instance, ScoreUpdate.new_impl(ScoreUpdate_impl).bindings_instance);
62 return impl_holder.held;
66 * Gets the underlying ScoreLookUp.
68 public ScoreLookUp get_score_look_up() {
69 ScoreLookUp res = new ScoreLookUp(null, bindings.LDKScore_get_ScoreLookUp(this.ptr));
70 res.ptrs_to.add(this);
76 * Gets the underlying ScoreUpdate.
78 public ScoreUpdate get_score_update() {
79 ScoreUpdate res = new ScoreUpdate(null, bindings.LDKScore_get_ScoreUpdate(this.ptr));
80 res.ptrs_to.add(this);
85 * Serialize the object into a byte array
87 public byte[] write() {
88 byte[] ret = bindings.Score_write(this.ptr);
89 Reference.reachabilityFence(this);